htmlexpresspdfnext.jshtml-pdf

Is it possible to embed an iframe using html-pdf on Express?


I have the following file as a html just for testing purposes:

    <div id="pageHeader">
        <h1>Page Header</h1>
        <p>test</p>
    </div>
    <div>
        <iframe
            title="something"
            src="https://geoportal.implanchihuahua.org/sigmun/apps/webappviewer/index.html?id=92971c77b4b047f89d35b08791a83db9"
            width='100%'
            height='100%'>
        </iframe>

The question might seem kind of weird and obvious, but I wanted to give it a try. Is it possible to embed an iframe component and export it as an image to a pdf file using the library html-pdf?

My sample method to make the PDF on an endpoint is the following:

    let baseFile = fs.readFileSync('./src/templates/test.html', 'utf8');
    console.log(baseFile);
    pdf.create(baseFile).toFile('./test.pdf', (err, res) => {
        if (err){
            console.log(err);
        }else {
            console.log(res);
        }
    })

Solution

  • Without html-pdf active I can not say for definite, However the css styling of the iFrame will potentially need to be obtained and applied by you for your own html-pdf rendering, here we can see using skia engine, that there is a mixture of good and bad PDF rendering in parts of the iFrame.

    Customisation of .css is likely to be complex or varied from dynamic case to case, but some drop out may be inevitable, if not using simple images.

    enter image description here

    enter image description here