### Poppler Command Line Tool Examples Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73.md Provides examples of using command-line utilities from the Poppler PDF rendering library. This includes getting PDF information, extracting text, converting to HTML, and converting to images. ```bash # Info pdfinfo document.pdf # Extract text pdftotext document.pdf # To HTML pdtohtml document.pdf # To images pdftoppm document.pdf output -png ``` -------------------------------- ### Automated PDF/A Archive System Processing Pipeline Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 15 Practical Examples and Complete Workflo 2829a37af35d817c940cfcd5a61fde09.md Outlines the step-by-step process for an automated PDF/A archival system, starting from receiving an input PDF through pre-validation, conversion, post-validation, metadata extraction, storage, indexing, and audit logging. ```text 1. Input PDF received ↓ 2. Pre-validation check ↓ 3. Conversion to PDF/A ├── Font embedding ├── Color conversion ├── Transparency flattening └── Metadata addition ↓ 4. Post-validation ↓ 5. Metadata extraction ↓ 6. Archive storage ↓ 7. Index generation ↓ 8. Audit log entry ``` -------------------------------- ### PDF Placing Image Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73.md An example of placing an image on a PDF page using the 'Do' operator. It includes setting a transformation matrix ('cm') to control the image's size and position. ```pdf q 200 0 0 150 100 500 cm % Transform /Im1 Do % Paint Q ``` -------------------------------- ### Hello World PDF Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73.md An example demonstrating how to create a PDF that displays 'Hello World'. It includes font resource definition and text rendering commands, serving as a practical introduction to PDF content streams. ```plaintext %PDF-1.4 1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj 2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 >> endobj 3 0 obj << /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >> endobj 4 0 obj << /Length 44 >> stream BT /F1 24 Tf 100 700 Td (Hello World) Tj ET endstream endobj 5 0 obj << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> endobj xref 0 6 0000000000 65535 f 0000000009 00000 n 0000000058 00000 n 0000000115 00000 n 0000000261 00000 n 0000000353 00000 n trailer << /Size 6 /Root 1 0 R >> startxref 422 %%EOF ``` -------------------------------- ### Basic PDF Generation with PDFKit (Node.js) Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 16 Tools and Development - Comprehensive D 2829a37af35d80d796ccdfcd108f6481.md This example shows the basic usage of the PDFKit library in Node.js to create a PDF document, add text to pages, and save it to a file. It requires installing the 'pdfkit' package. ```bash npm install pdfkit ``` ```javascript const PDFDocument = require('pdfkit'); const fs = require('fs'); // Create document const doc = new PDFDocument(); // Pipe to file doc.pipe(fs.createWriteStream('output.pdf')); // Add content doc.fontSize(25) .text('Hello, World!', 100, 100); doc.addPage() .fontSize(12) .text('Page 2 content', 100, 100); // Finalize doc.end(); ``` -------------------------------- ### Ghostscript Command Line Tool Examples Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73.md Illustrates command-line usage for Ghostscript, a powerful interpreter for PostScript and PDF. Examples include compressing PDFs, and converting PDF pages to PNG images. ```bash # Compress gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \ -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH \ -sOutputFile=compressed.pdf input.pdf # Convert to images gs -sDEVICE=png16m -r300 -o page-%d.png input.pdf ``` -------------------------------- ### QPDF Command Line Tool Examples Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73.md Provides common command-line usage examples for the QPDF tool, a command-line utility for PDF manipulation. It covers checking, showing objects, linearizing, encrypting, and merging PDFs. ```bash # Check PDF qpdf --check input.pdf # Show object qpdf --show-object=1 input.pdf # Linearize qpdf --linearize input.pdf output.pdf # Encrypt qpdf --encrypt user owner 256 -- input.pdf output.pdf # Merge qpdf --empty --pages *.pdf -- merged.pdf ``` -------------------------------- ### Poppler Utilities: Installation Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 16 Tools and Development - Comprehensive D 2829a37af35d80d796ccdfcd108f6481.md Provides installation commands for Poppler utilities on Ubuntu/Debian, macOS, and Windows using package managers. ```bash # Ubuntu/Debian sudo apt-get install poppler-utils # macOS brew install poppler # Windows (part of MiKTeX or standalone) choco install poppler ``` -------------------------------- ### Python: PyPDF2/pypdf Installation Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 16 Tools and Development - Comprehensive D 2829a37af35d80d796ccdfcd108f6481.md Provides installation commands for the PyPDF2 and pypdf Python libraries using pip. pypdf is recommended as it is actively maintained. ```bash # PyPDF2 (original, less maintained) pip install PyPDF2 # pypdf (recommended, actively maintained) pip install pypdf ``` -------------------------------- ### pdftk Command Line Tool Examples Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73.md Shows typical command-line operations using pdftk, a versatile PDF manipulation tool. Examples cover merging, splitting, rotating, and extracting specific pages from PDF documents. ```bash # Merge pdftk file1.pdf file2.pdf cat output merged.pdf # Split pdftk input.pdf burst # Rotate pdftk input.pdf cat 1-endeast output rotated.pdf # Extract pages pdftk input.pdf cat 1-3 output pages.pdf ``` -------------------------------- ### PDF Simple Text Display Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73.md A basic example of showing a text string using the 'Tj' operator in PDF. This is the most straightforward way to render text. ```pdf (Hello World) Tj ``` -------------------------------- ### PDF Text Positioning Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73.md An example illustrating the use of 'Td' (Text Move) operator to position lines of text on a PDF page. It shows how to place text and then move down for subsequent lines. ```pdf BT 100 700 Td % Position (Line 1) Tj 0 -20 Td % Move down (Line 2) Tj ET ``` -------------------------------- ### Complete PDF Portfolio Structure Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 14 Advanced Topics - Comprehensive Deep Di 2829a37af35d80c18fb9f2d777263754.md Provides a comprehensive example of a PDF portfolio structure, including the catalog referencing the collection and embedded files, and a collection definition with a custom schema and view. ```PostScript % Catalog with collection 1 0 obj << /Type /Catalog /Pages 2 0 R /Collection 210 0 R /Names << /EmbeddedFiles 250 0 R >> >> endobj % Embedded files name tree 250 0 obj << /Names [ (cover.pdf) 220 0 R (report1.pdf) 221 0 R (report2.pdf) 222 0 R (data.xlsx) 223 0 R ] >> endobj % Collection with custom schema 210 0 obj << /Type /Collection /Schema << /FileName << /Type /CollectionField /Subtype /S /N (Name) /O 1 >> /FileSize << /Type /CollectionField /Subtype /N /N (Size) /O 2 >> /Department << /Type /CollectionField /Subtype /S /N (Dept) /O 3 >> >> /View /D % Detail view /Sort << /S /FileName /A true >> >> endobj ``` -------------------------------- ### Line Width Examples Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 5 Content Streams and Operators - Comprehe 2819a37af35d80ad9097dd5c9db55c99.md Demonstrates setting different line widths using the 'w' operator. Examples include thin, normal, thick, and very thick lines, as well as the minimum possible width. ```PDF 0.5 w % Thin line (0.5 pt) 1 w % Normal line (1 pt, default) 5 w % Thick line (5 pt) 10 w % Very thick line (10 pt) ``` ```PDF 0 w % Thinnest possible (device-dependent) ``` -------------------------------- ### PDF/X Metadata (XML) Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 15 Practical Examples and Complete Workflo 2829a37af35d817c940cfcd5a61fde09.md Provides an example of embedding PDF/X metadata using XML, specifically indicating the PDF/X version. This metadata is crucial for ensuring compliance with print exchange standards. ```XML PDF/X-4 ``` -------------------------------- ### Install QPDF Command-Line Tool Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 16 Tools and Development - Comprehensive D 2829a37af35d80d796ccdfcd108f6481.md Commands to install the QPDF utility on different operating systems (Ubuntu/Debian, macOS, Windows). QPDF is a command-line program for structural PDF manipulation and inspection. ```bash # Ubuntu/Debian sudo apt-get install qpdf # macOS brew install qpdf # Windows choco install qpdf ``` -------------------------------- ### Color Space Conversion Logic Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 15 Practical Examples and Complete Workflo 2829a37af35d817c940cfcd5a61fde09.md This pseudocode describes the process of converting various color spaces (DeviceRGB, DeviceCMYK, DeviceGray) to ICCBased profiles, ensuring consistency and verifying existing ICCBased profiles. ```pseudocode For each color space: If DeviceRGB: Convert to ICCBased sRGB If DeviceCMYK: Convert to ICCBased FOGRA39 If DeviceGray: Convert to ICCBased Gray profile If already ICCBased: Verify profile embedded ``` -------------------------------- ### PDF/UA Metadata Specification Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 15 Practical Examples and Complete Workflo 2829a37af35d817c940cfcd5a61fde09.md XML snippet defining the PDF/UA (Universal Accessibility) standard compliance for a PDF document. It specifies the PDF version as Part 1, indicating adherence to the accessibility guidelines. ```xml 1 ``` -------------------------------- ### PDF Accessibility Tagging Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 4 Document Structure - Comprehensive Deep 2819a37af35d80b1898bf564a95163d1.md Provides an example of PDF tagging for accessibility, including the /StructTreeRoot, /MarkInfo dictionary, and language specification. ```postscript /StructTreeRoot with proper hierarchy /MarkInfo << /Marked true >> /Lang (en-US) ``` -------------------------------- ### Complete PDF Page Object Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 3 Object Types and Syntax - Deep Dive 2819a37af35d8094b2add8ab6378eae8.md Provides a comprehensive example of a PDF page object. This includes its type, parent reference, media box dimensions, content stream reference, resource dictionary (fonts, procsets), and rotation. ```pdf 3 0 obj << /Type /Page % Type: Page /Parent 2 0 R % Reference to parent /MediaBox [0 0 612 792] % Letter size /Contents 4 0 R % Content stream /Resources << % Resource dictionary /Font << % Font resources /F1 7 0 R % Font reference >> /ProcSet [/PDF /Text] % Procedure sets >> /Rotate 0 % No rotation >> endobj ``` -------------------------------- ### Uncolored Tiling Pattern Example (PDF Object) Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 14 Advanced Topics - Comprehensive Deep Di 2829a37af35d80c18fb9f2d777263754.md Illustrates an uncolored tiling pattern, where the color is applied when the pattern is used. This example defines a simple pattern stream and shows how to apply a specific color to it in the content stream. ```pdf 35 0 obj << /Type /Pattern /PatternType 1 /PaintType 2 % Uncolored /TilingType 1 /BBox [0 0 10 10] /XStep 10 /YStep 10 /Length 45 >> stream q 0 0 5 5 re f % Small square (no color defined) Q endstream endobj % Use with color /Pattern cs 1 0 0 % Red color components /P2 scn % Pattern with color 100 500 200 150 re f ``` -------------------------------- ### Install Ghostscript on Various Systems Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 16 Tools and Development - Comprehensive D 2829a37af35d80d796ccdfcd108f6481.md Provides installation commands for Ghostscript on Ubuntu/Debian, macOS, and Windows using their respective package managers. Ghostscript is a PostScript and PDF interpreter used for conversion and optimization. ```bash # Ubuntu/Debian sudo apt-get install ghostscript # macOS brew install ghostscript # Windows choco install ghostscript ``` -------------------------------- ### Complete PDF 3D Annotation Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 14 Advanced Topics - Comprehensive Deep Di 2829a37af35d80c18fb9f2d777263754.md A comprehensive example demonstrating the integration of a 3D annotation within a PDF page. It includes the page definition, content stream with text, the 3D annotation itself, and the 3D artwork stream, showcasing a practical implementation. ```pdf % Page with 3D content 3 0 obj << /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R /Annots [70 0 R] % 3D annotation /Resources << /Font << /F1 10 0 R >> >> >> endobj 4 0 obj << /Length 120 >> stream BT /F1 18 Tf 200 750 Td (3D Model Viewer) Tj /F1 12 Tf 0 -30 Td (Click below to interact with 3D model) Tj ET endstream endobj 70 0 obj << /Type /Annot /Subtype /3D /Rect [100 200 500 600] /3DD 75 0 R /3DV << /Type /3DView /XN (Default) /MS /M /C2W [1 0 0 0 1 0 0 0 1 0 0 -10] /CO 10 /P << /Subtype /P /FOV 45 >> >> /3DA << /A /PO >> /P 3 0 R >> endobj 75 0 obj << /Type /3D /Subtype /U3D /Length 125000 /Filter /FlateDecode >> stream ... compressed U3D model data ... endstream endobj ``` -------------------------------- ### PDF Cross-Reference Stream Entry Types Examples Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 11 Compression Techniques - Comprehensive 2819a37af35d8010a1cbf8f4f7e51f73.md Provides examples of the three entry types within a PDF cross-reference stream: Type 0 (Free), Type 1 (Uncompressed Object), and Type 2 (Compressed Object). Each example shows the binary representation and its interpretation based on the /W array. ```pdf Type 0 (Free Entry): [0] [next_free] [generation] Example: 00 000005 0A - Type: 0 (free) - Next free object: 5 - Generation: 10 Type 1 (Uncompressed Object): [1] [offset] [generation] Example: 01 0012A4 00 - Type: 1 (in-use) - Byte offset: 0x12A4 (4772) - Generation: 0 Type 2 (Compressed Object): [2] [obj_stream_num] [index] Example: 02 000064 03 - Type: 2 (in object stream) - Object stream number: 100 - Index in stream: 3 ``` -------------------------------- ### Install Puppeteer Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 16 Tools and Development - Comprehensive D 2829a37af35d80d796ccdfcd108f6481.md Installs the Puppeteer library using npm. Puppeteer is a Node.js library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. ```bash npm install puppeteer ``` -------------------------------- ### Complete Line Style Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 5 Content Streams and Operators - Comprehe 2819a37af35d80ad9097dd5c9db55c99.md This comprehensive example applies multiple line style operators at once. It sets a thick, red, dashed line with round caps and joins, then draws a decorative border using these styles. State is saved and restored using 'q' and 'Q'. ```PDF q % Save state % Thick, red, dashed line with round caps 5 w % 5pt width 1 0 0 RG % Red color 1 J % Round caps 1 j % Round joins [10 5] 0 d % Dash pattern % Draw decorative border 50 50 m 550 50 l 550 750 l 50 750 l h S Q % Restore state ``` -------------------------------- ### Encrypted PDF Security Structure Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 15 Practical Examples and Complete Workflo 2829a37af35d817c940cfcd5a61fde09.md Illustrates the PDF structure for encryption and security features. It shows the trailer referencing an encryption dictionary with AES-256 settings and permissions, and the catalog referencing AcroForm for signature fields and Perms for usage rights. ```PostScript Trailer └── Encrypt (encryption dictionary) ├── Filter /Standard ├── V 5 % AES-256 ├── R 6 % Revision 6 ├── P (permissions) └── CF (crypt filters) Catalog ├── AcroForm (signature fields) │ ├── SigFlags 3 % Signatures exist + append-only │ └── Fields │ └── Signature field └── Perms (usage rights) ``` -------------------------------- ### Invoice Generation: Page Object Structure Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 15 Practical Examples and Complete Workflo 2829a37af35d817c940cfcd5a61fde09.md Defines the essential page boxes for an invoice, ensuring consistent layout and print readiness. Specifies MediaBox, CropBox, and BleedBox for standard page dimensions. ```pdf /MediaBox [0 0 612 792] % Letter size /CropBox [0 0 612 792] /BleedBox [0 0 612 792] ``` -------------------------------- ### PDF/A Validation Workflow with veraPDF Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 15 Practical Examples and Complete Workflo 2829a37af35d817c940cfcd5a61fde09.md This pseudocode outlines the validation workflow using veraPDF, including pre-validation checks, running validation profiles, handling rule failures with automatic fixes and re-validation, and generating compliance reports. ```pseudocode Using veraPDF: 1. Run validation profile 2. Check all rules passed 3. If failures: - Log specific errors - Attempt automatic fixes - Re-validate 4. Generate compliance report ``` -------------------------------- ### Transparency Flattening Process Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 15 Practical Examples and Complete Workflo 2829a37af35d817c940cfcd5a61fde09.md This pseudocode details the steps involved in flattening transparency in PDF pages, including identifying transparent objects, rasterizing complex elements, converting blend modes, and merging layers while preserving visual appearance. ```pseudocode For each page with transparency: Identify transparent objects Rasterize complex transparency Convert blend modes to opaque equivalents Merge layers Maintain visual appearance ``` -------------------------------- ### PDF Resources Object Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 2 PDF File Structure - Deep Dive 2819a37af35d8071babbfc4919f3c020.md Example of a PDF Resources object. This object declares resources used on a page, such as fonts (e.g., '/F1 8 0 R') and processing sets ('/ProcSet'). ```plaintext 7 0 obj << /Font << /F1 8 0 R >> /ProcSet [/PDF /Text] >> endobj ``` -------------------------------- ### Creating a Minimal PDF with Text Source: https://context7.com/intellig-io/intelli-pdf-format-guide/llms.txt A complete, working example demonstrating how to create a minimal PDF file containing the text 'Hello World'. It illustrates the necessary objects and structure for basic PDF content. ```pdf %PDF-1.4 1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj 2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 >> endobj 3 0 obj << /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >> endobj 4 0 obj << /Length 44 >> stream BT /F1 24 Tf 100 700 Td (Hello World) Tj ET endstream endobj 5 0 obj << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> endobj xref 0 6 0000000000 65535 f 0000000009 00000 n 0000000058 00000 n 0000000115 00000 n 0000000261 00000 n 0000000353 00000 n trailer << /Size 6 /Root 1 0 R >> startxref 422 %%EOF ``` -------------------------------- ### Apache PDFBox Basic PDF Creation Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 16 Tools and Development - Comprehensive D 2829a37af35d80d796ccdfcd108f6481.md Create a simple PDF document with 'Hello, World!' text using Apache PDFBox. This example demonstrates initializing a document, adding a page, writing text, and saving the PDF. ```java import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.font.PDType1Font; public class CreatePDF { public static void main(String[] args) throws Exception { PDDocument document = new PDDocument(); PDPage page = new PDPage(); document.addPage(page); PDPageContentStream contentStream = new PDPageContentStream(document, page); contentStream.beginText(); contentStream.setFont(PDType1Font.HELVETICA_BOLD, 12); contentStream.newLineAtOffset(100, 700); contentStream.showText("Hello, World!"); contentStream.endText(); contentStream.close(); document.save("output.pdf"); document.close(); }} ``` -------------------------------- ### PDF Header Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73.md The header of a PDF file indicates the version of the PDF specification used. It typically starts with '%PDF-' followed by the version number. The second line, often containing binary characters, signals the presence of binary data within the file. ```plaintext %PDF-1.7 %âãÏÓ ``` -------------------------------- ### Run-Length Encoding Algorithm Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 11 Compression Techniques - Comprehensive 2819a37af35d8010a1cbf8f4f7e51f73.md This section explains the Run-Length Encoding (RLE) algorithm with a practical example of binary data compression. It shows how sequences of identical bytes are represented by a count and the byte value, and how non-repeating bytes are handled. ```text Input: AAAABBCCCCCCDAA Output: 4A 2B 6C 1D 2A Encoding: - Count consecutive identical bytes - Store: count + byte value - For non-repeating: special marker Actual Format: Length byte (0-127): Copy next Length+1 bytes literally Length byte (129-255): Repeat next byte (257-Length) times Length byte = 128: No operation (skip) Original: [100] [100] [100] [50] [50] [200] Encoded: [254] [100] [253] [50] [0] [200] Breakdown: [254][100] = Repeat 100 three times (257-254=3) [253][50] = Repeat 50 two times [0][200] = Copy next 1 byte literally ``` -------------------------------- ### PDF Xref Table Subsection Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 2 PDF File Structure - Deep Dive 2819a37af35d8071babbfc4919f3c020.md Demonstrates how a PDF Xref table can be structured with multiple subsections. Each subsection begins with a header indicating the starting object number and the count of entries, followed by the individual object entries. ```plaintext xref 0 1 0000000000 65535 f 3 2 0000000156 00000 n 0000000298 00000 n 10 3 0000000451 00000 n 0000000595 00000 n 0000000789 00000 n ``` -------------------------------- ### QPDF Command-Line Examples Source: https://context7.com/intellig-io/intelli-pdf-format-guide/llms.txt Provides various command-line examples using the QPDF utility for common PDF manipulation tasks. This includes checking structure, showing object details, linearizing, encrypting, decrypting, merging, extracting pages, and compressing PDFs. ```bash # ===== QPDF Examples ===== # Validate PDF structure qpdf --check document.pdf # Show internal object structure qpdf --show-object=1 document.pdf qpdf --show-xref document.pdf # Linearize for web viewing qpdf --linearize input.pdf output.pdf # Encrypt with user and owner passwords qpdf --encrypt userpass ownerpass 256 \ --print=full --modify=none -- input.pdf encrypted.pdf # Decrypt PDF (requires password) qpdf --decrypt --password=userpass encrypted.pdf decrypted.pdf # Merge multiple PDFs qpdf --empty --pages file1.pdf file2.pdf file3.pdf -- merged.pdf # Extract specific pages qpdf input.pdf --pages . 1-5,10,15-20 -- output.pdf # Compress using object streams qpdf --object-streams=generate --compression-level=9 input.pdf compressed.pdf ``` -------------------------------- ### PDF Layered Content Stream Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 4 Document Structure - Comprehensive Deep 2819a37af35d80b1898bf564a95163d1.md Provides an example of constructing layered content streams for a PDF page. It demonstrates setting colors, drawing rectangles for backgrounds, rendering text, and applying transparency and transformations for a watermark. ```text Example - Layered Content: ``` % Background stream (8 0 R) 0.9 0.9 0.9 rg % Light gray 0 0 612 792 re f % Content stream (9 0 R) BT /F1 12 Tf 100 700 Td (Main content) Tj ET % Watermark stream (10 0 R) q /GS1 gs % Transparency 1 0.707 -0.707 1 306 396 cm BT /F2 48 Tf 1 0 0 rg (DRAFT) Tj ET Q ``` ``` -------------------------------- ### Named Actions for Document Entry Points using JavaScript Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 9 Interactive Features and Forms - Compreh 2819a37af35d80ff9d54e00eb967e504.md Demonstrates how to use named actions to create multiple entry points or provide specific startup behavior for a document. This example checks if it's the first time the document is opened and displays a welcome message accordingly. ```JavaScript // Check if this is first time opening if (typeof global.firstVisit === "undefined") { global.firstVisit = false; app.alert("Welcome! This appears to be your first visit."); } ``` -------------------------------- ### PDF Trailer Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73.md The trailer section of a PDF file follows the cross-reference table and contains essential information like the total number of entries in the xref table ('/Size'), a reference to the document's root catalog ('/Root'), the starting byte offset of the xref table ('startxref'), and the end-of-file marker ('%%EOF'). ```plaintext trailer << /Size 4 /Root 1 0 R >> startxref 245 %%EOF ``` -------------------------------- ### PDF Version Line Formats Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 2 PDF File Structure - Deep Dive 2819a37af35d8071babbfc4919f3c020.md Shows various examples of the PDF version line format, which starts with '%PDF-' followed by the major and minor version numbers. This line must appear within the first 1024 bytes of the file, typically as the very first line. ```plaintext %PDF-1.0 (PDF 1.0 - original, 1993) ``` ```plaintext %PDF-1.4 (PDF 1.4 - transparency, 2001) ``` ```plaintext %PDF-1.7 (PDF 1.7 - ISO 32000-1, 2008) ``` ```plaintext %PDF-2.0 (PDF 2.0 - ISO 32000-2, 2017) ``` -------------------------------- ### Ghostscript Command-Line Examples Source: https://context7.com/intellig-io/intelli-pdf-format-guide/llms.txt Offers command-line examples using Ghostscript (gs) for PDF processing. Demonstrates aggressive compression, conversion to images (PNG), conversion to grayscale, and reducing file size with various quality settings. ```bash # ===== Ghostscript Examples ===== # Compress PDF aggressively gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \ -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH \ -sOutputFile=compressed.pdf input.pdf # Convert PDF to images (PNG, 300 DPI) gs -sDEVICE=png16m -r300 -o page-%03d.png input.pdf # Convert to grayscale gs -sDEVICE=pdfwrite -dProcessColorModel=/DeviceGray \ -dColorConversionStrategy=/Gray -dPDFUseOldCMS=false \ -dNOPAUSE -dBATCH -sOutputFile=gray.pdf input.pdf # Reduce file size with quality settings # /screen (72dpi), /ebook (150dpi), /printer (300dpi), /prepress (300dpi) gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \ -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH \ -sOutputFile=optimized.pdf large.pdf ``` -------------------------------- ### Create Interactive Product Demonstration PDF (Python) Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 14 Advanced Topics - Comprehensive Deep Di 2829a37af35d80c18fb9f2d777263754.md Generates a PDF with a 3D product model and video demonstration. Includes annotations for 3D model embedding and rich media for video playback. Requires a 3D model file and a video file to be embedded. ```python def create_product_demo(): """Create interactive product demonstration PDF""" # 3D model annotation model_3d = { 'Type': '/Annot', 'Subtype': '/3D', 'Rect': [100, 400, 500, 700], '3DD': { 'Type': '/3D', 'Subtype': '/U3D', }, '3DV': { 'Type': '/3DView', 'XN': '(Isometric View)', 'MS': '/M', 'C2W': [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -10], 'CO': 10, 'P': { 'Subtype': '/P', 'FOV': 45 }, 'VA': [ {'XN': '(Front)', 'MS': '/M', ...}, {'XN': '(Top)', 'MS': '/M', ...}, {'XN': '(Right)', 'MS': '/M', ...} ] }, '3DA': { 'A': '/PO', 'D': '/PC' } } # Video demonstration video_richmedia = { 'Type': '/Annot', 'Subtype': '/RichMedia', 'Rect': [100, 100, 500, 350], 'RichMediaContent': { 'Assets': { 'Names': [ ('demo.mp4', { 'Type': '/Filespec', 'F': 'demo.mp4', }) ] }, 'Configurations': [{ 'Type': '/RichMediaConfiguration', 'Subtype': '/Video', 'Instances': [{ 'Type': '/RichMediaInstance', 'Params': { 'Binding': '/Foreground', 'FlashVars': 'autoPlay=false&controls=true' } }] }] } } # Interactive buttons for view control buttons = create_3d_view_buttons(model_3d) return { '3d_model': model_3d, 'video': video_richmedia, 'controls': buttons } ``` -------------------------------- ### Text Field with Validation and Formatting (JavaScript) Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 15 Practical Examples and Complete Workflo 2829a37af35d817c940cfcd5a61fde09.md An example of a text field configuration in PDF, utilizing JavaScript for keystroke validation and formatting. This ensures data integrity and consistency as the user types. ```pdf /T (email) % Field name /FT /Tx % Field type: text /V () % Initial value /Ff 4194304 % Flags: required field /Q 0 % Left justified /DA (/Helv 11 Tf 0 g) /MaxLen 100 /AA << /K << % Keystroke validation /S /JavaScript /JS (emailValidation();) >> /F << % Format action /S /JavaScript /JS (formatEmail();) >> >> ``` -------------------------------- ### AcroForm Dictionary Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 15 Practical Examples and Complete Workflo 2829a37af35d817c940cfcd5a61fde09.md This snippet shows the structure of the AcroForm dictionary, which defines the interactive form elements. It includes references to fields, default appearance, and default resources like fonts. ```pdf /AcroForm << /Fields [10 0 R 11 0 R 12 0 R] % References to field groups /NeedAppearances true /SigFlags 0 /DA (/Helvetica 12 Tf 0 g) % Default appearance /DR << % Default resources /Font << /Helv 20 0 R /HelvBold 21 0 R >> >> >> ``` -------------------------------- ### JavaScript PDF 'this' (Doc) Object Examples Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 9 Interactive Features and Forms - Compreh 2819a37af35d80ff9d54e00eb967e504.md Illustrates common operations using the `this` (or `Doc`) object in PDF JavaScript, which refers to the current document. Examples include getting and setting field values, retrieving all field names, and accessing document properties like file name and page count. ```javascript // Get field var field = this.getField("fieldName"); // Set field value this.getField("total").value = 100.50; // Get all field names var fields = this.getField(); for (var i = 0; i < fields.length; i++) { console.println(fields[i].name); } // Document properties console.println(this.documentFileName); console.println(this.numPages); console.println(this.pageNum); // Current page (0-indexed) ``` -------------------------------- ### PDF: Smooth Curves with Bézier Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 5 Content Streams and Operators - Comprehe 2819a37af35d80ad9097dd5c9db55c99.md Illustrates the creation of natural-looking curves in PDF using Bézier path construction operators. This example defines a wave pattern by specifying control points for cubic Bézier curves ('c') after moving to the starting point ('m'). The path is then stroked ('S') to render the curves. ```pdf % Wave pattern 100 200 m % First wave 150 250 200 250 250 200 c % Second wave 300 150 350 150 400 200 c % Third wave 450 250 500 250 550 200 c S ``` -------------------------------- ### Create PDFs with ReportLab (Python) Source: https://context7.com/intellig-io/intelli-pdf-format-guide/llms.txt This Python snippet shows how to create PDF documents from scratch using the ReportLab library. It covers setting up the canvas, drawing text, shapes, and images, and managing pages. Dependencies include ReportLab. ```python from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import letter, A4 from reportlab.lib.units import inch from reportlab.lib.colors import blue, red, black # Create simple PDF c = canvas.Canvas("output.pdf", pagesize=letter) width, height = letter # Draw text c.setFont("Helvetica", 12) c.drawString(100, height - 100, "Hello World") # Draw shapes c.setStrokeColor(red) c.setFillColor(blue) c.rect(100, 500, 200, 100, fill=1, stroke=1) c.circle(300, 400, 50, fill=0, stroke=1) # Draw image c.drawImage("logo.png", 100, 300, width=2*inch, height=1*inch) c.showPage() # New page c.save() ``` -------------------------------- ### Install PDFtk on Various Systems Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 16 Tools and Development - Comprehensive D 2829a37af35d80d796ccdfcd108f6481.md Provides installation commands for PDFtk (or its Java alternative) on Ubuntu/Debian and macOS, along with a note for Windows users to download from the official PDF Labs website. PDFtk is a command-line tool for common PDF operations. ```bash # Ubuntu/Debian sudo apt-get install pdftk # macOS (pdftk-java) brew install pdftk-java # Windows # Download from: https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/ ``` -------------------------------- ### Install pdf-lib Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 16 Tools and Development - Comprehensive D 2829a37af35d80d796ccdfcd108f6481.md Installs the pdf-lib library using npm. This library is used for PDF manipulation in Node.js. ```bash npm install pdf-lib ``` -------------------------------- ### PDF/A-1b Compliance Example Source: https://context7.com/intellig-io/intelli-pdf-format-guide/llms.txt Provides an example of PDF objects required for PDF/A-1b archival compliance. This includes the Catalog dictionary specifying metadata and output intents, and the Metadata object containing XMP data, along with an OutputIntent object for color management. ```pdf % PDF/A-1b (Archival) compliance 1 0 obj << /Type /Catalog /Pages 2 0 R /Metadata 100 0 R % XMP metadata required /OutputIntents [101 0 R] % Output intent required >> endobj 100 0 obj << /Type /Metadata /Subtype /XML /Length 2345 >> stream 1 B endstream endobj % Output intent for color management 101 0 obj << /Type /OutputIntent /S /GTS_PDFA1 /OutputConditionIdentifier (sRGB IEC61966-2.1) /Info (sRGB) /DestOutputProfile 102 0 R % ICC profile >> endobj % PDF/A Requirements: % - All fonts must be embedded % - No encryption allowed % - No JavaScript or executable content % - Self-contained (all resources embedded) ``` -------------------------------- ### PDF Text Leading (TL) Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 6 Text Rendering - Comprehensive Deep Dive 2819a37af35d8053941dd045f12054a1.md Provides an example of setting text leading (line spacing) in PDF using the 'TL' operator. This affects the vertical spacing between lines when using the T* operator. The example shows tight and loose leading. ```PostScript BT /F1 12 Tf 100 700 Td 12 TL % Tight leading (Line 1) ' (Line 2) ' (Line 3) ' 50 200 Td % Move to new position 20 TL % Loose leading (Line 1) ' (Line 2) ' (Line 3) ' ET ``` -------------------------------- ### PDF EmbeddedFiles Name Tree Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 15 Practical Examples and Complete Workflo 2829a37af35d817c940cfcd5a61fde09.md Represents the EmbeddedFiles Name Tree in a PDF, listing the names of embedded files and their corresponding object references. ```pdf /Names << /EmbeddedFiles << /Names [ (project1.jpg) 100 0 R (demo.mp4) 101 0 R (proposal.pdf) 102 0 R ] >> >> ``` -------------------------------- ### Poppler Utilities - pdfinfo Example Source: https://context7.com/intellig-io/intelli-pdf-format-guide/llms.txt Shows how to use the `pdfinfo` command-line utility from the Poppler suite to extract metadata from a PDF file, including general information and specific XMP metadata. ```bash # ===== Poppler Utilities ===== # Extract metadata pdfinfo document.pdf pdfinfo -meta document.pdf # XMP metadata ``` -------------------------------- ### PDF Content Stream Examples - Postfix Notation Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 5 Content Streams and Operators - Comprehe 2819a37af35d80ad9097dd5c9db55c99.md Demonstrates the use of postfix (Reverse Polish) notation in PDF content streams for common graphics operations. Examples include moving to a specific coordinate, setting the fill color using RGB values, and setting the font and size. ```pdf 100 200 m % Move to (100, 200) 1 0 0 rg % Set fill color to red (RGB: 1, 0, 0) /F1 12 Tf % Set font to F1 at 12 points ``` -------------------------------- ### Submit Button Action (JavaScript) Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 15 Practical Examples and Complete Workflo 2829a37af35d817c940cfcd5a61fde09.md Configuration for a submit button that triggers a form submission to a specified URL. It includes an action to perform validation before submitting, using JavaScript. ```pdf /Subtype /Widget /FT /Btn % Button field /Ff 65536 % Push button flag /T (submit_button) /TU (Submit Application) /A << % Action /S /SubmitForm /F (https://api.example.com/submit) /Flags 4 % Include field values >> /AA << /D << % Mouse down - validate before submit /S /JavaScript /JS (validateAllFields();) >> >> ``` -------------------------------- ### Basic PDF Creation with ReportLab Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 16 Tools and Development - Comprehensive D 2829a37af35d80d796ccdfcd108f6481.md Introduces the ReportLab library for creating PDFs from scratch. Demonstrates creating a canvas, drawing text, setting fonts, drawing shapes, adding images, and saving the PDF. Requires the reportlab library. ```bash pip install reportlab ``` ```python from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import letter, A4 from reportlab.lib.units import inch # Create canvas c = canvas.Canvas("hello.pdf", pagesize=letter) width, height = letter # Draw text c.drawString(100, 750, "Hello, World!") # Set font c.setFont("Helvetica-Bold", 24) c.drawString(100, 700, "Large Bold Text") # Draw shapes c.rect(100, 600, 200, 100, stroke=1, fill=0) c.circle(300, 500, 50, stroke=1, fill=1) c.line(100, 450, 500, 450) # Add image # c.drawImage("logo.png", 100, 300, width=200, height=100) # Save c.save() ``` -------------------------------- ### Correct Xref Entry Byte Padding Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 2 PDF File Structure - Deep Dive 2819a37af35d8071babbfc4919f3c020.md This example highlights the correct byte padding for xref entries in a PDF file. Each entry must be exactly 20 bytes, including the newline character. The 'wrong' example shows insufficient padding, while the 'correct' example demonstrates the required format. ```text Example (wrong): 15 0 n % Only 6 bytes - WRONG! Example (correct): 0000000015 00000 n % Exactly 20 bytes including EOL ``` -------------------------------- ### Grayscale Color Examples Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 5 Content Streams and Operators - Comprehe 2819a37af35d80ad9097dd5c9db55c99.md Examples of setting fill and stroke colors using grayscale values. This includes setting black, white, 50% gray fill, and a light gray stroke. ```PDF 0 g % Black fill 1 g % White fill 0.5 g % 50% gray fill 0.75 G % Light gray stroke ``` -------------------------------- ### OCMD Policy Examples - PDF Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 14 Advanced Topics - Comprehensive Deep Di 2829a37af35d80c18fb9f2d777263754.md Lists common policies used in Optional Content Membership Dictionaries (OCMDs) to define visibility rules based on the ON/OFF states of associated OCGs, including AllOn, AnyOn, AnyOff, and AllOff. ```pdf Policies: - /AllOn - All referenced OCGs must be ON - /AnyOn - At least one OCG must be ON - /AnyOff - At least one OCG must be OFF - /AllOff - All OCGs must be OFF ``` -------------------------------- ### Miter Limit Example Source: https://github.com/intellig-io/intelli-pdf-format-guide/blob/main/The Complete PDF Format Guide 2819a37af35d8073a08eee30dd28ef73/Chapter 5 Content Streams and Operators - Comprehe 2819a37af35d80ad9097dd5c9db55c99.md This example shows how to set the miter limit using the 'M' operator. It demonstrates setting a limit of 5 and then drawing sharp angles to observe how they might be beveled. ```PDF 0 j % Miter joins 5 M % Limit = 5 5 w % Sharp angles will be beveled ```