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

[Feature Request] Print PDF's in landscape orientation and using specific page size #9842

Closed
cjlotz opened this issue Apr 7, 2024 · 2 comments · Fixed by #9850
Closed

[Feature Request] Print PDF's in landscape orientation and using specific page size #9842

cjlotz opened this issue Apr 7, 2024 · 2 comments · Fixed by #9850
Labels
pdf Produce PDF as the output format

Comments

@cjlotz
Copy link
Contributor

cjlotz commented Apr 7, 2024

How difficult will it be to extend to the existing PDF printing logic to specify the orientation and page size of the page that should be used? Thinking of adding pdfOrientation: landscape | portrait setting. If not specified it should default to portrait. For size, using something like pdfPageSize: A0 | A1 .. | Letter

If possible, any pointers where to start looking at adding the support to the existing code base?

@cjlotz cjlotz changed the title [Feature Request] Print PDF's in landscape orientation [Feature Request] Print PDF's in landscape orientation or using specific page size Apr 7, 2024
@cjlotz cjlotz changed the title [Feature Request] Print PDF's in landscape orientation or using specific page size [Feature Request] Print PDF's in landscape orientation and using specific page size Apr 7, 2024
@filzrev
Copy link
Contributor

filzrev commented Apr 7, 2024

I've confirmed it can change page size and orientation with following steps.

1. Set PagePdfOptions's PreferCSSPageSize property to true.

return await page.PdfAsync(new PagePdfOptions { PrintBackground = outline.pdfPrintBackground });

See: https://playwright.dev/docs/api/class-page#page-pdf-option-prefer-css-page-size

2. Add print style at custom template's main.css file.

@media print {
  @page {
    size: A3 landscape
  }
}

@yufeih
Copy link
Contributor

yufeih commented Apr 8, 2024

Make sense to me to set PreferCSSPageSize to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pdf Produce PDF as the output format
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants