You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Norbert Sándor <de...@erinors.com> on 2014/04/14 21:07:21 UTC
PDF printing - page size problem
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
Re: PDF printing - page size problem
Posted by Tilman Hausherr <TH...@t-online.de>.
One more question:
Did you ever get the expected size with the 2.0 version? Or with a 1.8.x
version?
Btw the current source code uses findRotatedCropBox(), not the mediaBox.
The older code used both.
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
>
Re: PDF printing - page size problem
Posted by Norbert Sándor <de...@erinors.com>.
Hello,
Thanks for your reply!
Yes, we're printing to an endless paper using a cash register printer.
I will try setting setImageableArea() and let you know the result.
Best regards:
Norbert Sándor
On 2014.04.18. 15:55, Tilman Hausherr wrote:
> 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
>>>
>>
>
Re: PDF printing - page size problem
Posted by Tilman Hausherr <TH...@t-online.de>.
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
>>
>
Re: PDF printing - page size problem
Posted by Tilman Hausherr <TH...@t-online.de>.
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
>
Re: PDF printing - page size problem
Posted by Tilman Hausherr <TH...@t-online.de>.
Hello Norbert,
I think the best would be to open a JIRA issue and include your PDF. You
generate it yourself, so you can remove anything that is confidential .
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
>