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

Support for appending to existing PDF / TIFF files #2959

Closed
vashek opened this issue Jan 14, 2018 · 11 comments · Fixed by #2965
Closed

Support for appending to existing PDF / TIFF files #2959

vashek opened this issue Jan 14, 2018 · 11 comments · Fixed by #2965

Comments

@vashek
Copy link
Contributor

vashek commented Jan 14, 2018

I need the ability to append images as pages to existing PDF files.
I have an implementation for PDFs up to version 1.4. Seems to be working fine as far as I can tell, but if anyone knows of any tools to verify the correctness of a PDF, or in general an idea for how to test this other than verify that I can open the PDF file and it looks right...

Would a pull request be welcome for this?

The same could also easily be done for TIFFs, I believe.

@radarhere
Copy link
Member

@vashek
Copy link
Contributor Author

vashek commented Jan 15, 2018

I'm aware of that, but as far as I can tell, you can only create new PDF files (and yes, then append more images to them).
What I have in mind is appending pages to existing PDF files.

(I have actually since realized that I'm stupid and what I really need is merge two PDFs into one (or, open a PDF image and append it to another PDF). But appending images to an existing PDF is potentially still at least half a solution, and I have it done, so I might as well contribute it.)

@radarhere
Copy link
Member

You're right, sorry, I have forgotten that Pillow does not read PDFs. Regarding the TIFF format though, that at least should be able to be handled by Pillow, yes?

@vashek
Copy link
Contributor Author

vashek commented Jan 15, 2018

Well in the sense that you can open a TIFF file and then write it back from scratch while appending another image, yes. If you want to avoid the overhead of reading and writing back, there actually is an existing solution in Pillow called TiffImagePlugin.AppendingTiffWriter, but there is no standard API and I don't even think AppendingTiffWriter is documented. (It is used internally by TiffImagePlugin for writing multipage TIFFs.)

@vashek
Copy link
Contributor Author

vashek commented Jan 18, 2018

So, here's my attempt at an implementation for PDFs. Supports PDFs up to version 1.4. Tested with Python 3.6 and as far as I can tell, works great. The pdfReader module itself is tested with Python 2.7 as well, but not the PdfImagePlugin part. I haven't touched the documentation at all yet.

vashek added a commit to vashek/Pillow that referenced this issue Jan 22, 2018
vashek added a commit to vashek/Pillow that referenced this issue Jan 24, 2018
…remnants of text writing from PdfImagePlugin
vashek added a commit to vashek/Pillow that referenced this issue Jan 24, 2018
@vashek
Copy link
Contributor Author

vashek commented Jan 24, 2018

So this has turned into a major rework of PdfImagePlugin. :) I have now added tests and am confident it works nicely, and in fact opens the path for some more new features, such as specifying key+value metadata when saving PDFs, specifying margins or placing on the page and perhaps even opening bitmap PDFs.

Any feedback, please? Pretty please? :)

@wiredfool
Copy link
Member

I'll take a look.

vashek added a commit to vashek/Pillow that referenced this issue Jan 24, 2018
vashek added a commit to vashek/Pillow that referenced this issue Jan 24, 2018
vashek added a commit to vashek/Pillow that referenced this issue Jan 24, 2018
vashek added a commit to vashek/Pillow that referenced this issue Jan 24, 2018
vashek added a commit to vashek/Pillow that referenced this issue Jan 25, 2018
vashek added a commit to vashek/Pillow that referenced this issue Jan 26, 2018
vashek added a commit to vashek/Pillow that referenced this issue Jan 26, 2018
vashek added a commit to vashek/Pillow that referenced this issue Jan 26, 2018
vashek added a commit to vashek/Pillow that referenced this issue Jan 26, 2018
vashek added a commit to vashek/Pillow that referenced this issue Jan 26, 2018
vashek added a commit to vashek/Pillow that referenced this issue Jan 26, 2018
vashek added a commit to vashek/Pillow that referenced this issue Jan 26, 2018
…thods to support writing, eliminate the passing of file or buffer
@vashek
Copy link
Contributor Author

vashek commented Jan 26, 2018

I'm now reasonably satisfied with the result. Documentation and tests are done as well. What do you say?

vashek added a commit to vashek/Pillow that referenced this issue Jan 30, 2018
vashek added a commit to vashek/Pillow that referenced this issue Jan 30, 2018
vashek added a commit to vashek/Pillow that referenced this issue Jan 31, 2018
@vashek
Copy link
Contributor Author

vashek commented Feb 6, 2018

Sorry to nag but... merge please? Or more feedback? Thanks. :)

@wiredfool
Copy link
Member

I'm not going to have time to look at this until friday at the very earliest.

@vashek
Copy link
Contributor Author

vashek commented Feb 19, 2018

Would it help, hypothetically, if I somehow split this into multiple smaller pull requests?

vashek added a commit to vashek/Pillow that referenced this issue Mar 3, 2018
vashek added a commit to vashek/Pillow that referenced this issue Mar 3, 2018
vashek added a commit to vashek/Pillow that referenced this issue Mar 3, 2018
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

Successfully merging a pull request may close this issue.

3 participants