dotnet / docfx

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

[Bug] Footer and page size incorrect for custom printed layout #10087

Open cjlotz opened 3 months ago

cjlotz commented 3 months ago

Describe the bug Using the new #9850 feature to specify a custom layout, the footer containing page numbers is not positioned correctly. The page content is also not scaled correctly to fit onto the page

To Reproduce Steps to reproduce the behavior:

  1. Add custom CSS as in #9850 to force custom print layout
    @media print {
    @page {
        size: A4 landscape;
    }    
    }
  2. Build and run docfx to create output that includes pdf settings like the following sample globalMetadata
    "globalMetadata": {
      "_appTitle": "On Key Release Notes",
      "_appFooter": "On Key Plus 2024.13.0 (Build 0)",
      "_appFaviconPath": "images/favicon.png",
      "_appLogoPath": "images/onkey_icon.png",
      "_enableNewTab": true,
      "_enableSearch": true,
      "_disableNavBar": "true",
      "_disableBreadcrumb": "true",
      "_disableToc": "false",
      "_disableAffix": "false",
      "pdf": true,
      "pdfTocPage": true,
      "pdfFileName": "onkey_releasenotes.pdf",
      "pdfPrintBackground": true
    },

Generated output

image

Notice that the page content is not scaled to fix onto the page (nr 2) and that the footer is not positioned correctly (nr 1) as illustrated above

Context (please complete the following information):

filzrev commented 3 months ago

@cjlotz What is the size of the generated PDF file page?

On my Windows environment. Generated page size is displayed as 373 x 288 mm. And it's not match A4 landscape (297 x210mm).

I've confirmed same issues when using Playwright 1.4.0 and without PreferCSSPageSize setting. So I suspect environment-specific problems.

cjlotz commented 3 months ago

@filzrev I had an issue with the version of the docfx tool that was still 2.76.0. Once updated, the page scaling issue has been resolved, but the footer is still not positioned at the right side of the page being printed in A4 landscape orientation. I can confirm that my page size is correct (i.e. 297x210mm) for A4

image

filzrev commented 3 months ago

Thanks for your confirmation.

Page size problem is not related reported issues. I've confirmed It's occurred on Edge PDF Viewer and not occurred on Chrome/Acrobat Reader.


the footer is still not positioned at the right side of the page being printed in A4 landscape orientation.

It seems PDF header/footer rendering is not using PreferCSSPageSize settings currently. So default letter size setting is used for header/footer. https://github.com/dotnet/docfx/blob/main/src/Docfx.App/PdfBuilder.cs#L203-L208

If manually set following properties. PDF footer is rendered correctly.

Format = "A4",
Landscape = true,

It would be necessary to add an implementation of either of the following logics.

filzrev commented 2 months ago

Wrong PDF footer location problem should be fixed by PR(#10100)

Another reported issue (Table layout is corrupted on some condition) seems to be content-dependent problems.

Is is able to provide following information? (if it can be reproduceable on docfx v2.77.0)

cjlotz commented 2 months ago

@filzrev just confirming from my side that the table layout issues I reported initially in the bug report was related to the version of my docfx still being 2.76.0. Once I fixed that to 2.77.0 the table layout scaling issues were fixed with only the footer issue - which should now be resolved with PR #10100, remaining.