twirl / The-API-Book

‘The API’ book by Sergey Konstantinov
Other
731 stars 38 forks source link

PDF formatting #2

Closed anthonsur closed 3 years ago

anthonsur commented 3 years ago

Hard to read generated PDF file.

Suggesting to add styles before generate PDF:

const printStyles = `
@media print {
    * { 
        text-align: left;
        line-height: 1.55;
    }
    code, pre {
        white-space: pre-wrap;
    }
    h1, h2, h3, h4, h5, h6 {
        page-break-inside: avoid;
    }
    h1::after, h2::after, h3::after, h4::after, h5::after, h6::after {
        content: "";
        display: block;
        height: 100px;
        margin-bottom: -100px;
    }
    p {
        orphans: 2;
        widows: 2;
    }
}`;

async function buildPdf() {
    //…
    await page.addStyleTag({ content: printStyles });
    //…
}

Thx for book, sir.

twirl commented 3 years ago

There are some print styles already. Could you be more specific, what problems make PDF hard to read?

anthonsur commented 3 years ago

There are some print styles already. Could you be more specific, what problems make PDF hard to read?

In earlier versions was problems with code formatting (one line) and small leading. Now seems all ok.

anthonsur commented 3 years ago

Just one more thing: text alignment. Justified text is ugly if there is no support for auto hyphenation (see https://drafts.csswg.org/css-text-3/#propdef-hyphens).

//cc @twirl

twirl commented 3 years ago

I returned text-align: left for small screens. As for auto hyphenation I greatly doubt it would work nice with a Russian text with lots of inlined code.