### PDF Trailer Example Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/validate_pdf_a2_b_full_example.txt An example of a PDF trailer, containing the size of the cross-reference table and references to the root and info objects. ```pdf trailer << /Size 20 /Root 19 0 R /Info 17 0 R /ID [(v2U9mGQ+WUI4624aqXDQ5g==) (v2U9mGQ+WUI4624aqXDQ5g==)] >> startxref 11149 %%EOF ``` -------------------------------- ### XMP Metadata Example Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/validate_pdf_ua1_full_example.txt An example of XMP metadata embedded within a PDF, including title, language, and PDF version. ```xml a nice titleen11application/pdfqqb7gDlHhciUx5YW+9A0tA==qqb7gDlHhciUx5YW+9A0tA==proof1.7 ``` -------------------------------- ### PDF Cross-Reference Table Example Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/validate_pdf_a2_b_full_example.txt An example of a PDF cross-reference table (xref), listing the offsets of objects within the PDF file. ```pdf xref 0 20 0000000000 65535 f 0000000016 00000 n 0000000081 00000 n 0000000272 00000 n 0000000296 00000 n 0000000331 00000 n 0000000366 00000 n 0000000508 00000 n 0000000670 00000 n 0000001012 00000 n 0000001256 00000 n 0000001373 00000 n 0000001488 00000 n 0000002314 00000 n 0000005208 00000 n 0000005551 00000 n 0000006208 00000 n 0000006983 00000 n 0000007073 00000 n 0000011039 00000 n ``` -------------------------------- ### PDF Metadata Example Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/validate_pdf_a2_u_full_example.txt An example of metadata embedded within a PDF document, specifying properties like producer, trapped status, and format. ```rdf rdf:li rdf:parseType="Resource">internalName of the application that created the PDF documentProducerTextinternalWhether the document has been trappedTrappedText2U1application/pdfv2U9mGQ+WUI4624aqXDQ5g==v2U9mGQ+WUI4624aqXDQ5g==proof1.7 endstream endobj ``` -------------------------------- ### PDF Trailer Example Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/path_with_luma.txt An example of a PDF trailer. ```pdf trailer << /Size 6 /Root 5 0 R /ID [(3lBjeyWpXfDDEQhiTGpA0Q==) (3lBjeyWpXfDDEQhiTGpA0Q==)] >> ``` -------------------------------- ### PDF Metadata Example Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/validate_pdf_a2_b_full_example.txt An example of RDF metadata embedded within a PDF document, specifying properties like producer, trapped status, and format. ```rdf rdf:li rdf:parseType="Resource">internalName of the application that created the PDF documentProducerTextinternalWhether the document has been trappedTrappedText2B1application/pdfv2U9mGQ+WUI4624aqXDQ5g==v2U9mGQ+WUI4624aqXDQ5g==proof1.7 endstream endobj ``` -------------------------------- ### PDF Catalog Object Example Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/validate_pdf_a3_u_full_example.txt An example of a PDF catalog object, defining the root of the document's object hierarchy and referencing other key objects like pages, metadata, and output intents. ```pdf 19 0 obj << /Type /Catalog /Pages 1 0 R /Metadata 18 0 R /OutputIntents 3 0 R /Lang (en) >> endobj ``` -------------------------------- ### PDF Cross-Reference Table Example Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/validate_pdf_a3_u_full_example.txt An example of a PDF cross-reference table (xref), which provides the byte offsets for each object in the PDF file, enabling efficient random access. ```pdf xref 0 20 0000000000 65535 f 0000000016 00000 n 0000000081 00000 n 0000000272 00000 n 0000000296 00000 n 0000000331 00000 n 0000000366 00000 n 0000000508 00000 n 0000000670 00000 n 0000001012 00000 n 0000001256 00000 n 0000001373 00000 n 0000001488 00000 n 0000002314 00000 n 0000005208 00000 n 0000005551 00000 n 0000006208 00000 n 0000006983 00000 n 0000007073 00000 n 0000011039 00000 n trailer << /Size 20 /Root 19 0 R /Info 17 0 R /ID [(v2U9mGQ+WUI4624aqXDQ5g==) (v2U9mGQ+WUI4624aqXDQ5g==)] >> startxref 11149 %%EOF ``` -------------------------------- ### Example Source: https://github.com/laurenzv/krilla/blob/main/crates/krilla/README.md This example shows some of the features of krilla in action. It creates a PDF file with two pages. On the first page, it adds two small pieces of text, and on the second page it draws a triangle with a gradient fill. ```rust use std::path::{self, PathBuf}; use krilla::color::rgb; use krilla::text::Font; use krilla::geom::{Point, PathBuilder}; use krilla::paint::{SpreadMethod, LinearGradient, Stop, FillRule}; use krilla::text::TextDirection; use krilla::paint::Fill; use krilla::Document; use krilla::page::PageSettings; use krilla::num::NormalizedF32; // Create a new document. let mut document = Document::new(); // Load a font. let font = { let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../assets/fonts/NotoSans-Regular.ttf"); let data = std::fs::read(&path).unwrap(); Font::new(data.into(), 0).unwrap() }; // Add a new page with dimensions 200x200. let mut page = document.start_page_with(PageSettings::from_wh(200.0, 200.0).unwrap()); // Get the surface of the page. let mut surface = page.surface(); // Draw some text. surface.draw_text( Point::from_xy(0.0, 25.0), font.clone(), 14.0, "This text has font size 14!", false, TextDirection::Auto ); surface.set_fill(Some(Fill { paint: rgb::Color::new(255, 0, 0).into(), opacity: NormalizedF32::new(0.5).unwrap(), rule: Default::default(), })); // Draw some more text, in a different color with an opacity and bigger font size. surface.draw_text( Point::from_xy(0.0, 50.0), font.clone(), 16.0, "This text has font size 16!", false, TextDirection::Auto ); // Finish the page. surface.finish(); page.finish(); // Start a new page. let mut page = document.start_page_with(PageSettings::from_wh(200.0, 200.0).unwrap()); // Create the triangle. let triangle = { let mut pb = PathBuilder::new(); pb.move_to(100.0, 20.0); pb.line_to(160.0, 160.0); pb.line_to(40.0, 160.0); pb.close(); pb.finish().unwrap() }; // Create the linear gradient. let lg = LinearGradient { x1: 60.0, y1: 0.0, x2: 140.0, y2: 0.0, transform: Default::default(), spread_method: SpreadMethod::Repeat, stops: vec![ Stop { offset: NormalizedF32::new(0.2).unwrap(), color: rgb::Color::new(255, 0, 0).into(), opacity: NormalizedF32::ONE, }, Stop { offset: NormalizedF32::new(0.8).unwrap(), color: rgb::Color::new(255, 255, 0).into(), opacity: NormalizedF32::ONE, }, ], anti_alias: false, }; let mut surface = page.surface(); // Set the fill. surface.set_fill(Some(Fill { paint: lg.into(), rule: FillRule::EvenOdd, opacity: NormalizedF32::ONE })); // Fill the path. surface.draw_path(&triangle); // Finish up and write the resulting PDF. surface.finish(); page.finish(); let pdf = document.finish().unwrap(); let path = path::absolute("basic.pdf").unwrap(); eprintln!("Saved PDF to '{}'", path.display()); // Write the PDF to a file. std::fs::write(path, &pdf).unwrap(); ``` -------------------------------- ### PDF Page Label Object Example Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/page_label_after_embedded_page.txt This snippet shows a PDF object defining page labels with Roman numerals starting from the second page. ```pdf 4 0 obj << /Type /PageLabel /S /r /St 2 >> endobj ``` -------------------------------- ### PDF Object Example Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/validate_pdf_ua1_full_example.txt An example of a PDF object defining a link annotation. ```pdf %PDF-1.7 %AAAA 1 0 obj << /Type /Pages /Count 1 /Kids [12 0 R] >> endobj 2 0 obj << /Type /Outlines >> endobj 3 0 obj << /Type /StructTreeRoot /RoleMap << /Datetime /Span /Terms /Part /Title /P /Strong /Span /Em /Span >> /K [6 0 R] /ParentTree << /Nums [0 5 0 R 1 4 0 R] >> /ParentTreeNextKey 2 >> endobj 4 0 obj [6 0 R] endobj 5 0 obj << /Type /StructElem /S /Link /P 6 0 R /K [<< /Type /OBJR /Pg 12 0 R /Obj 7 0 R >>] >> endobj 6 0 obj << /Type /StructElem /S /Document /P 3 0 R /K [0 5 0 R] /Pg 12 0 R >> endobj 7 0 obj << /Type /Annot /Subtype /Link /Rect [50 692 150 792] /Border [0 0 0] /A << /Type /Action /S /URI /URI (https://www.youtube.com) >> /F 4 /StructParent 0 /Contents (A link to youtube) >> endobj 8 0 obj << /ProcSet [/PDF /Text /ImageC /ImageB] /Font << /f0 9 0 R >> >> endobj 9 0 obj << /Type /Font /Subtype /Type0 /BaseFont /EOHQDA+NotoSans-Regular /Encoding /Identity-H /DescendantFonts [10 0 R] /ToUnicode 14 0 R >> endobj 10 0 obj << /Type /Font /Subtype /CIDFontType2 /BaseFont /EOHQDA+NotoSans-Regular /CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >> /FontDescriptor 11 0 R /DW 0 /CIDToGIDMap /Identity /W [0 0 600 1 1 556 2 2 618 3 3 258 4 4 479 5 5 260 6 6 605 7 7 935 8 8 564 9 9 361 10 10 529] >> endobj 11 0 obj << /Type /FontDescriptor /FontName /EOHQDA+NotoSans-Regular /Flags 131076 /FontBBox [10 -10 854 760] /ItalicAngle 0 /Ascent 1069 /Descent -293 /CapHeight 714 /StemV 95.4 /CIDSet 13 0 R /FontFile2 15 0 R >> endobj 12 0 obj << /Type /Page /Resources 8 0 R /MediaBox [0 0 595 842] /StructParents 1 /Tabs /S /Parent 1 0 R /Contents 16 0 R /Annots [7 0 R] >> endobj 13 0 obj << /Length 20 /Filter [/ASCIIHexDecode /FlateDecode] >> stream 789CFBFF000002E001E0 endstream endobj 14 0 obj << /Length 746 /Type /CMap /WMode 0 >> stream %!PS-Adobe-3.0 Resource-CMap %%DocumentNeededResources: procset CIDInit %%IncludeResource: procset CIDInit %%BeginResource: CMap Custom %%Title: (Custom Adobe Identity 0) %%Version: 1 %%EndComments /CIDInit /ProcSet findresource begin 12 dict begin begincmap /CIDSystemInfo 3 dict dup begin /Registry (Adobe) def /Ordering (Identity) def /Supplement 0 def end def /CMapName /Custom def /CMapVersion 1 def /CMapType 0 def /WMode 0 def 1 begincodespacerange <0000> endcodespacerange 10 beginbfchar <0001> <0054> <0002> <0068> <0003> <0069> <0004> <0073> <0005> <0020> <0006> <006f> <0007> <006d> <0008> <0065> <0009> <0074> <000A> <0078> endbfchar endcmap CMapName currentdict /CMap defineresource pop end end %%EndResource %%EOF endstream endobj 15 0 obj << /Length 2797 /Filter [/ASCIIHexDecode /FlateDecode] >> stream 789C8D545B4C5C5514DDE7CC30C3A35006E6C14360666E1960A443E1CE835AA49D0CF2 EA94570B0C1020033365B0F3B233F485B6558B5AA389B6FD30697F4C3FD40F4D5363D2 FEF8E34FA5F1CF34269AD6FA61AA264D7F6C6C0D83EB5E2E50B04D7A4FCE3D7BEFB3F7 DAFBAC7DEE25464439749A545438133D7EF0C417FDF761B944C47F8B848321E18F03B7 8954A761734760D8F275D6DBD0AF41DF1689A58F1917B800FD17E8F5D1C4745075461D 275267432F89058F25C9C14E41374337C783B170F0F5B38FA0EFC1742413A934DD6237 88B293D86F4E1E0E27239A0F16A07F0E5D4B9C2688D823BE88EAB444A2CEA2ABB6E82C 13EC62E613E6CADCE48B4B6E918788512EEAB5C00F5E164127B82C0681F946EF70D36D 3EDFDB0B101A844729FF870C44C57AADE8768B4D46834ED03905AB465AC52FB3346523 CEA9A9E163A3BE408097D60A75F6F199CC6536FC667822F31742514F0FEAFA86DFA53C DA0A1C20E83582D5E672BA4D80784B5F55A53756567A03FC6E79C50B782ACABF5FBAC7 4BA4FCE2F24376955BA98EA85A0EAA71198D6293DBE5B4D96A1C1C1028C8A4B5D9A47A F446A3A992B3ABE9A9E6FE2AF35883AFC5B8D3E5ECAE4D8C360E56575ABB6BDC3BCB5E 16C54EDB859EBEA2C2BEC2F217B7E9CD66BDBEB6B9BEADBB58D75EA0172A8D5515FAE2 DA9D52D59EE587BC06B9F3A914A5C8D96D2B098D597AA508A4E535EFA63A127BDE4975 2576670EED1DE8F7FB0706BA59FEC239EF1B230B1F79E747261389C9C96854E1533504 4C0B948D4CAE316A925996DEFCD3B1D1E1588F6F38DEDF1AE8C8CF2A1DDC71D296553E CEADE311303C726A7428F31396D044E64F5ED265AF1B75D42B7533E43051A59CC56830 5864D23C06CDEA21DC26AB466BB1D9D8B657A65D998FF9489FD86BAFEBF3F8E7BCBB0E B5EFEED2321D6BE5D69658976B6CB2B8685F91AE757E2470B2ADB3BFB36D10E728445F F6F3F38426553F018C3BE4F18806D120E8F44696ADB7E717384BEC1DF5FE7D82F3E2C5 8656ADDAA7CDA9E8F4B266BB7078BE2DB3D8D820B15284D7321A9E87DBA1124D1E5155 2CD468851FAF87DE3F3B7DFDBBD0B90BD3AC88691617338F33F76FDD2229061D62376F B4E4FF3EB9B5E56F52A9EEC142B76BB46E65F52E9DCF1CC97D90E583AA012B2B0FE2D4 DB333F13E5952C9DFFF74CEE0319E9C9278F076882D7532E7F950619EE2EBB43225323 DD3879549FD120779287CD5221D74975939EAAA993C27419E3075A668D2CC05E9351F3 105542C7917D630EB5AC17D057F83E993A077204734596B888283287CF094556919BDE 53643559E95B45CEA232FA55913564A6C78AACA53656A6C8D96467138A9C43B56C1527 8F5AD91545DE422DECBE22E7332BB72B720139557EF251829238C9619AA519D49746A6 26DA418DE4A2EDB2D404D94C1DF04BC0230A3ECCE42729D201C90B4B14EBC05A7C4AD6 ``` -------------------------------- ### PDF Object Stream Example Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/validate_pdf_ua1_full_example.txt An example of a PDF object stream containing drawing commands and text. ```pdf /Span << /MCID 0 >> BDC q 1 0 0 -1 0 842 cm 0 g BT 0 Tr /f0 20 Tf 1 0 0 -1 0 100 Tm [(\000\001\000\002\000\003\000\004\000\005\000\003\000\004\000\005\000\004\000\006\000\007\000\b\000\005\000\t\000\b) 20 (\000\n\000\t)] TJ ET Q EMC ``` -------------------------------- ### PDF Object Structure Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/metadata_full_with_xmp.txt Example of PDF object definitions, including Pages, Resources, Page, Contents, Metadata, and Catalog objects. ```pdf %PDF-1.7 %AAAA 1 0 obj << /Type /Pages /Count 1 /Kids [3 0 R] >> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageC /ImageB] >> endobj 3 0 obj << /Type /Page /Resources 2 0 R /MediaBox [0 0 595 842] /Parent 1 0 R /Contents 4 0 R >> endobj 4 0 obj << /Length 0 >> stream endstream endobj 5 0 obj << /Title (An awesome title) /Subject (A very interesting subject) /Keywords (keyword1, keyword2, keyword3) /Author (John Doe, Max Mustermann) /Creator (krilla) /Producer (krilla) /ModDate (D:20241108222318+01'12) /CreationDate (D:20241108222318+01'12) >> endobj 6 0 obj << /Length 1377 /Type /Metadata /Subtype /XML >> stream An awesome titleA very interesting subjectkeyword1, keyword2, keyword3John Doe, Max Mustermannkrillakrillaen2024-11-08T22:23:18+01:122024-11-08T22:23:18+01:121application/pdf5PugGGJusizcjNP5D9me0A==CGF89dB/kZ8HG+0AeiObmg==proof1.7 endstream endobj 7 0 obj << /Type /Catalog /Pages 1 0 R /Metadata 6 0 R /Lang (en) /ViewerPreferences << /Direction /L2R >> /PageLayout /TwoColumnRight >> endobj xref 0 8 0000000000 65535 f 0000000016 00000 n 0000000080 00000 n 0000000142 00000 n 0000000257 00000 n 0000000309 00000 n 0000000597 00000 n 0000002063 00000 n trailer << /Size 8 /Root 7 0 R /Info 5 0 R /ID [(CGF89dB/kZ8HG+0AeiObmg==) (5PugGGJusizcjNP5D9me0A==)] >> startxref 2227 %%EOF ``` -------------------------------- ### PDF Metadata: XMP Packet Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/validate_pdf_a2_b_full_example.txt An XMP metadata packet containing document information, history, and PDF/A conformance details. ```XML en2001-01-01T00:00:00Z2001-01-01T00:00:00Zsaved2001-01-01T00:00:00Zv2U9mGQ+WUI4624aqXDQ5g==_sourceconverted2001-01-01T00:00:00Zv2U9mGQ+WUI4624aqXDQ5g==_sourceXMP Media Management schemahttp://ns.adobe.com/xap/1.0/mm/xmpMMinternalUUID based identifier for specific incarnation of a documentInstanceIDTextAdobe PDF schemahttp://ns.adobe.com/pdf/1.3/pdfexternalKeywords associated with the documentKeywordsTextinternalVersion of the PDF specification to which the document conformsPDFVersionText ``` -------------------------------- ### XMP Metadata Structure Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/metadata_full_with_xmp.txt Example of XMP metadata embedded within a PDF, using RDF and XML. ```xml An awesome titleA very interesting subjectkeyword1, keyword2, keyword3John Doe, Max Mustermannkrillakrillaen2024-11-08T22:23:18+01:122024-11-08T22:23:18+01:121application/pdf5PugGGJusizcjNP5D9me0A==CGF89dB/kZ8HG+0AeiObmg==proof1.7 ``` -------------------------------- ### PDF Page Content Stream Example Source: https://github.com/laurenzv/krilla/blob/main/refs/snapshots/outline_simple.txt This snippet shows the content stream for a PDF page, defining graphical operations like setting colors, moving to points, drawing lines, and filling shapes. ```pdf 15 0 obj << /Length 66 >> stream q 1 0 0 -1 0 200 cm 1 0 0 rg 0 0 m 100 0 l 100 100 l 0 100 l h f Q endstream endobj 16 0 obj << /Length 70 >> stream q 1 0 0 -1 0 200 cm 0 1 0 rg 50 50 m 150 50 l 150 150 l 50 150 l h f Q endstream endobj 17 0 obj << /Length 74 >> stream q 1 0 0 -1 0 200 cm 0 0 1 rg 100 100 m 200 100 l 200 200 l 100 200 l h f Q endstream endobj ```