-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Proposal: Allow authors to enforce "save as PDF" when printing a document #7946
Comments
@BenjaminAster May I work on this issue? |
@arya-vats Of course you may! After all, this is an open community where everyone can work on everything. |
Saving a document as a PDF can be surprisingly complex for the average end user, so I think this is desparately needed. I like the idea of |
@anaestheticsapp Great idea! If author-controlled options like layout or background graphics would be implemented, I think it would make sense here to make them universally available for both printing and saving as a PDF. I'd suggest an additional interface PrintOptions {
saveAsPDF?: boolean; // always sets "save as PDF" as the destination
print?: boolean; // always sets "print" as the destination
settings?: {
layout?: "portrait" | "landscape";
margins?: {
all?: number; // top, bottom, left, right
vertical?: number; // top, bottom
horizontal?: number; // left, right
top?: number;
bottom?: number;
left?: number;
right?: number;
};
scale?: number;
informationalText?: boolean; // headers and footers
backgroundGraphics?: boolean;
};
} |
As an alternative to passing print options, would it make sense to specify them via CSS using Paged Media where all these (and much more) are already specified? |
@mbrevda Ok, you're absolutely right! I've never looked into So I guess the |
One thing that was brought up was the ability to not convert the entire page to PDF, but just a subsection of it, for example, for printing receipts: <body>
<section><!-- App UI --></section>
<section class="receipt">
<h1>Receipt</h1>
<ul><!-- Receipt contents --></ul>
</section>
<section><!-- App UI --></section>
</body> If there were a way to pass a selector like |
@tomayac This can already be done (with a bit of effort) by re-layouting the whole page with But yes, I agree that it would be convenient to specify an element that gets printed individually and without some hacky CSS solution. Maybe something like |
Interesting - didn't know about Instead of having a boolean, another option could be to just pass the HTML element into saveAsPDF. window.print({ saveAsPDF: document.body })
window.print({ saveAsPDF: document.querySelector('section.receipt') }) Agree, would make sense to be able to specify metadata when generating the PDF document. I guess the browser could just use the data already provided by HTML
|
To simplify the API surface, perhaps the ability to print could be added to any element, like |
👍 In some situations it would be nice to have the ability to get the printed PDF file programmatically |
There are several use cases where it would be handy to be able to show a "save as PDF" dialog programmatically. For example, a document editing application might want to allow their users to export the document as a PDF without using any PDF generation library. While most user agents already allow users to select a "save as PDF" option when a document is printed (e.g. when
Window.print()
is called), there is currently no possibility for the author to hint the browser that the print dialog should be shown with the "save as PDF" option enabled.I am proposing an addition to the
Window.print()
method with an optional parameter that allows authors to tell the user agent the way that the print dialog should be shown:If the user agent is not able to provide a way to export the document as a PDF, it may ignore this option.
The text was updated successfully, but these errors were encountered: