Some test text!

menu
Remove contentkeyboard_arrow_down

Removing images from PDF page in Node.js

To remove all images from a document page.

const doc = await PDFNet.PDFDoc.createFromURL(filename);
const firstPage = 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();

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

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Join our live demo to learn about use cases & capabilities for WebViewer

Learn more
close