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: Printing Sides and Chromaticity
Date Tue, 30 Jan 2018 19:40:39 GMT
Am 30.01.2018 um 04:51 schrieb Ivan Ridao Freitas | IvanRF.com:
> Regarding Sides, my doubt was if I set the Sides.ONE_SIDED equivalent 
> in the PDDocument, for example:
>
>    PDViewerPreferences prefs = new
> PDViewerPreferences(document.getDocumentCatalog().getCOSObject());
>    prefs.setDuplex(PDViewerPreferences.DUPLEX.Simplex);
>    document.getDocumentCatalog().setViewerPreferences(prefs);
>
> will this be respected when I print the PDF like this?:
>
>    PrinterJob job = PrinterJob.getPrinterJob();
>    ...
>    Book book = new Book();
>    book.append(new PDFPrintable(document, scaling), pageFormat,
>    document.getNumberOfPages());
>    job.setPageable(book);
>
>    job.print();
>
> I just test it and I can say it is not respected. I guess that's why 
> you added the example code on Printing.java to show how to convert the 
> PDViewerPreferences to a PrintRequestAttributeSet.
>
> So, is it right to say that the sides preference of a print job can 
> only be defined with PrintRequestAttributeSet attributes and not with 
> a Pageable/Printable object?

I don't know, I'm not a java printing expect... but when searching for 
the topic on google, I keep finding things about 
PrintRequestAttributeSet attributes.


>
> Regarding grayscale, is extending PDFPrintable and overriding 
> print(Graphics, PageFormat, int) the right place to modify the 
> graphics color? Also, if the PDF is rendered as an image wouldn't be a 
> negative impact on printing performance and quality?
>

See PDFPrintable.print, when the dpi parameter is != 0. Change 
BufferedImage.TYPE_INT_ARGB to BufferedImage.TYPE_BYTE_GRAY, or create 
an custom type that has grey and alpha and then construct a PDFPrintable 
with a non dpi != 0. If your dpi is too low the quality will go down. It 
should be at least 300, better 600. And yes it will use more memory. 
Custom types will also be slower because java internally converts to 
standard types.

Tilman


> Thanks!
>
> Ivan
> On 29/01/2018 2:01 p. m., Tilman Hausherr wrote:
>> I haven't understood the first part of your question but here's a 
>> segment in PDFDebugger, maybe that can answer it somewhat:
>>
>>             PrinterJob job = PrinterJob.getPrinterJob();
>>             job.setPageable(new PDFPageable(document));
>>             PrintRequestAttributeSet pras = new 
>> HashPrintRequestAttributeSet();
>>             PDViewerPreferences vp = 
>> document.getDocumentCatalog().getViewerPreferences();
>>             if (vp != null && vp.getDuplex() != null)
>>             {
>>                 String dp = vp.getDuplex();
>>                 if 
>> (PDViewerPreferences.DUPLEX.DuplexFlipLongEdge.toString().equals(dp))
>>                 {
>>                     pras.add(Sides.TWO_SIDED_LONG_EDGE);
>>                 }
>>                 else if 
>> (PDViewerPreferences.DUPLEX.DuplexFlipShortEdge.toString().equals(dp))
>>                 {
>>                     pras.add(Sides.TWO_SIDED_SHORT_EDGE);
>>                 }
>>                 else if 
>> (PDViewerPreferences.DUPLEX.Simplex.toString().equals(dp))
>>                 {
>>                     pras.add(Sides.ONE_SIDED);
>>                 }
>>             }
>>             if (job.printDialog(pras))
>>             {
>>                 job.print(pras);
>>             }
>>
>> To set it, just call 
>> document.getDocumentCatalog().setViewerPreferences().
>>
>> Re grayscale:
>> there is no feature to change a PDF to grey. You could render a PDF 
>> to a greyscale image and then print that one.
>>
>> Tilman
>>
>>
>> Am 28.01.2018 um 22:39 schrieb Ivan Ridao Freitas | IvanRF.com:
>>> Hi, I have two question regarding Java Printing attributes.
>>>
>>> *Sides*: a new HP printer has Duplex mode as default an encountered 
>>> two different outputs for these scenarios:
>>>
>>>  - a PDDocument with one page, but setting PrinterJob.setCopies(2): 
>>> prints ok one page after the other
>>>
>>>  - a PDDocument with two equal pages in it (without using 
>>> setCopies): prints one page and the printer stops showing a message 
>>> to continue with Duplex mode. (this can only be solved by always 
>>> adding Sides.ONE_SIDED and print with attributes)
>>>
>>> My question is, can the side behaviour be set on the PDDocument or 
>>> the only way to always use "one sided" is with attributes?
>>> I saw in the Printing example 
>>> <https://svn.apache.org/repos/asf/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/printing/Printing.java>

>>> a conversion from PDViewerPreferences.DUPLEX.Simplex to 
>>> Sides.ONE_SIDED, but I don't know how to use PDViewerPreferences and 
>>> more importantly if these preferences are actually respected when 
>>> printing.
>>>
>>> *
>>> Chromaticity*: similar to this question 
>>> <http://markmail.org/message/5sr6p2d36xpm32eq>, the same HP printer 
>>> always prints in color, ignoring the attribute 
>>> Chromaticity.MONOCHROME. I tested a virtual printer (with Snagit) 
>>> and that attribute works. So, I can assume that the printer is the 
>>> one discarding the Chromaticity attribute.
>>>
>>> My question is, PDFBox provides a way to change a PDF to grayscale? 
>>> If not, could you indicate me at which point should be the color 
>>> conversion be made?
>>>
>>> I'm using the latest PDFBox 2.0.8.
>>>
>>> Thanks,
>>> Ivan
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> 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


Mime
View raw message