### Install Dependencies and Verify Tests Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/CONTRIBUTING.md Initial setup commands to install project dependencies and run the test suite. ```bash # Install dependencies composer install # Verify the test suite passes ./vendor/bin/phpunit ``` -------------------------------- ### Example: Configuring Page Setup Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Section.md Demonstrates using shortcut methods to set page size, padding, and background color. ```php use Paperdoc\Enum\PageSize; use Paperdoc\Document\Image; $section->setPageSize(PageSize::A4) ->setPagePadding(50, 50, 50, 50) ->setPageBackgroundColor('#FFFFFF'); ``` -------------------------------- ### Get Page Setup Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Section.md Retrieves the page setup configuration for the section. Returns null if not configured. ```php public function getPageSetup(): ?PageSetup ``` -------------------------------- ### Shortcut Page Setup Methods Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Section.md Provides convenient setters for common page setup properties. These methods lazily create and configure the underlying PageSetup object. ```php public function setPageSize(PageSize $size, string $orientation = 'portrait'): static public function setPageDimensions(float $width, float $height): static public function setPagePadding(float ...$values): static public function setPagePaddingTop(float $v): static public function setPagePaddingRight(float $v): static public function setPagePaddingBottom(float $v): static public function setPagePaddingLeft(float $v): static public function setPageBackgroundImage(?Image $image): static public function setPageBackgroundColor(?string $color): static ``` -------------------------------- ### Set Column Widths Example Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Table.md Example of setting specific widths for three columns in a table. ```php $table->setColumnWidths([100.0, 150.0, 100.0]); ``` -------------------------------- ### Complete Section Example with Vertical Alignment Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Section.md A comprehensive example showing how to create and configure a section, including setting page size, padding, and vertical alignment to CENTER. This demonstrates chaining multiple configuration methods. ```php use Paperdoc\Document\Section; use Paperdoc\Document\Style\TextStyle; use Paperdoc\Enum\PageSize; use Paperdoc\Enum\VerticalAlignment; $section = Section::make('chapter-1'); $section->setPageSize(PageSize::A4) ->setPagePadding(40, 60, 40, 60) ->setVerticalAlignment(VerticalAlignment::CENTER); $section->addHeading('CHAPTER 1', 1); $section->addHeading('Introduction', 2); $section->addParagraph('Lorem ipsum dolor sit amet...'); $section->addBulletList() ->addText('Key point one') ->addText('Key point two'); $section->addRule(); $section->addText( 'Learn more at example.com', TextStyle::make()->setItalic()->setFontSize(10) ); ``` -------------------------------- ### Example LLM Configuration Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/configuration.md An example of enabling LLM augmentation with OpenAI, specifying the API key and model. ```php 'llm' => [ 'enabled' => true, 'provider' => 'openai', 'api_key' => env('OPENAI_API_KEY'), 'model' => 'gpt-4-vision', ] ``` -------------------------------- ### Example OCR Configuration Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/configuration.md Provides a complete example of an OCR configuration, setting enabled status, language, minimum text ratio, pool size, timeout, and Tesseract binary path with options. ```php 'ocr' => [ 'enabled' => 'auto', 'language' => 'eng', 'min_text_ratio' => 0.15, 'pool_size' => 4, 'process_timeout' => 120, 'tesseract' => [ 'binary' => '/usr/bin/tesseract', 'options' => ['--psm', '6', '--oem', '1'], ], ] ``` -------------------------------- ### ListBlock Factory Examples Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/ListBlock.md Demonstrates how to use the static factory methods to create bullet and ordered lists, including setting a custom starting number for ordered lists. ```php $bulletList = ListBlock::bullet(); $orderedList = ListBlock::ordered(5); // Start at 5 $list = ListBlock::make('bullet'); ``` -------------------------------- ### Clone and Setup Repository Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/CONTRIBUTING.md Commands to clone the repository and configure the upstream remote. ```bash git clone https://github.com//paperdoc-lib.git cd paperdoc-lib ``` ```bash git remote add upstream https://github.com/paperdoc-dev/paperdoc-lib.git ``` -------------------------------- ### Example: Get Plain Text Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Paragraph.md Demonstrates how to retrieve the plain text content of a paragraph that has multiple text runs with different styles. ```php $para = $section->addText('Hello '); $para->addRun(new TextRun('world', TextStyle::make()->setBold())); echo $para->getPlainText(); // 'Hello world' ``` -------------------------------- ### Create an Ordered List Starting at a Specific Number Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/ListBlock.md Shows how to create a numbered list and specify a custom starting number (e.g., 5) using the constructor parameters. ```php $section->addList('ordered', 5) ->addText('Step five') ->addText('Step six'); ``` -------------------------------- ### Set Page Setup Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Section.md Sets the page setup configuration for the section. Pass null to clear the setup. ```php public function setPageSetup(?PageSetup $setup): static ``` -------------------------------- ### Metadata Setup with Dates Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Shows how to create and set metadata, including creation and modification dates. ```php $meta = Metadata::make() ->setAuthor('Finance Team') ->setSubject('Budget Allocation') ->setCreatedAt(new DateTime('2024-01-15')) ->setModifiedAt(new DateTime('2024-02-20')); $doc->setProperties($meta); ``` -------------------------------- ### Install Paperdoc Library Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/README.md Use Composer to install the Paperdoc library. This command adds the library as a dependency to your project. ```bash composer require paperdoc-dev/paperdoc-lib ``` -------------------------------- ### Set Image Dimensions Example Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Image.md Demonstrates setting the dimensions of an image after it has been created. ```php $img = Image::make('photo.jpg')->setDimensions(600, 400); ``` -------------------------------- ### Create Image Instance Examples Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Image.md Demonstrates how to create an Image instance from a file path or from embedded binary data. ```php // On-disk image $img = Image::make('path/to/photo.jpg'); // Embedded image $img = Image::fromData(file_get_contents('photo.jpg'), 'image/jpeg'); ``` -------------------------------- ### Configure Page Setup with Different Backgrounds Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/README.md Define page sections with specific page setups, including standard and custom sizes, padding, background images, and colors. Available since v0.7.0. ```php use Paperdoc\Document\Image; use Paperdoc\Document\Section; use Paperdoc\Document\Style\PageSetup; use Paperdoc\Enum\PageSize; $cover = Section::make('cover')->setPageSetup( PageSetup::fromSize(PageSize::A4) ->setPadding(0) // 1, 2, 3 or 4 values (CSS shorthand) ->setBackgroundImage(Image::make('cover.jpg')) // full-bleed image ); $body = Section::make('body')->setPageSetup( PageSetup::fromSize(PageSize::A4, PageSetup::ORIENTATION_LANDSCAPE) ->setPadding(50) ->setBackgroundColor('#F8F5EC') // solid color ); $square = Section::make('back-cover')->setPageSetup( PageSetup::custom(500, 500) // any width × height in pt ->setBackgroundImage(Image::make('back.jpg')) ); ``` -------------------------------- ### Basic Metadata Setup Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Demonstrates creating and setting basic metadata properties like author, subject, and keywords using the Metadata class. ```php use Paperdoc\Document\Metadata; $meta = Metadata::make() ->setAuthor('Alice Thompson') ->setSubject('Q1 2024 Financial Report') ->setKeywords('finance, quarterly, 2024'); $doc->setProperties($meta); ``` -------------------------------- ### Page Setup Configuration Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Section.md Methods for configuring page geometry, backgrounds, and padding for a section. ```APIDOC ## getPageSetup() ### Description Retrieves the page setup configuration for the section. ### Method GET ### Endpoint Not Applicable (SDK Method) ### Parameters None ### Response #### Success Response (200) - **pageSetup** (PageSetup|null) - The PageSetup object or null if not configured. ### Response Example ```json { "example": "PageSetup object or null" } ``` ## setPageSetup(?PageSetup $setup) ### Description Sets the page setup configuration for the section. Pass null to clear the setup. ### Method POST ### Endpoint Not Applicable (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **setup** (PageSetup|null) - Required - The PageSetup object or null to clear. ### Request Example ```json { "example": "PageSetup object or null" } ``` ### Response #### Success Response (200) - **static** (static) - Returns the current static instance for method chaining. ### Response Example ```json { "example": "static" } ``` ## setPageSize(PageSize $size, string $orientation = 'portrait') ### Description Sets the page size and orientation for the section. ### Method POST ### Endpoint Not Applicable (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **size** (PageSize) - Required - The desired page size (e.g., A4). - **orientation** (string) - Optional - The page orientation ('portrait' or 'landscape'). Defaults to 'portrait'. ### Request Example ```json { "example": "PageSize::A4, 'portrait'" } ``` ### Response #### Success Response (200) - **static** (static) - Returns the current static instance for method chaining. ### Response Example ```json { "example": "static" } ``` ## setPageDimensions(float $width, float $height) ### Description Sets the custom page dimensions (width and height) for the section. ### Method POST ### Endpoint Not Applicable (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **width** (float) - Required - The custom page width. - **height** (float) - Required - The custom page height. ### Request Example ```json { "example": "width, height" } ``` ### Response #### Success Response (200) - **static** (static) - Returns the current static instance for method chaining. ### Response Example ```json { "example": "static" } ``` ## setPagePadding(float ...$values) ### Description Sets the page padding for the section. Accepts one to four values for top, right, bottom, and left padding. ### Method POST ### Endpoint Not Applicable (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **values** (float) - Required - One to four float values representing padding (top, right, bottom, left). ### Request Example ```json { "example": "50, 50, 50, 50" } ``` ### Response #### Success Response (200) - **static** (static) - Returns the current static instance for method chaining. ### Response Example ```json { "example": "static" } ``` ## setPagePaddingTop(float $v) ### Description Sets the top padding for the section. ### Method POST ### Endpoint Not Applicable (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **v** (float) - Required - The value for the top padding. ### Request Example ```json { "example": "v" } ``` ### Response #### Success Response (200) - **static** (static) - Returns the current static instance for method chaining. ### Response Example ```json { "example": "static" } ``` ## setPagePaddingRight(float $v) ### Description Sets the right padding for the section. ### Method POST ### Endpoint Not Applicable (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **v** (float) - Required - The value for the right padding. ### Request Example ```json { "example": "v" } ``` ### Response #### Success Response (200) - **static** (static) - Returns the current static instance for method chaining. ### Response Example ```json { "example": "static" } ``` ## setPagePaddingBottom(float $v) ### Description Sets the bottom padding for the section. ### Method POST ### Endpoint Not Applicable (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **v** (float) - Required - The value for the bottom padding. ### Request Example ```json { "example": "v" } ``` ### Response #### Success Response (200) - **static** (static) - Returns the current static instance for method chaining. ### Response Example ```json { "example": "static" } ``` ## setPagePaddingLeft(float $v) ### Description Sets the left padding for the section. ### Method POST ### Endpoint Not Applicable (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **v** (float) - Required - The value for the left padding. ### Request Example ```json { "example": "v" } ``` ### Response #### Success Response (200) - **static** (static) - Returns the current static instance for method chaining. ### Response Example ```json { "example": "static" } ``` ## setPageBackgroundImage(?Image $image) ### Description Sets a background image for the section. ### Method POST ### Endpoint Not Applicable (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **image** (Image|null) - Optional - The Image object for the background, or null to clear. ### Request Example ```json { "example": "Image object or null" } ``` ### Response #### Success Response (200) - **static** (static) - Returns the current static instance for method chaining. ### Response Example ```json { "example": "static" } ``` ## setPageBackgroundColor(?string $color) ### Description Sets a background color for the section. ### Method POST ### Endpoint Not Applicable (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **color** (string|null) - Optional - The background color string (e.g., '#FFFFFF'), or null to clear. ### Request Example ```json { "example": "'#FFFFFF' or null" } ``` ### Response #### Success Response (200) - **static** (static) - Returns the current static instance for method chaining. ### Response Example ```json { "example": "static" } ``` ``` -------------------------------- ### Set Headers and Add Row Example Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Table.md Demonstrates setting header values and then adding a data row to the table. ```php $table->setHeaders(['Product', 'Quantity', 'Price']); $table->addRowFromArray(['Widget', '100', '$5.00']); ``` -------------------------------- ### Install Tesseract OCR Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/configuration.md Install Tesseract OCR on Ubuntu/Debian or macOS systems. This is required for PDF scanning functionality. ```bash # Ubuntu/Debian sudo apt-get install tesseract-ocr # macOS brew install tesseract ``` -------------------------------- ### Create and Configure Footer with RunningElement Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/types.md Example of creating a footer with page numbering and timestamp using RunningElement. Ensure necessary imports are included. ```php use Paperdoc\Document\Style\RunningElement; use Paperdoc\Enum\Alignment; $doc->setFooter( RunningElement::make('Page {page} / {pages} · {datetime}') ->setAlignment(Alignment::CENTER) ); ``` -------------------------------- ### ListBlock getStart() Method Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/ListBlock.md Retrieves the starting number for ordered lists. This value is only relevant for lists with the 'ordered' style. ```php public function getStart(): int ``` -------------------------------- ### Section Page Setup Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/CHANGELOG.md Allows setting custom page configurations for individual sections. Useful for mixed-layout documents. ```php $section->setPageSize(Paperdoc\Enum\PageSize::A5); ``` ```php $section->setPagePadding('10mm 5mm'); ``` ```php $section->setPageBackgroundColor('#ffffff'); ``` ```php $section->setPageBackgroundImage('cover.jpg'); ``` -------------------------------- ### Static Factories for ListBlock Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/ListBlock.md Provides static methods to create ListBlock instances with specific styles. `make` allows custom style and start number, `bullet` creates an unordered list, and `ordered` creates a numbered list starting from a specified number. ```php public static function make(string $style = self::STYLE_BULLET, int $start = 1): static public static function bullet(): static public static function ordered(int $start = 1): static ``` -------------------------------- ### Create Simple Paragraph Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Paragraph.md A basic example of creating a paragraph with a single text string. ```php $para = $section->addParagraph('This is a simple paragraph.'); ``` -------------------------------- ### Styled Link Example Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextLink.md Shows how to apply various text styles, such as color, underline, and bold, to a TextLink. ```APIDOC ## Styled link ### Example ```php $link = TextLink::make('https://example.com'); $run = TextRun::make( 'External link', TextStyle::make() ->setColor('#0066CC') ->setUnderline() ->setBold(), $link ); ``` ``` -------------------------------- ### URL with Fragment Example Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextLink.md Illustrates creating a TextLink to a specific subsection of an external URL. ```APIDOC ## URL with fragment ### Example ```php $link = TextLink::make('https://example.com/page', 'subsection'); // Renders as: ``` ``` -------------------------------- ### Create New Document Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/MANIFEST.txt Use DocumentManager::create() to start building a new document from scratch. This is the primary entry point for document generation. ```php use Paperdoc\DocumentManager; // Create a new document instance $document = DocumentManager::create(); ``` -------------------------------- ### Example: Center a Colophon Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Section.md Demonstrates how to center a colophon section on the page using `setVerticalAlignment`. This method is chainable. ```php use Paperdoc\Enum\VerticalAlignment; // Center a colophon on the page $colophon = $doc->openSection('colophon') ->setVerticalAlignment(VerticalAlignment::CENTER); $colophon->addText('© 2024 — All rights reserved.'); ``` -------------------------------- ### Build a Richly-Typed Document Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/README.md Example demonstrating how to programmatically construct a document with metadata, headings, lists, code blocks, bookmarks, and blockquotes using the Paperdoc library. ```php use Paperdoc\Document\{Document, Section, Metadata, ListBlock}; use Paperdoc\Document\Style\TextStyle; $doc = Document::make('md', 'Release notes v0.5.0') ->setProperties( Metadata::make() ->setAuthor('Alice') ->setKeywords('release, changelog, paperdoc') ->setLanguage('en-US') ); $section = $doc->openSection(); $section->addElement(\Paperdoc\Document\Heading::make('Getting started', 2, 'intro')); $section->addBulletList() ->addText('Install the library') ->addText('Run the quick start') ->addText('Read the docs'); $section->addCodeBlock("composer require paperdoc-dev/paperdoc-lib", 'bash'); $section->addBookmark('ready-to-go'); $section->addBlockquote() ->addText('You are all set.', TextStyle::make()->setItalic()); ``` -------------------------------- ### External URL Example Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextLink.md Demonstrates creating a TextLink for an external URL and incorporating it into a TextRun with specific styling. ```APIDOC ## External URL ### Example ```php use Paperdoc\Document\Link\TextLink; use Paperdoc\Document\TextRun; use Paperdoc\Document\Style\TextStyle; $link = TextLink::make('https://github.com/paperdoc-dev/paperdoc-lib'); $run = TextRun::make( 'Visit our GitHub repository', TextStyle::make()->setColor('#0066CC')->setUnderline(), $link ); $para = new Paragraph(); $para->addRun($run); ``` ``` -------------------------------- ### TextLink with Tooltip Example Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextLink.md Demonstrates how to add a tooltip to a TextLink. This provides additional information to the user when they hover over the link, enhancing usability. ```php $link = TextLink::make( 'https://paperdoc.dev', '', 'Official Paperdoc documentation' ); // In HTML: title="Official Paperdoc documentation" // In Markdown: [text](url "Official Paperdoc documentation") ``` -------------------------------- ### ListBlock setStart() Method Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/ListBlock.md Sets the starting number for an ordered list. This method has no effect on bullet (unordered) lists. ```php public function setStart(int $start): static ``` -------------------------------- ### Link with Tooltip Example Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextLink.md Demonstrates how to add a tooltip to a TextLink, which appears on hover in HTML and is used in Markdown. ```APIDOC ## Link with tooltip ### Example ```php $link = TextLink::make( 'https://paperdoc.dev', '', 'Official Paperdoc documentation' ); // In HTML: title="Official Paperdoc documentation" // In Markdown: [text](url "Official Paperdoc documentation") ``` ``` -------------------------------- ### Styled TextLink Example Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextLink.md Shows how to apply custom styling, such as color, underline, and bold, to a TextLink when it is rendered as part of a TextRun. This allows for visually distinct links. ```php $link = TextLink::make('https://example.com'); $run = TextRun::make( 'External link', TextStyle::make() ->setColor('#0066CC') ->setUnderline() ->setBold(), $link ); ``` -------------------------------- ### ListBlock Style and Start Number Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/ListBlock.md Methods to get and set the style (bullet or ordered) and the starting number for ordered lists. ```APIDOC ## Style ### `getStyle(): string` Returns the list style: `'bullet'` or `'ordered'`. ### `setStyle(string $style): static` Sets the list style. Throws `InvalidDocumentException` if the provided style is invalid. ### `isBullet(): bool` Returns `true` if the list is a bullet (unordered) list, `false` otherwise. ### `isOrdered(): bool` Returns `true` if the list is an ordered (numbered) list, `false` otherwise. ## Start Number ### `getStart(): int` Returns the starting number for ordered lists. ### `setStart(int $start): static` Sets the starting number for the list. This is only meaningful for ordered lists. ``` -------------------------------- ### Get MIME Type from Format Enum Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/types.md Example demonstrating how to get the MIME type for a given document format using the Format enum's mimeType() method. ```php use Paperdoc\Enum\Format; $fmt = Format::fromExtension('.pdf'); echo $fmt->mimeType(); // 'application/pdf' ``` -------------------------------- ### Page Setup Value Object Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/CHANGELOG.md Describes page physical properties like size, orientation, padding, and background. Use to configure page styles. ```php $pageSetup = new Paperdoc\Document\Style\PageSetup( Paperdoc\Enum\PageSize::LETTER, Paperdoc\Enum\Orientation::LANDSCAPE, '1cm 2cm', '#f0f0f0', 'background.png' ); ``` -------------------------------- ### Internal Anchor Example Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextLink.md Shows how to create a TextLink that points to an internal bookmark or anchor within the document. ```APIDOC ## Internal anchor ### Example ```php // Link to a bookmark $link = TextLink::make('', 'section-2'); $run = TextRun::make('Jump to Section 2', null, $link); ``` ``` -------------------------------- ### ListBlock Constructor Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/ListBlock.md Initializes a new ListBlock instance. Accepts an optional style and starting number for ordered lists. ```php public function __construct(string $style = self::STYLE_BULLET, int $start = 1) ``` -------------------------------- ### Configure Page Setup with Size and Background Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/types.md Creates a PageSetup object for a standard page size (A4) and sets padding and background color. This is useful for defining the basic layout of a document page. ```php use Paperdoc\Document\Style\PageSetup; use Paperdoc\Enum\PageSize; $setup = PageSetup::fromSize(PageSize::A4) ->setPadding(40) ->setBackgroundColor('#FFFFFF'); ``` -------------------------------- ### Complete Document Example Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/OtherElements.md Demonstrates the creation of a complete PDF document with various elements including headings, blockquotes, code blocks, rules, bookmarks, and lists. ```php use Paperdoc\Document\Document; use Paperdoc\Document\Style\TextStyle; use Paperdoc\Enum\Alignment; $doc = Document::make('pdf', 'Technical Report'); $section = $doc->openSection(); // Title $section->addHeading('Introduction', 1); // Quoted introduction $quote = $section->addBlockquote(); $quote->addText('Quality is not an act, it is a habit.'); $quote->addText('— Aristotle', TextStyle::make()->setItalic()); // Code example $section->addCodeBlock( "const doc = DocumentManager::create('pdf');\n" . "doc->openSection()->addText('Hello');", 'php' ); // Divider $section->addRule(); // Bookmark for TOC linking $section->addBookmark('section-1'); // Heading with ID for cross-references $heading = new Heading('Main Content', 2, 'main-content'); $section->addElement($heading); // Content $section->addBulletList() ->addText('Point one') ->addText('Point two'); // Another page $section->addPageBreak(); $section->addHeading('Conclusion', 2); $section->addText('Final thoughts...'); DocumentManager::save($doc, 'report.pdf'); ``` -------------------------------- ### Example: Set Embedded Image Data Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Image.md Demonstrates how to set embedded image data by reading image bytes from a file and specifying the MIME type. ```php $imageBytes = file_get_contents('logo.png'); $img = new Image(); $img->setData($imageBytes, 'image/png'); ``` -------------------------------- ### Create Simple Bold Red Text Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextStyle.md Applies bold and red color to text, then adds it to a section. This is a basic example of styling text content. ```php $style = TextStyle::make() ->setBold() ->setColor('#FF0000'); $section->addText('Error message', $style); ``` -------------------------------- ### TextRun Constructor and Factory Methods Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextRun.md Demonstrates the instantiation of a TextRun using its constructor and the static 'make' factory method. The factory method is often preferred for its conciseness. ```php public function __construct( string $text, ?TextStyle $style = null, ?TextLink $link = null, ) public static function make(string $text, ?TextStyle $style = null, ?TextLink $link = null): static ``` ```php use Paperdoc\Document\TextRun; use Paperdoc\Document\Style\TextStyle; $run = TextRun::make('Bold text', TextStyle::make()->setBold()); ``` -------------------------------- ### Get Section Name Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Section.md Retrieves the current name of the section. ```php public function getName(): string ``` -------------------------------- ### Internal Anchor TextLink Example Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextLink.md Shows how to create a TextLink that points to an internal bookmark or anchor within a document. This is used for navigation within the same document. ```php // Link to a bookmark $link = TextLink::make('', 'section-2'); $run = TextRun::make('Jump to Section 2', null, $link); ``` -------------------------------- ### Description Property Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Get or set the full text description of the document. ```APIDOC ## Description ### `getDescription` ```php public function getDescription(): string ``` Returns the full text description of the document. ### `setDescription` ```php public function setDescription(string $description): static ``` Sets the full text description of the document. ``` -------------------------------- ### Get Paragraph Style Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Paragraph.md Retrieves the ParagraphStyle object associated with this paragraph, if any. ```php public function getStyle(): ?ParagraphStyle ``` -------------------------------- ### Create a Simple Bullet List Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/ListBlock.md Demonstrates creating a basic unordered list and adding text items using the `addText` convenience method. ```php $section->addList('bullet') ->addText('First item') ->addText('Second item') ->addText('Third item'); ``` -------------------------------- ### Constructor and Factory Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextStyle.md Creates a new text style with defaults. The `make()` factory method is recommended for instantiation. ```APIDOC ## Constructor and Factory ### Description Creates a new text style with defaults. The `make()` factory method is recommended for instantiation. ### Methods - `__construct()`: Initializes a new TextStyle object with default values. - `make(): static`: A static factory method to create a new TextStyle instance with default settings. ``` -------------------------------- ### Get Metadata Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Section.md Retrieves loose key-value metadata pairs associated with the section. ```php public function getMetadata(): array ``` -------------------------------- ### Create a new Document instance Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Document.md Use the static `make` method to create a new Document instance, specifying the desired format and an optional title. ```php use Paperdoc\Document\Document; $doc = Document::make('pdf', 'Annual Report 2024'); ``` -------------------------------- ### TextLink Title Accessors Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextLink.md Methods to get and set the tooltip/title text for the TextLink. ```APIDOC ## Title Accessors ### Description Provides methods to retrieve and modify the tooltip or title text associated with the TextLink. This text typically appears when a user hovers over the link. ### Methods ```php public function getTitle(): string public function setTitle(string $v): static ``` ### Parameters #### setTitle - **$v** (string) - Required - The tooltip/title text to set. ``` -------------------------------- ### TextLink URL Accessors Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextLink.md Methods to get and set the external URL for the TextLink. ```APIDOC ## URL Accessors ### Description Provides methods to retrieve and modify the external URL associated with the TextLink. The URL can be a standard web address, a mailto link, or a tel link. ### Methods ```php public function getUrl(): string public function setUrl(string $v): static ``` ### Parameters #### setUrl - **$v** (string) - Required - The external URL to set. ### Example Values - `'https://example.com'` - `'https://example.com/path'` - `'mailto:user@example.com'` - `'tel:+1234567890' ``` -------------------------------- ### Get Column Widths Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Table.md Retrieves the array defining the widths of each column in the table. ```php public function getColumnWidths(): array ``` -------------------------------- ### Created Date Property Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Get or set the creation date and time of the document. ```APIDOC ## Created Date ### `getCreatedAt` ```php public function getCreatedAt(): ?DateTimeImmutable ``` Returns the document creation date/time. ### `setCreatedAt` ```php public function setCreatedAt(?DateTimeInterface $createdAt): static ``` Sets the document creation date/time. ``` -------------------------------- ### Creating a Simple Unstyled TextRun Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextRun.md Demonstrates the creation of a basic TextRun with plain text content and adding it to a Paragraph. This is the simplest way to include text. ```php $para = new Paragraph(); $para->addRun(new TextRun('Plain text')); ``` -------------------------------- ### Keywords Property Accessors Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Methods to get and set comma-separated keywords for the document. ```php public function getKeywords(): string public function setKeywords(string $keywords): static ``` -------------------------------- ### Creating a Styled TextRun Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextRun.md Illustrates how to create a TextRun with specific styling, such as bold text and a custom color, using the TextStyle::make() factory. ```php $run = TextRun::make( 'Important', TextStyle::make()->setBold()->setColor('#FF0000') ); $para = new Paragraph(); $para->addRun($run); ``` -------------------------------- ### Get Paragraph Type Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Paragraph.md Returns the string identifier for this block element type. ```php public function getType(): string ``` -------------------------------- ### Create and Save a PDF Document Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/README.md Demonstrates how to create a new PDF document, add sections with headings, paragraphs, and bullet lists, and then save it to a file. ```php use Paperdoc\Support\DocumentManager; use Paperdoc\Document\Style\TextStyle; $doc = DocumentManager::create('pdf', 'My Report'); $doc->openSection() ->addHeading('Introduction', 1) ->addParagraph('This is the introduction.') ->addBulletList() ->addText('Point one') ->addText('Point two'); DocumentManager::save($doc, 'output/report.pdf'); ``` -------------------------------- ### Document Constructor Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Document.md Initializes a new Document instance. You can specify the document format and an optional title. ```APIDOC ## Constructor ### Description Initializes a new Document instance with a specified format and an optional title. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method Signature `__construct(string $format, string $title = '')` #### Parameters - **`$format`** (string) - Required - Document format (e.g., 'pdf', 'docx') - **`$title`** (string) - Optional - Document title, used in metadata ``` -------------------------------- ### TextLink Anchor Accessors Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextLink.md Methods to get and set the internal anchor ID for the TextLink. ```APIDOC ## Anchor Accessors ### Description Provides methods to retrieve and modify the internal anchor ID for the TextLink. This is used for linking to specific sections within a document. ### Methods ```php public function getAnchor(): string public function setAnchor(string $v): static ``` ### Parameters #### setAnchor - **$v** (string) - Required - The internal anchor ID to set. ### Example Values - `'section-1'` - `'introduction'` - `'footnote-5' ``` -------------------------------- ### Get Default Text Style Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Document.md Retrieves the current default text style for the document. ```php public function getDefaultTextStyle(): TextStyle ``` -------------------------------- ### Get All Table Rows Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Table.md Retrieves an array containing all TableRow objects currently in the table. ```php public function getRows(): array ``` -------------------------------- ### Modified Date Property Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Get or set the last modification date and time of the document. ```APIDOC ## Modified Date ### `getModifiedAt` ```php public function getModifiedAt(): ?DateTimeImmutable ``` Returns the last modification date/time of the document. ### `setModifiedAt` ```php public function setModifiedAt(?DateTimeInterface $modifiedAt): static ``` Sets the last modification date/time of the document. ``` -------------------------------- ### Constructor and Factory Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/ParagraphStyle.md Creates a new paragraph style with default values for alignment, spacing, line spacing, heading level, and first-line indent. ```APIDOC ## Constructor and Factory ### Description Creates a new paragraph style with default values. ### Methods - `__construct()`: Initializes a new ParagraphStyle object. - `make(): static`: A static factory method to create a new ParagraphStyle instance. ### Default Values - Alignment: `LEFT` - Space before: `0.0` pt - Space after: `6.0` pt - Line spacing: `1.15` - Heading level: `null` - First-line indent: `0.0` pt ``` -------------------------------- ### Keywords Property Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Get or set the keywords for the document. Keywords should be provided as a comma-separated string. ```APIDOC ## Keywords ### `getKeywords` ```php public function getKeywords(): string ``` Returns the comma-separated keywords for the document. ### `setKeywords` ```php public function setKeywords(string $keywords): static ``` Sets the comma-separated keywords for the document. ``` -------------------------------- ### Open Document with Options Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/configuration.md Override default configuration by passing options directly to the open() or openBatch() methods in DocumentManager. ```php $doc = DocumentManager::open('scan.pdf', [ 'ocr' => true, 'language' => 'fra', 'llm' => true, ]); ``` -------------------------------- ### Subject Property Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Get or set the subject of the document. The subject is a short descriptive string. ```APIDOC ## Subject ### `getSubject` ```php public function getSubject(): string ``` Returns the short subject line of the document. ### `setSubject` ```php public function setSubject(string $subject): static ``` Sets the short subject line of the document. ``` -------------------------------- ### Table Constructor and Factory Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Table.md Initializes a new Table instance. The `make` static method provides a convenient way to create a table with optional styling. ```APIDOC ## Constructor and Factory ### `__construct(TableStyle $style = null)` Initializes a new Table instance with optional styling. ### `make(?TableStyle $style = null): static` Factory method to create a new Table instance with optional styling. ``` -------------------------------- ### Created Date Property Accessors Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Methods to get and set the document creation date/time. ```php public function getCreatedAt(): ?DateTimeImmutable public function setCreatedAt(?DateTimeInterface $createdAt): static ``` -------------------------------- ### Create Tooltip Link Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextLink.md Use TextLink::make with a URL and a third argument for the tooltip text to create a link that displays a tooltip on hover. ```php TextLink::make('https://x.com', '', 'title') ``` -------------------------------- ### Language Property Accessors Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Methods to get and set the ISO language code for the document. ```php public function getLanguage(): string public function setLanguage(string $language): static ``` -------------------------------- ### Create Simple Data Table Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Table.md Demonstrates creating a basic table with headers and rows populated from arrays. This is useful for displaying straightforward tabular data. ```php $table = new Table(); $table->setHeaders(['Name', 'Email', 'Role']); $table->addRowFromArray(['Alice', 'alice@example.com', 'Admin']); $table->addRowFromArray(['Bob', 'bob@example.com', 'User']); $section->addElement($table); ``` -------------------------------- ### Description Property Accessors Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Methods to get and set the full text description of the document. ```php public function getDescription(): string public function setDescription(string $description): static ``` -------------------------------- ### Converting DOCX with Hyperlinks to Markdown Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/README.md Illustrates how to open a DOCX file and render its content, including hyperlinks, into Markdown format. ```php use Paperdoc\Support\DocumentManager; // elements are parsed and attached to their TextRun $doc = DocumentManager::open('report.docx'); // Links are rendered as safe [label](url) — labels with ] and URLs with spaces // or parentheses are escaped/wrapped automatically. file_put_contents('report.md', DocumentManager::renderAs($doc, 'md')); ``` -------------------------------- ### Subject Property Accessors Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Methods to get and set the short subject line of the document. ```php public function getSubject(): string public function setSubject(string $subject): static ``` -------------------------------- ### Author Property Accessors Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Methods to get and set the document author's name. ```php public function getAuthor(): string public function setAuthor(string $author): static ``` -------------------------------- ### Create a List with Styled Text Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/ListBlock.md Demonstrates adding list items with custom text styling, such as bold and color, using the `TextStyle` class. ```php use Paperdoc\Document\Style\TextStyle; $section->addBulletList() ->addText( 'Important deadline', TextStyle::make()->setBold()->setColor('#FF0000') ) ->addText('Regular item'); ``` -------------------------------- ### Add and Link to Bookmark Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/OtherElements.md Demonstrates how to add a bookmark to a section and later create a text link pointing to that bookmark. ```php $section->addBookmark('appendix-a'); // Later, link to it $link = TextLink::make('', 'appendix-a'); $para = $section->addText('Go to Appendix A', null, $link); ``` -------------------------------- ### Set Vertical Alignment for a Section Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/types.md Example of setting the vertical alignment for a section's content. ```php use Paperdoc\Enum\VerticalAlignment; $colophon = $doc->openSection('colophon') ->setVerticalAlignment(VerticalAlignment::BOTTOM); ``` -------------------------------- ### Conventional Commit Format Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/CONTRIBUTING.md Template and examples for writing commit messages following Conventional Commits. ```text (): [optional body] [optional footer: Closes #123] ``` ```text feat(renderer): add table border styles to XLSX renderer fix(parser): handle empty paragraphs in DOCX parser docs(readme): add batch processing example test(pdf): add unit tests for PdfRenderer page breaks ``` -------------------------------- ### Create and Save Document (Laravel Facade) Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/README.md Create a new DOCX document using the Paperdoc facade, add content, and save it to the storage path. Ensure the storage directory exists. ```php use Paperdoc\Facades\Paperdoc; // Create $doc = Paperdoc::create('docx', 'Invoice #1042'); $doc->openSection()->addParagraph('Amount due: $500'); Paperdoc::save($doc, storage_path('invoices/1042.docx')); ``` -------------------------------- ### addOrderedList() Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Section.md A convenience method to create and add an ordered list to the section, with an optional starting number. ```APIDOC ## addOrderedList() ### Description Convenience method to create an ordered list starting at a specified number. ### Method Signature `public function addOrderedList(int $start = 1): ListBlock` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **`$start`** (int) - Optional - Default: `1` - The starting number for the ordered list. ### Returns - **`ListBlock`** - The `ListBlock` object for fluent item addition. ### Example ```php $section->addOrderedList(5) ->addText('Item 5') ->addText('Item 6'); ``` ``` -------------------------------- ### LinkInterface Definition Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/types.md Interface for hyperlink objects, providing methods to get URL, anchor, and title. ```php namespace Paperdoc\Contracts; interface LinkInterface { public function getUrl(): string; public function getAnchor(): string; public function getTitle(): string; } ``` -------------------------------- ### PHP Example: Adding and Configuring a Horizontal Rule Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/OtherElements.md Demonstrates how to add a horizontal rule to a section and customize its properties such as width, thickness, color, alignment, and margins. ```php $section->addRule() ->setWidth('50%') ->setThickness(1.5) ->setColor('#CCCCCC') ->setAlignment(Alignment::CENTER) ->setMargins(12.0, 12.0); ``` -------------------------------- ### Get All Section Elements Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Section.md Retrieves an array containing all the block elements currently added to the section. ```php public function getElements(): array ``` -------------------------------- ### Setting and Getting Title Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/TextLink.md Manages the optional tooltip text for the hyperlink, which appears when hovering over the link. ```php public function getTitle(): string public function setTitle(string $v): static ``` -------------------------------- ### Run Static Analysis Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/CONTRIBUTING.md Command to execute static analysis on the codebase. ```bash ./vendor/bin/phpstan analyse ``` -------------------------------- ### Get Alt Text Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Image.md Retrieves the alt text associated with the image. This is useful for accessibility purposes. ```php public function getAlt(): string ``` -------------------------------- ### Metadata Constructor and Factories Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Shows the signature for the constructor and static factory methods to create Metadata instances. ```php public function __construct( string $author = '', string $subject = '', string $description = '', string $keywords = '', ?DateTimeImmutable $createdAt = null, ?DateTimeImmutable $modifiedAt = null, string $language = '' ) public static function make(): static public static function fromArray(array $data): static ``` -------------------------------- ### Image Rendering from Path Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/README.md Use Image::make to render an image from a file path. This method is accepted by all renderers. ```php Image::make($path) ``` -------------------------------- ### Author Property Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Get or set the author of the document. The author's name is stored as a string. ```APIDOC ## Author ### `getAuthor` ```php public function getAuthor(): string ``` Returns the document author's name. ### `setAuthor` ```php public function setAuthor(string $author): static ``` Sets the document author's name. ``` -------------------------------- ### Modified Date Property Accessors Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Metadata.md Methods to get and set the last modification date/time of the document. ```php public function getModifiedAt(): ?DateTimeImmutable public function setModifiedAt(?DateTimeInterface $modifiedAt): static ``` -------------------------------- ### Apply Paragraph Styling Source: https://github.com/paperdoc-dev/paperdoc-lib/blob/main/_autodocs/api-reference/Paragraph.md Demonstrates how to create and apply a ParagraphStyle to a paragraph, including alignment and spacing. ```php use Paperdoc\Document\Style\ParagraphStyle; use Paperdoc\Enum\Alignment; $style = ParagraphStyle::make() ->setAlignment(Alignment::CENTER) ->setLineSpacing(1.5) ->setSpaceBefore(12) ->setSpaceAfter(12); $para = $section->addText('Centered heading text'); $para->setStyle($style); ```