3

I have an Android App which renders HTML to PDF using Android (Kotlin) webView from webkit and PrintDocumentAdapter. The margins for printing are set with a @page like this:

@page {
    size: A4 portrait;
    margin: 20mm 15mm 20mm 15mm;
}

@media screen, print {
    html, body {
        width: 210mm;
        height: 294mm;
    }

    page {
        box-shadow: 0;
        display: block;
    }

}

I added with AND height due to the following reference Chrome seems to miscalculate css sizes given in mm unit when printing. But missing width ist not the problem here. Until recent Chrome for Android Update (78.0.3904.62) the generated html did render perfectly with the desired margins to a ISO A4 pdf. When using the following PrintAttributes in Kotlin:

var attributes : PrintAttributes = PrintAttributes.Builder()
                .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
                .setResolution(PrintAttributes.Resolution("pdf", "pdf", 150, 150))
                .setMinMargins(PrintAttributes.Margins.NO_MARGINS).build()

But after the Chrome update our app produces pdfs with 8cm margin on all four sides. I could fix the issue for now using px instead of mm. But this does not feel like the correct solution. This is the html/css which works for now:

@page {
    size: A4 portrait;
    margin: 22px 20px 23px 21px;
}

@media screen, print {
    html, body {
        width: 210mm;
        height: 294mm;
    }

    page {
        box-shadow: 0;
        display: block;
    }

}

Is this a bug in Chrome for Android or am I missing something important here?

masp
  • 350
  • 3
  • 10

0 Answers0