py-pdf/fpdf2

When I use Acrobat, I get the same error when printing a PDF. The only requirement is that there is a "path" in the code.

Lucas-C opened this issue · 10 comments

When I use Acrobat, I get the same error when printing a PDF. The only requirement is that there is a "path" in the code.

Minimal test code:

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()

with pdf.new_path() as path:
    path.move_to(1, 1)
    path.line_to(9, 9)
    path.close()

pdf.output("test.pdf")

Then print test.pdf using Acrobat reader. The error should appear right after printing.
test.pdf

The problem persists when pdf.compress = False

Originally posted by @GerardoAllende in #960 (comment)

Hi @GerardoAllende

I was able to open the test.pdf file produced by this script in both Sumatra PDF reader and Adobe Acrobat reader 2024.001.20643 under Windows.

Sorry, I cannot reproduce your problem! 😢

Could you maybe provide a screenshot of the error you are facing?

The problem shows only when printing. Only with Acrobat. Screenshot attached. Tested in Windows 7 and 10.
1
2

The PDFs in https://py-pdf.github.io/fpdf2/Drawing.html for example:

https://py-pdf.github.io/fpdf2/drawing/demo-1.pdf

Are not showing the nag message box in Acrobat when printing.

But, if I create the PDF using the sample code in the page, the PDF shows the message when printing. The PDFs created and the ones in the page are different. Do you know if the PDFs in the page were post processed? Or do you remember how they were created? I'm using release 2.7.8.

Manually edited the PDF, changed this:

stream
2 J
0.57 w
q 2.8346 0 0 -2.8346 0 28.3465 cm /GS0 gs [] 0 d q 2 2 m 8 8 l 2 8 l 8 2 l h B Q Q
endstream

Deleted /GS0 gs
Result:

stream
2 J
0.57 w
q 2.8346 0 0 -2.8346 0 28.3465 cm         [] 0 d q 2 2 m 8 8 l 2 8 l 8 2 l h B Q Q
endstream

And the PDF is not showing the nag message box when printing.

Well, temporary solution found:

Comment lines https://github.com/py-pdf/fpdf2/edit/master/fpdf/drawing.py#L1448-L1454

Great job catching that up. In the stroke_dash_pattern setter we are transforming None into empty set "()":
https://github.com/py-pdf/fpdf2/blob/master/fpdf/drawing.py#L1395-L1396

In the "IF" condition you highlighted, adding and self.stroke_dash_pattern != () should solve the problem.

@GerardoAllende would you be interested in submitting a PR?

Yes, thanks! May we reduce the if to:

if self.stroke_dash_pattern and (
   self.stroke_dash_pattern is not self.INHERIT
        ):

?

Yes, thanks! May we reduce the if to:

if self.stroke_dash_pattern and (
   self.stroke_dash_pattern is not self.INHERIT
        ):

?

Definitely, yes. You can remove the parentheses too.

Fixed in #1145