pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Hewson <j...@jahewson.com>
Subject Re: PdfBox 2.0 scale to A4 while printing document
Date Mon, 29 Jun 2015 04:23:06 GMT

> On 28 Jun 2015, at 11:04, Alex Sviridov <ooo_saturn7@mail.ru> wrote:
> 
> Uff! I have finally made it to work. The following code prints with normal margins:
> 
>             PrinterJob job = PrinterJob.getPrinterJob();
>             Paper paper=new Paper();
>             paper.setSize(72d*8.267d, 72d*11.692d);
>             paper.setImageableArea(0,0,72d*8.267d, 72d*11.692d);
>             
>             PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet();
>             attr_set.add(MediaSizeName.ISO_A4);
>             attr_set.add(Sides.ONE_SIDED);
>             
>             PDFPrinter pDFPrinter=new PDFPrinter(document,Scaling.SCALE_TO_FIT, Orientation.PORTRAIT,paper);
>             pDFPrinter.silentPrint(attr_set);

This makes sense, I think, because Java reports the size of the paper with a margin already
applied (known as the “imageable area”). PDFBox will scale the document to fit within
*that*,
not within the paper. Setting the paper size doesn’t make much sense though - because
 PrinterJob.getPrinterJob() reports the size of paper which is currently in the printer, and
obviously you can’t change that! So that bit looks wrong still to me. Perhaps your default
paper
is US letter or something and so by setting it to A4 you get the full imageable area to play
with
and then the printer just crops the result? You might loose content at the edges of some PDFs
that way.

Is your PDF actually A4, by the way, or are you trying to scale down another size onto A4?
(In which case you’ll need to do either do some scaling or crop some (hopefully whitespace)
content).

Either way, paper.setSize(…) to anything other than the size of paper in your printer isn’t
right
and setImageableArea(…) to a size beyond your printer’s maximum margins isn’t either…
so
your code might work in this case, but it’s not really the answer in general.

Have you tried using Scaling.ACTUAL_SIZE?

— John

> 
> Воскресенье, 28 июня 2015, 19:40 +02:00 от Tilman Hausherr <THausherr@t-online.de>:
>> Thanks, I have opened an issue in JIRA. I can confirm it, and it is only 
>> in 2.0, not on 1.8 (which doesn't help, because 1.8 doesn't render your 
>> fonts properly)
>> 
>> https://issues.apache.org/jira/browse/PDFBOX-2844
>> 
>> Tilman
>> 
>> Am 28.06.2015 um 18:01 schrieb Alex Sviridov:
>>>  The file I tested is here  https://yadi.sk/i/iX-KJwlhhXMY2
>>> 
>>> I printed this pdf file with Adobe Reader in mode 100%. And as expected left
and right margins are about 2cm. In comparison when I print using pdfbox left margin is 4.5cm,
right about 3.5cm.
>>> 
>>> The code I use :
>>> PrinterJob job = PrinterJob.getPrinterJob();
>>> Paper paper=new Paper();
>>> paper.setSize(72d*8.267d, 72d*11.692);
>>> PDFPrinter pDFPrinter=new PDFPrinter(document,Scaling.SCALE_TO_FIT, Orientation.PORTRAIT,paper);
>>> pDFPrinter.silentPrint(job);
>>> 
>>> Questions:
>>> 1) how can I make pdfbox to SCALE_TO_FIT?
>>> 2) how can I print only certain page - not entire document?
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> Воскресенье, 28 июня 2015, 17:40 +02:00 от Tilman Hausherr <
THausherr@t-online.de >:
>>>> Hi,
>>>> 
>>>> Something is indeed a bit tricky with your mailing software, your own
>>>> comments are mixed with my comments. But I think I got them. Sorry for
>>>> my "What else would you expect" comment, that was a failed attempt of
>>>> being funny.
>>>> 
>>>> I don't have LibreOffice installed, I don't know if the others do. So
>>>> the best would be that you create a PDF where the borders are obvious,
>>>> and upload it somewhere.
>>>> 
>>>> Tilman
>>>> 
>>>> 
>>>> 
>>>> Am 28.06.2015 um 17:33 schrieb Александр Свиридов:
>>>>> Воскресенье, 28 июня 2015, 17:10 +02:00 от Tilman Hausherr
<  THausherr@t-online.de >:
>>>>>> Am 28.06.2015 um 16:43 schrieb Александр Свиридов:
>>>>>>>    When I print pdf document it doesn't stretch to take normal
A4 page area. I mean that margins are too big and document is smaller then it could be and
is located in center of the page.
>>>>>> Yes it is centered. What else would you expect? Adjusted to the bottom
>>>>>> right? I don't understand you. Really. Of course I expect it to be
centered. And it is centered as it's expected. However, If everything were as expected I wouldn't
right to mailing list, would I?
>>>>> I always thought that information for fixing some bug is a starting point.
That's why I provided this information.
>>>>>> We'd need the PDF to find out what (if anything) is wrong I do all
files using Libre Office. I tried different files and even very simple ones. So just take
any file and you must get the same results.
>>>>>> 
>>>>>> 
>>>>>> Please try also printing it with Adobe Reader in 100% mode. I printed
my pdf file with Adobe Reader in mode 100%. And as expected left and right margins are about
2cm. In comparison when I print using pdfbox left margin is 4.5cm, right about 3.5cm.
>>>>>> 
>>>>>> Tilman
>>>>>> 
>>>>>> PS: don't CC user postings to me. I get then anyway. Really sorry
for this. I can't understand why my mailing service added your address and I didn't notice
it.
>>>>> So the problem is still there. How to fix it?
>>>>>>> My code:
>>>>>>> PrinterJob job = PrinterJob.getPrinterJob();
>>>>>>> Paper paper=new Paper();
>>>>>>> paper.setSize(72d*8.267d, 72d*11.692);
>>>>>>> PDFPrinter pDFPrinter=new PDFPrinter(document,Scaling.SCALE_TO_FIT,
Orientation.PORTRAIT,paper);
>>>>>>> pDFPrinter.silentPrint(job);
>>>>>>> 
>>>>>>> Please help me to solve this problem.
>>>>>>> 
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail:  users-unsubscribe@pdfbox.apache.org
>>>>>> For additional commands, e-mail:  users-help@pdfbox.apache.org
>>>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail:  users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail:  users-help@pdfbox.apache.org
>>>> 
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:  users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail:  users-help@pdfbox.apache.org
>> 
> 
> 
> -- 
> Alex Sviridov


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message