Some test text!

Loading...
Guides
Remove content

Removing images from PDF page in Node.js

To remove all images from a document page.

async function main() {
    const doc = await PDFNet.PDFDoc.createFromURL(filename);
    const page = await doc.getPage(1);

    const writer = await PDFNet.ElementWriter.create();
    const reader = await PDFNet.ElementReader.create();
    reader.beginOnPage(page);
    writer.beginOnPage(page, PDFNet.ElementWriter.WriteMode.e_replacement, false);

    for (let element = await reader.next(); element !== null; element = await reader.next()) 
    {
        const elementType = await element.getType();
        switch (elementType) 
        {
            case PDFNet.Element.Type.e_image:
            case PDFNet.Element.Type.e_inline_image:
                // remove all images by skipping them
                break;
            default:
                writer.writeElement(element);
                break;
        }
    }

    writer.end();
    reader.end();
}
PDFNet.runWithCleanup(main);

PDF Editor (Programmatic)
Full code sample which strips all images from the page and changes text color to blue.

Get the answers you need: Support

Upcoming Webinar: PDFTron SDK Tech Review | Nov 29, 2022 at 2 pm ET

PDFTron SDK

The Platform

NEW

© 2022 PDFTron Systems Inc. All rights reserved.

Privacy

Terms of Use