@coolgk/pdf
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.5 • Public • Published

    @coolgk/pdf

    a javascript / typescript module

    npm install @coolgk/pdf

    html to PDF module. create PDF files from html string or file.

    Report bugs here: https://github.com/coolgk/node-utils/issues

    Examples

    // for "error while loading shared libraries: libfontconfig.so" run "sudo apt-get -y install libfontconfig"
     
    import { Pdf, Format, Orientation } from '@coolgk/pdf';
    // OR
    // const { Pdf, Format, Orientation } = require('@coolgk/pdf');
     
    const pdf = new Pdf({
        tmpConfig: { dir: '/tmp/pdf' } // optional
    });
     
    pdf.createFromHtmlFile(
        '/tmp/test.html',
        {
            header: {
                height: '1cm',
                contents: "<strong style='color: red'>Page ${pageNumber} of ${numberOfPages} - ${pageNumber}</strong>"
            },
            footer: {
                height: '1cm',
                contents: 'footer <strong>Page ${pageNumber} of ${numberOfPages}</strong>'
            },
            margin: '0.5cm'
        }
    ).then((pdfFile) => {
        console.log(pdfFile);
    });
     
    const htmlCode = `<!DOCTYPE html><html><head>
            <title>CCES</title>
            <style>
                .pagebreak { page-break-after: always; }
                h2, h1 { color: red }
            </style>
        </head>
        <body>
            <div>
                <h1>page 1</h1>
                <p>some text <img src='https://dummyimage.com/600x400/3bbda9/f516ae.jpg'></p>
            </div>
            <div class="pagebreak"></div>
            <div>
                <h2>page 2</h2>
                <table>
                    <tr>
                        <td>texgt</td>
                        <td>text</td>
                    </tr>
                </table>
            </div>
        </body>
    </html>`;
     
    pdf.createFromHtmlString(htmlCode).then((pdfFile) => {
        console.log(pdfFile);
    });
     

    Install

    npm i @coolgk/pdf

    DownloadsWeekly Downloads

    4

    Version

    2.0.5

    License

    MIT

    Unpacked Size

    9.71 kB

    Total Files

    5

    Last publish

    Collaborators

    • coolgk