0

Hey guys I try to print a bootstrap modal which contains an iframe pointing to a local pdf file. The modal itself looks fine.

t

Problem is I want to print the modal with my own button (not the one in the pdf dialog, this works great).

<button onclick="window.print()">print page!<button />

If I do that, the pdf is cut off. This seems to happen only with pdf, not f.i. images.

enter image description here

1
  • no it is not landscape :( I tried all settings but unfortunately it did not help! Commented Sep 16, 2024 at 18:25

1 Answer 1

0

The problem is the iframe does not scale to match the size of your pdf.

There is no native way of fixing this in the browser, but we can work around the issue with a couple of JS librairies.

The first step is to use a JS PDF renderer, rather than the native browser PDF render. This then allows us to run JS alongside the PDF.

Next we can use JS to workout the size of the PDF and resize the iframe. This is an overly complex problem that is solved by the iframe-resizer library.

Once you have both of these setup the iframe will automagically scale to the size of your PDF and stay correctly scaled when the viewport is resized during the print process.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.