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

Adding other PDFs into output #1271

Closed
wangkev opened this issue Dec 15, 2020 · 7 comments
Closed

Adding other PDFs into output #1271

wangkev opened this issue Dec 15, 2020 · 7 comments

Comments

@wangkev
Copy link

wangkev commented Dec 15, 2020

Is it possible to add other pdfs directly into a weasyprint output pdf? Basically interested in something like:

Output PDF document:

  • weasyprint page 1
  • weasyprint page 2
  • other pdf page 1
  • other pdf page 2
  • weasyprint page 5
  • ...

I think there was past discussion #52, but not sure if it is exactly the same issue (and where it stands given the migration to pydyf).

My current solution is to leverage PyPDF2, but the links within the document break after merging the document (open issue py-pdf/pypdf#471).

@liZe
Copy link
Member

liZe commented Dec 15, 2020

Hi!

WeasyPrint doesn’t offer the possibility to include other PDFs. Rendering HTML and CSS is already a big challenge, we’ve just added the PDF generation part to this challenge, I think that’s difficult enough 😉!

Using third-party libraries as you do is probably the best solution for now. Is that OK for you?

@wangkev
Copy link
Author

wangkev commented Dec 15, 2020

Thanks for the reply!

Utilizing PyPDF2 is fine, but a bit of a roundabout solution as I have to generate dummy pages to be replaced (to ensure page numbers are correct), and would be ideal to have the links work. Unfortunately, I am not super familiar with the inner workings of PDF, so not really sure why the links would break in the first place.

Naively, looking through the code, it seems like new pages are added here:

pdf.add_page(pdf_page)

If I wanted to hack together a more pydyf/weasyprint solution, would it be possible to just inject the pages from the other PDF there?

@liZe
Copy link
Member

liZe commented Dec 15, 2020

not really sure why the links would break in the first place.

I can’t really tell, it depends on how you use PyPDF2. The PyPDF2 team knows much more about PDF than we do!

If I wanted to hack together a more pydyf/weasyprint solution, would it be possible to just inject the pages from the other PDF there?

As far as I know, there’s no easy way to add pages from one PDF to another. PDFs contain "objects", and copying a page means that you also have to copy the objects it contains. As these objects can reference other objects, you actually have to do this recursively.

Moreover, pydyf only generates PDF files, it’s totally unable to read them. So… Use PyPDF2. pydyf can’t help you for what you want to do.

@wangkev
Copy link
Author

wangkev commented Dec 16, 2020

Understood -- appreciate the clarification. Would there be any possibility so support this in the future, or should I close this issue?

@liZe
Copy link
Member

liZe commented Dec 16, 2020

Would there be any possibility so support this in the future, or should I close this issue?

I don’t think that this feature will ever be included in WeasyPrint, it’s too complicated and out of the scope. Sorry 😒.

@liZe liZe closed this as completed Dec 16, 2020
@dmkallan
Copy link

Very much in search of the exact same capability: use some sort of HTML tag or CSS property to include pages from external PDFs inline.

@ericbf
Copy link

ericbf commented Mar 14, 2023

@wangkev

Utilizing PyPDF2 is fine, but a bit of a roundabout solution as I have to generate dummy pages to be replaced (to ensure page numbers are correct)

Can you elaborate on this workaround? I am wanting to get page numbers working when appending PDFs, and have no links to break in my docs.

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

4 participants