You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Tres Finocchiaro <tr...@gmail.com> on 2023/05/09 15:06:56 UTC

Second page missing printing a PDF

When printing the following PDF, some strange things occur:
https://github.com/qzind/tray/files/11432463/sample_file-1.pdf

   - When printing to a virtual printer (e.g. PDFCreator), the first page
   prints normally, but the second page prints rasterized
   - When printing to a ZDesigner driver on Windows, the second page is
   missing completely

I'm using a custom 4"x6" form, so some resizing does occur, but I've never
had a second page completely missing before (neither through PDFBOX nor
through the ZDesigner driver) so I'm trying to figure out:

   - Is this related to the second page rasterizing or is this just a
   coincidence?
   - Is there a workaround?
   - Is this worthy of a bug report?

I've tested with 2.0 and 3.0.

- Tres.Finocchiaro@gmail.com

Re: Second page missing printing a PDF

Posted by Tres Finocchiaro <tr...@gmail.com>.
Update:  With the rasterization avoided, the second page prints just fine
now with Zebra's driver. 🎉

>

Re: Second page missing printing a PDF

Posted by Tres Finocchiaro <tr...@gmail.com>.
>
> I modified SetGraphicsStateParameters.java as describe


Thanks a bunch, that fixes the second page rasterization, next to retest on
actual hardware to see if it fixes the missing second page. :)

- Tres.Finocchiaro@gmail.com

Re: Second page missing printing a PDF

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

What you did isn't what I wrote, and your code applies to drawing an 
object, but the thing that makes trouble happens when drawing a line (or 
rather, a small rectangle):

   0 0 0 rg
*  /GS0 gs*
   q
     1 0 0 1 0 252.8705 cm
     0 0 m
     710.598 0 l
     710.598 0.8 l
     0 0.8 l
     0 0 l
     h
     0 0 m
     710.598 0 l
     710.598 0 l
     0 0 l
     0 0 l
     h
     f*
   Q

So I modified SetGraphicsStateParameters.java as described (although I 
moved my two lines after the null check) and the printed file is no 
longer rasterized on the second page.

https://drive.google.com/file/d/1U6X0ZqQeJtdaZqAXEnXFK7F8F5_rtffv/view?usp=sharing

Tilman

On 19.05.2023 05:51, Tres Finocchiaro wrote:
> Thanks.
>
> I've added the code to our existing custom "process()" function.... it
> looks like this:
>
> public void process(Operator operator, List<COSBase> operands) throws
>> IOException {
>>          if (operands.isEmpty()) {
>>              throw new MissingOperandException(operator, operands);
>>          } else {
>>              COSBase base0 = operands.get(0);
>>              if (base0 instanceof COSName) {
>>                  COSName objectName = (COSName)base0;
>
>
>
>>
>>
>>
>> *// Disable alpha for lines, etc                PDExtendedGraphicsState gs
>> = context.getResources().getExtGState(objectName);                if(gs !=
>> null) {                    gs.setNonStrokingAlphaConstant(1f);
>>        gs.setStrokingAlphaConstant(1f);                }*
>
> ... Unfortunately, it doesn't seem to have the same effect as the
> brute-force approach of "hard-coded them to always set/return '1' in
> PDGraphicsState".  Do you have any suspicions as to why?
>
> This is reproducible using the following steps:
>
>     1. Windows 11, Java 11
>     2. PDF from original email in this thread
>     3. XPS Document Writer, DPI set to 300
>     4. Custom form size: 4x6
>
> P.S. This rasterization seems specific to Windows.
>
> -Tres.Finocchiaro@gmail.com
>
>
> On Thu, May 18, 2023 at 1:30 AM Tilman Hausherr<TH...@t-online.de>
> wrote:
>
>> Hi,
>>
>> I looked again and I see my advice was wrong, the protected method I
>> looked at is final, and the other one is private.
>>
>> The next thing that you could try is to create your own
>> SetGraphicsStateParameters class, and call addOperator(new
>> SetGraphicsStateParameters()); in your own drawer.
>>
>> The new class should be like the old class but with this modification
>>
>>           PDExtendedGraphicsState gs =
>> context.getResources().getExtGState(graphicsName); // existing line
>>           gs.setNonStrokingAlphaConstant(1f);
>>           gs.setStrokingAlphaConstant(1f);
>>
>>
>> Tilman
>>
>> On 17.05.2023 22:28, Tres Finocchiaro wrote:
>>>      What you could try is to extend *getNonStrokingPaint* and
>>>      *getStrokingPaint*
>>>      and set both values to 1 (that is the default if no ca/CA entry
>>>      exists)
>>>      with *setAlphaConstant*() and *setNonStrokeAlphaConstant*().
>>>
>>>
>>> Thanks.  Do you mind offering a pointer on how to perform this?  For
>>> example, *getNonStrokingPaint*() and *getStrokingPaint*() return Paint
>>> objects.  Should I be forcing *setAlphaConstant*() and
>>> *setNonStrokeAlphaConstant*() like this code example?
>>>
>>>
>> https://github.com/apache/pdfbox/blob/f7ac68e7b367a43e36e74e1ec915c25b117304cb/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java#L237-L238
>>> As a quick test, I hard-coded them to always set/return "1" in
>>> *PDGraphicsState * and it appears to fix the rasterization of the
>>> second page, but I'd like to be able to make this toggleable.
>>>
>>> Here's my current code:
>>>
>> https://github.com/qzind/tray/pull/1108/files#diff-aba44d09ef8de16a001d790ae7671bea33941071306f549b8dc290504e3e1d1b,
>>
>>> which is largely based on a conversation here:
>>>
>> https://issues.apache.org/jira/browse/PDFBOX-4123?focusedCommentId=17529733&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17529733
>>> <
>> https://issues.apache.org/jira/browse/PDFBOX-4123?focusedCommentId=17529733&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17529733
>>> .
>>>
>>> image.png
>>>
>>> -Tres.Finocchiaro@gmail.com
>>

Re: Second page missing printing a PDF

Posted by Tres Finocchiaro <tr...@gmail.com>.
Thanks.

I've added the code to our existing custom "process()" function.... it
looks like this:

public void process(Operator operator, List<COSBase> operands) throws
> IOException {
>         if (operands.isEmpty()) {
>             throw new MissingOperandException(operator, operands);
>         } else {
>             COSBase base0 = operands.get(0);
>             if (base0 instanceof COSName) {
>                 COSName objectName = (COSName)base0;




>
>
>
>
> *// Disable alpha for lines, etc                PDExtendedGraphicsState gs
> = context.getResources().getExtGState(objectName);                if(gs !=
> null) {                    gs.setNonStrokingAlphaConstant(1f);
>       gs.setStrokingAlphaConstant(1f);                }*


... Unfortunately, it doesn't seem to have the same effect as the
brute-force approach of "hard-coded them to always set/return '1' in
PDGraphicsState".  Do you have any suspicions as to why?

This is reproducible using the following steps:

   1. Windows 11, Java 11
   2. PDF from original email in this thread
   3. XPS Document Writer, DPI set to 300
   4. Custom form size: 4x6

P.S. This rasterization seems specific to Windows.

- Tres.Finocchiaro@gmail.com


On Thu, May 18, 2023 at 1:30 AM Tilman Hausherr <TH...@t-online.de>
wrote:

> Hi,
>
> I looked again and I see my advice was wrong, the protected method I
> looked at is final, and the other one is private.
>
> The next thing that you could try is to create your own
> SetGraphicsStateParameters class, and call addOperator(new
> SetGraphicsStateParameters()); in your own drawer.
>
> The new class should be like the old class but with this modification
>
>          PDExtendedGraphicsState gs =
> context.getResources().getExtGState(graphicsName); // existing line
>          gs.setNonStrokingAlphaConstant(1f);
>          gs.setStrokingAlphaConstant(1f);
>
>
> Tilman
>
> On 17.05.2023 22:28, Tres Finocchiaro wrote:
> >
> >     What you could try is to extend *getNonStrokingPaint* and
> >     *getStrokingPaint*
> >     and set both values to 1 (that is the default if no ca/CA entry
> >     exists)
> >     with *setAlphaConstant*() and *setNonStrokeAlphaConstant*().
> >
> >
> > Thanks.  Do you mind offering a pointer on how to perform this?  For
> > example, *getNonStrokingPaint*() and *getStrokingPaint*() return Paint
> > objects.  Should I be forcing *setAlphaConstant*() and
> > *setNonStrokeAlphaConstant*() like this code example?
> >
> >
> https://github.com/apache/pdfbox/blob/f7ac68e7b367a43e36e74e1ec915c25b117304cb/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java#L237-L238
> >
> > As a quick test, I hard-coded them to always set/return "1" in
> > *PDGraphicsState * and it appears to fix the rasterization of the
> > second page, but I'd like to be able to make this toggleable.
> >
> > Here's my current code:
> >
> https://github.com/qzind/tray/pull/1108/files#diff-aba44d09ef8de16a001d790ae7671bea33941071306f549b8dc290504e3e1d1b,
>
> > which is largely based on a conversation here:
> >
> https://issues.apache.org/jira/browse/PDFBOX-4123?focusedCommentId=17529733&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17529733
> > <
> https://issues.apache.org/jira/browse/PDFBOX-4123?focusedCommentId=17529733&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17529733
> >.
> >
> > image.png
> >
> > - Tres.Finocchiaro@gmail.com
>
>

Re: Second page missing printing a PDF

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

I looked again and I see my advice was wrong, the protected method I 
looked at is final, and the other one is private.

The next thing that you could try is to create your own 
SetGraphicsStateParameters class, and call addOperator(new 
SetGraphicsStateParameters()); in your own drawer.

The new class should be like the old class but with this modification

         PDExtendedGraphicsState gs = 
context.getResources().getExtGState(graphicsName); // existing line
         gs.setNonStrokingAlphaConstant(1f);
         gs.setStrokingAlphaConstant(1f);


Tilman

On 17.05.2023 22:28, Tres Finocchiaro wrote:
>
>     What you could try is to extend *getNonStrokingPaint* and
>     *getStrokingPaint*
>     and set both values to 1 (that is the default if no ca/CA entry
>     exists)
>     with *setAlphaConstant*() and *setNonStrokeAlphaConstant*().
>
>
> Thanks.  Do you mind offering a pointer on how to perform this?  For 
> example, *getNonStrokingPaint*() and *getStrokingPaint*() return Paint 
> objects.  Should I be forcing *setAlphaConstant*() and 
> *setNonStrokeAlphaConstant*() like this code example?
>
> https://github.com/apache/pdfbox/blob/f7ac68e7b367a43e36e74e1ec915c25b117304cb/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java#L237-L238
>
> As a quick test, I hard-coded them to always set/return "1" in 
> *PDGraphicsState * and it appears to fix the rasterization of the 
> second page, but I'd like to be able to make this toggleable.
>
> Here's my current code: 
> https://github.com/qzind/tray/pull/1108/files#diff-aba44d09ef8de16a001d790ae7671bea33941071306f549b8dc290504e3e1d1b, 
> which is largely based on a conversation here: 
> https://issues.apache.org/jira/browse/PDFBOX-4123?focusedCommentId=17529733&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17529733 
> <https://issues.apache.org/jira/browse/PDFBOX-4123?focusedCommentId=17529733&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17529733>.
>
> image.png
>
> - Tres.Finocchiaro@gmail.com


Re: Second page missing printing a PDF

Posted by Tres Finocchiaro <tr...@gmail.com>.
>
> What you could try is to extend *getNonStrokingPaint* and
> *getStrokingPaint*
> and set both values to 1 (that is the default if no ca/CA entry exists)
> with *setAlphaConstant*() and *setNonStrokeAlphaConstant*().


Thanks.  Do you mind offering a pointer on how to perform this?  For
example, *getNonStrokingPaint*() and *getStrokingPaint*() return Paint
objects.  Should I be forcing *setAlphaConstant*() and
*setNonStrokeAlphaConstant*() like this code example?

https://github.com/apache/pdfbox/blob/f7ac68e7b367a43e36e74e1ec915c25b117304cb/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java#L237-L238

As a quick test, I hard-coded them to always set/return "1" in
*PDGraphicsState * and it appears to fix the rasterization of the second
page, but I'd like to be able to make this toggleable.

Here's my current code:
https://github.com/qzind/tray/pull/1108/files#diff-aba44d09ef8de16a001d790ae7671bea33941071306f549b8dc290504e3e1d1b,
which is largely based on a conversation here:
https://issues.apache.org/jira/browse/PDFBOX-4123?focusedCommentId=17529733&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17529733
.

[image: image.png]

- Tres.Finocchiaro@gmail.com

Re: Second page missing printing a PDF

Posted by Tilman Hausherr <TH...@t-online.de>.
What you could try is to extend getNonStrokingPaint and getStrokingPaint 
and set both values to 1 (that is the default if no ca/CA entry exists) 
with setAlphaConstant() and setNonStrokeAlphaConstant().

If that doesn't work, then modify the PDF by going through the page 
resources recursively and change the ExtGState objects. 
(resources.getExtGStateNames() and resources.getExtGState). Do this also 
for form XObjects (and more).

Tilman

On 13.05.2023 20:11, Tres Finocchiaro wrote:
>
>     > This ("ca") applies to the thin line and may be the cause of the
>     rasterization.
>
>
>  That seems to be the culprit, thanks!
>
> We worked together in the past to coerce documents into never 
> rasterizing... the fix we had originally written a workaround to 
> removing transparent layers.
>
> https://issues.apache.org/jira/browse/PDFBOX-4123?focusedCommentId=17529733&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17529733 
> <https://issues.apache.org/jira/browse/PDFBOX-4123?focusedCommentId=17529733&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17529733>
>
> I understand that this is slightly off-topic, but can additional 
> logical improvements be made to that logic to help with scenarios like 
> this?  Assuming the answer is yes, should I start a new email thread 
> (or bug report) about this?
>
> In regards to the originating issue (the second page), I'll re-test 
> with the "CA 1" entry removed.
>
> -Tres
>
> image.png


Re: Second page missing printing a PDF

Posted by Tres Finocchiaro <tr...@gmail.com>.
> > This ("ca") applies to the thin line and may be the cause of the
> rasterization.


 That seems to be the culprit, thanks!

We worked together in the past to coerce documents into never
rasterizing... the fix we had originally written a workaround to removing
transparent layers.

https://issues.apache.org/jira/browse/PDFBOX-4123?focusedCommentId=17529733&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17529733

I understand that this is slightly off-topic, but can additional logical
improvements be made to that logic to help with scenarios like this?
Assuming the answer is yes, should I start a new email thread (or bug
report) about this?

In regards to the originating issue (the second page), I'll re-test with
the "CA 1" entry removed.

-Tres

[image: image.png]

Re: Second page missing printing a PDF

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

I don't really know what logic is happening in the depth of the java 
printing system.

The second page has this


This ("ca") applies to the thin line and may be the cause of the 
rasterization.

Tilman





On 12.05.2023 06:05, Tres Finocchiaro wrote:
>> Works for me on windows with "print to PDF", the second page is
>> rasterized into 14 images.
>>
> Is this desired?  If so, why?
>
> Do you have any ideas why the ZDesigner driver just ditches that second
> page?  I'm only focusing on the rasterization because it seems coincidental.
>
> Reading the PCL from the PRN file, I can see that no second page is sent.
> When I print the same PDF from Adobe, both pages are present in the PCL
>
> I'm scratching my head....
>

Re: Second page missing printing a PDF

Posted by Tres Finocchiaro <tr...@gmail.com>.
> Works for me on windows with "print to PDF", the second page is
> rasterized into 14 images.
>

Is this desired?  If so, why?

Do you have any ideas why the ZDesigner driver just ditches that second
page?  I'm only focusing on the rasterization because it seems coincidental.

Reading the PCL from the PRN file, I can see that no second page is sent.
When I print the same PDF from Adobe, both pages are present in the PCL

I'm scratching my head....

Re: Second page missing printing a PDF

Posted by Tilman Hausherr <TH...@t-online.de>.
Works for me on windows with "print to PDF", the second page is 
rasterized into 14 images.

Tilman

On 09.05.2023 17:06, Tres Finocchiaro wrote:
> When printing the following PDF, some strange things occur:
> https://github.com/qzind/tray/files/11432463/sample_file-1.pdf
>
>     - When printing to a virtual printer (e.g. PDFCreator), the first page
>     prints normally, but the second page prints rasterized
>     - When printing to a ZDesigner driver on Windows, the second page is
>     missing completely
>
> I'm using a custom 4"x6" form, so some resizing does occur, but I've never
> had a second page completely missing before (neither through PDFBOX nor
> through the ZDesigner driver) so I'm trying to figure out:
>
>     - Is this related to the second page rasterizing or is this just a
>     coincidence?
>     - Is there a workaround?
>     - Is this worthy of a bug report?
>
> I've tested with 2.0 and 3.0.
>
> - Tres.Finocchiaro@gmail.com
>


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