Popular Post Numeric1 Posted October 26 Popular Post Posted October 26 (edited) PDFX 1.4 — real PDF files from pure AutoIt, no COM and no DLL (with a 27-page developer guide) Hello everyone, I would like to share a UDF I have been working on: PDFX. It writes real PDF 1.7 files straight from AutoIt, through a single #include — no COM object, no printer driver, no DLL, no helper executable. #include "PDFX.au3" Global $pdf = _PDFX_New("A4", "P", 20) ; A4 portrait, 20 mm margins _PDFX_SetCompression($pdf, 6) ; content streams as FlateDecode _PDFX_SetFont($pdf, "Helvetica", 18, "B") _PDFX_Text($pdf, _PDFX_Mm(20), _PDFX_Mm(30), "Hello from PDFX") _PDFX_Save($pdf, @ScriptDir & "\hello.pdf") _PDFX_Close($pdf) 👉 That is a complete, valid document. It opens identically in Acrobat, Chrome, Edge, Firefox, SumatraPDF and Preview, and passes a strict structural validator. Why another PDF UDF? Most AutoIt PDF work today ends up driving something else — Word, Excel, a printer driver, an external tool. That is fine until you need a report generated on a machine without Office, or you need the exact same file twice. PDFX takes the other road: it builds the objects, the cross-reference table and the trailer itself, in memory, and writes the file once. What is inside (42 public functions, about 3,200 documented lines) Text in the 14 standard fonts, with the real AFM metrics — _PDFX_TextWidth() returns the true width, so columns line up. WinAnsi encoding means é à ç ù ê ï ô œ € « » all render. Top-left coordinates in millimetres. _PDFX_Text($pdf, x, y, ...) anchors the top of the text at y, and _PDFX_TextWrap() returns the next ordinate, so blocks chain naturally. Shapes: lines, rectangles, rounded rectangles, ellipses, polylines, Bézier, fills, dashes, global opacity through ExtGState. Images: JPEG is copied byte for byte (/DCTDecode, including CMYK with the Adobe APP14 inversion), PNG/BMP/GIF are converted once through GDI+, and an image inserted ten times is stored once. Paginated tables with a repeated header Local $aCols[3][3] = [["Description", 0.60, "L"], ["Qty", 0.15, "C"], ["Total", 0.25, "R"]] Local $aRows[2][3] = [["Design", "1", "1,450.00"], ["Printing", "2", "640.00"]] _PDFX_Table($pdf, _PDFX_Mm(20), $y, _PDFX_Mm(170), $aCols, $aRows, "fontsize=9;zebra=1") Navigation: hierarchical bookmarks, internal links, page mode and layout. The useful detail — a link may target a page that does not exist yet. You can write a clickable table of contents on page 2 before the chapters are drawn; the engine resolves the destinations at save time. A target that never appears is dropped silently instead of producing a broken [0 0 R]. Header and footer with {page}, {pages} and {date}, drawn after the content so they stay readable on coloured backgrounds. One file, one save: after a successful _PDFX_Save, further drawing calls return @error = 2 instead of quietly producing a second, inconsistent document. Deterministic output. /CreationDate and /ModDate are in UTC, and /ID is an MD5 fingerprint of the content and metadata. Two runs over the same document produce the same bytes — which is what makes a regression test possible: the four test suites keep reference PDFs and Tools/regress.py compares them byte for byte, dates neutralised. Compression, written in AutoIt. _PDFX_SetCompression($pdf, 6) wraps every content stream in FlateDecode using a DEFLATE compressor implemented in the UDF itself, with no DLL and no zlib. It shrinks the text-heavy report from 18,505 to 5,775 bytes (about 3.2×) at roughly 30 KB/s, and leaves a stream uncompressed when compression would not help. Testing. Four examples and four test suites ship with the package: 23 robustness checks, 16 compression checks, 36 navigation checks, plus a nine-page torture document. The three Python tools in Tools\ have no third-party dependency: pdfcheck.py walks every offset, stream length, trailer entry, outline chain and annotation; outline.py prints the bookmark tree as page numbers; regress.py compares outputs. The guide. Because the API deserves better than a function list, the package includes a 27-page developer guide — and it is generated by PDFX itself, with a clickable table of contents written before the chapters exist. It covers the mental model, coordinates, fonts, images, tables, navigation, validity, compression, performance and the complete API reference, with worked examples and honest limits. What it does not do. PDFX writes; it does not read, merge, extract or fill forms. No encryption, signature or PDF/A. No TTF/OTF embedding (the Core 14 fonts keep files small and licence-free). No gradients, no transparency groups, no links outside the document. Pure-AutoIt compression is slower than zlib, so it is off by default. Requirements. AutoIt 3.3.16.1 (3.3.14+ should be fine), Windows 7 to 11, x86 or x64. Crypt.au3 and GDI+ ship with AutoIt and are used only for the document identifier and for non-JPEG images. The package contains PDFX.au3, four examples, four test suites with reference outputs, the three tools and the guide. Feedback, bug reports and example documents are very welcome; a minimal script that reproduces a problem is the most useful attachment. PDFX.au3 PDFX_1.4.0_forum.zip PDFX_Developer_Guide.pdf Edited October 26 by Numeric1 water, ioa747, argumentum and 2 others 2 3 From 0 and 1 to the stars, it all starts with binary, Numeric1
water Posted October 27 Posted October 27 Added your UDF to the Wiki Numeric1 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now