pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: PDF printing - page size problem
Date Fri, 18 Apr 2014 13:55:25 GMT
Hello Norbert, please see the comment by Andreas at the end of
https://issues.apache.org/jira/browse/PDFBOX-2033

Tilman


Am 18.04.2014 06:47, schrieb Tilman Hausherr:
> I was able to reproduce the problem, and also to print on a virtual 
> printer that creates new PDFs of that size, by using the longest 
> constructor of PDFPrinter().
>
> Sadly the output is blank. So we have a bug.
>
> But... I wonder why would anyone print a PDF into a PDF.
>
> - Do you want to remove meta stuff created by FOP by reprinting the PDF ?
> - Or do you want to print on an endless paper printer? E.g. a cash 
> register receipt printer?
>
>
>         PDDocument document = new PDDocument();
>         PDPage pdPage = new PDPage(new PDRectangle(198.425f, 
> 1700.787f)); // = 70 x 600 mm
>         document.addPage(pdPage);
>         PDFont font = PDType1Font.HELVETICA_BOLD;
>         PDPageContentStream contentStream = new 
> PDPageContentStream(document, pdPage);
>         contentStream.beginText();
>         contentStream.setFont(font, 12);
>         contentStream.moveTextPositionByAmount(100, 10);
>         for (int i = 0; i < 17; ++i)
>         {
>             contentStream.drawString("Hello World " + i);
>             contentStream.moveTextPositionByAmount(0, 100);
>         }
>         contentStream.endText();
>         contentStream.moveTo(1, 1);
>         contentStream.lineTo(1, 1700);
>         contentStream.lineTo(197, 1700);
>         contentStream.lineTo(197, 1);
>         contentStream.closeAndStroke();
>         contentStream.moveTo(1, 1);
>         contentStream.lineTo(197, 1700);
>         contentStream.closeAndStroke();
>         contentStream.moveTo(1, 1700);
>         contentStream.lineTo(197, 1);
>         contentStream.closeAndStroke();
>         contentStream.close();
>         System.out.println(document.getPage(0).findMediaBox());
>         System.out.println(document.getPage(0).findCropBox());
> //        document.save("XXXXXXXXXXX/Page.pdf");
>         Paper paper = new Paper();
>         paper.setSize(198.425f, 1700.787f);
>         //PDFPrinter pdfPrinter = new PDFPrinter(document, 
> PrinterJob.getPrinterJob()); // A4
>         //PDFPrinter pdfPrinter = new PDFPrinter(document, 
> Scaling.ACTUAL_SIZE, Orientation.AUTO, paper, 0);
>         PDFPrinter pdfPrinter = new PDFPrinter(document, 
> PrinterJob.getPrinterJob(), Scaling.ACTUAL_SIZE, Orientation.AUTO, 
> paper, false, 0); // blank
>         //PDFPrinter pdfPrinter = new PDFPrinter(document, 
> Scaling.ACTUAL_SIZE, Orientation.AUTO); // cut off
>         //PDFPrinter pdfPrinter = new PDFPrinter(document, 
> Scaling.SCALE_TO_FIT, Orientation.AUTO); // A4
>         //PDFPrinter pdfPrinter = new PDFPrinter(document, 
> Scaling.SHRINK_TO_FIT, Orientation.AUTO); // A4
>         pdfPrinter.silentPrint();
>         document.close();
>
>
> Tilman
>
> Am 14.04.2014 21:07, schrieb Norbert Sándor:
>> Hello,
>>
>> I use FOP to generate PDFs, and PDFBOX to print them.
>>
>> Recently I switched to the trunk version, mainly because of these 
>> issues in the current stable version:
>>
>>  * https://issues.apache.org/jira/browse/PDFBOX-1452
>>  * https://issues.apache.org/jira/browse/PDFBOX-1776
>>  * https://issues.apache.org/jira/browse/PDFBOX-1776
>>
>> The trunk version fixed the above issues but has a new one: when I 
>> print a PDF with an unusual page size, the printed page size is 
>> incorrect.
>>
>> 1. PDF is generated using FOP, page size is 2,76x23,62 (correct)
>> 2. I load the PDF using PDDocument.load() then immediately save() it,
>>    the resulting PDF has page size of 2,76x23,62 (correct)
>> 3. pdfDocument.getPage(0).findMediaBox() returns
>>    [0.0,0.0,198.425,1700.787] (correct)
>> 4. But when I try to print it using /new PDFPrinter(pdfDocument,
>>    printJob).silentPrint()/ to a virtual PdfCreator printer, then the
>>    resulting PDF has page size of 8,26x11,69 and the content is
>>    horizontally centered on the page. I tried physical printers as well
>>    with the same result, the output always seems to have A4 size...
>>
>> Do you have any idea how can I change the page size for printing?
>>
>> Thanks for your help in advance!
>>
>> Best regards:
>> Norbert Sándor
>>
>


Mime
View raw message