Adjust PDF MediaBox post-creation to match requested dimensions on Windows#22
Adjust PDF MediaBox post-creation to match requested dimensions on Windows#22Copilot wants to merge 14 commits intoadd-pdf-supportfrom
Conversation
Currently if one wants to create a PDF file it requires external libraries and as SWT does not allows an abstraction like Grahics2D in AWT one can not export real content of SWT components (e.g. Canvas) except exporting as an raster image or using some hacks. This now introduce a new PDFDocument to enable direct PDF generation from SWT widgets via Control.print(GC). This allows applications to export widget content to PDF files using the standard GC drawing API as well as even creating completely customized documents.
Currently if one wants to create a PDF file it requires external libraries and as SWT does not allows an abstraction like Grahics2D in AWT one can not export real content of SWT components (e.g. Canvas) except exporting as an raster image or using some hacks. This now introduce a new PDFDocument to enable direct PDF generation from SWT widgets via Control.print(GC). This allows applications to export widget content to PDF files using the standard GC drawing API as well as even creating completely customized documents.
The macOS implementation was just returning false without printing children, similar to a previously fixed Windows issue. Now it properly iterates through child controls and prints them with correct coordinate transformations using NSAffineTransform and NSGraphicsContext state management.
Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
…le specific exceptions Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
… design choices Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
|
@copilot using regexp does not feel right here... can we possibly use a DataInputStream or similar to step thorugh the document step by step. Otherwhise large PDF documents can possibly require a lot of memory and regexp is also not very performant on a almost binary stream. I'm also wondering if MediaBox is really at soem random position or if we can not decode more of the PDF structure to get to it more directly. |
…erformance and memory efficiency Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
I've replaced the regex-based approach with a streaming byte-level scanner (commit aff3591). The new implementation:
The MediaBox entries are found by scanning for the |
… bounds check Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
…e, early termination Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
0431cc4 to
9d37b22
Compare
Windows "Microsoft Print to PDF" only supports standard paper sizes (Letter, A4, etc.). When users request custom dimensions like 600×800px, the printer selects the closest standard size, producing PDFs larger than requested.
Implementation
Post-processing with streaming byte-level scanner:
API consistency:
requestedWidthInPointsandrequestedHeightInPointsfields to track user inputgetWidth()/getHeight()now return requested dimensions, not the standard paper size used internallynewPage(width, height)stores requested dimensions for final adjustmentTechnical details:
Example
Platform-specific: GTK and Cocoa implementations support custom page sizes natively; this workaround only applies to Windows.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.