dotnet / docfx

Static site generator for .NET API documentation.
https://dotnet.github.io/docfx/
MIT License
4.05k stars 862 forks source link

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

Closed cjlotz closed 6 months ago

cjlotz commented 6 months ago

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?

filzrev commented 6 months ago

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

1. Set PagePdfOptions's PreferCSSPageSize property to true.

https://github.com/dotnet/docfx/blob/464b947169eee016e4ca166cbae3f6a82f6178eb/src/Docfx.App/PdfBuilder.cs#L169 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 commented 6 months ago

Make sense to me to set PreferCSSPageSize to true.