Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why merge pdf is flipped with example.. #36

Closed
sqxccdy opened this issue Sep 15, 2015 · 6 comments
Closed

Why merge pdf is flipped with example.. #36

sqxccdy opened this issue Sep 15, 2015 · 6 comments

Comments

@sqxccdy
Copy link

sqxccdy commented Sep 15, 2015

use example fancy_watemark.py or watermark.py go to run it.

But the resulting watermark are all horizontal and vertical flip.

watermark with reportlab generate.for example

c = canvas.Canvas('transafe.pdf')
c.drawString(0,0,'hello') 
c.save()

Thanks in advance
Please tell me how to change it ..

@ThomasWaldmann
Copy link

@sunqianxiang i wrote some code based on the fancy_watermark.py, no issue with flipping.

@pmaupin
Copy link
Owner

pmaupin commented Sep 15, 2015

Either your watermark or your PDF pages are probably rotated. (Probably the PDF page, I think rotation for the watermark is handled.) If you have examples (especially if you have examples I can add to the test suite) please email them to me and I will fix.

Thanks,
Pat

@sqxccdy
Copy link
Author

sqxccdy commented Sep 17, 2015

but I maybe need normal merger..Such as for example with PyPDF2..

from PyPDF2 import PdfFileWriter, PdfFileReader
output = PdfFileWriter()
ipdf = PdfFileReader(open('output.pdf', 'rb'))
wpdf = PdfFileReader(open('transafe.pdf', 'rb'))
watermark = wpdf.getPage(0)
for i in xrange(ipdf.getNumPages()):
   try:
      page = ipdf.getPage(i)
      page.mergePage(watermark)
      output.addPage(page)
   except:
      pass
with open('newfile.pdf', 'wb') as f:
   output.write(f)

here generate not flipping pdf from code..but it have problem in pdf 1.4.
i think watemark need custom options or providing method to adjustment.
in pdf1.4 maybe have the problam.i can send mail to you for my pdf file..
Thanks in advance

@pmaupin
Copy link
Owner

pmaupin commented Sep 17, 2015

Thank you for this bug report. I have checked in some code on a new branch that fixes this problem.

When I did a rewrite of my merge code, I forgot to save graphics state if the object was a regular page and not a form XObject. Most PDFs work fine this way, but your example PDF alters the graphics state and leaves it altered (which is perfectly legal, but which I did not have a failing PDF for).

I have not yet checked the fix into the master because I will first need to update expected checksums for the output of the watermark test. There is one changed file, here:

https://github.com/pmaupin/pdfrw/blob/pagemerge_state_save_restore/pdfrw/pagemerge.py

Please verify it works on all your files.

Also, if you can create a non-sensitive file that the old one fails on and the new one works on I will add it to the test suite.

@ThomasWaldmann -- you may also want this fix, depending on how much control you have over the PDFs you are watermarking -- it is a definite bug in pdfrw, but the PDFs you provided so far did not provoke it.

Thanks,
Pat

@claytonbrown
Copy link

yup, works fine, had the same issue

@takluyver
Copy link
Collaborator

The branch to fix this is now merged, so I'm closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants