Skip to content

Copying Pages which include Tables #1701

@tomhands1

Description

@tomhands1

What were you trying to do?

Trying to copy pages from an existing PDF Document into a new document

How did you attempt to do it?

const fullPDFDoc = await PDFDocument.load(fileBuffer);
        const pageNumbers: number[] = Array((endPage - startPage) - 1).fill(startPage - 1).map((startPage, pageIndex) => pageIndex + startPage);
        const newPDFDoc = await PDFDocument.create();
        const pages = await newPDFDoc.copyPages(fullPDFDoc, pageNumbers)
        pages.forEach(page => newPDFDoc.addPage(page));
        const bytes = await newPDFDoc.save();

What actually happened?

This works for buffers of PDF's where the pages that I am copying include text only, but does not appear to work if the pages being copied include tables which is the primary need that I have here.

What did you expect to happen?

I expected the tables to be copied over to the newly created document like what happens with PDF document without tables

How can we reproduce the issue?

const fullPDFDoc = await PDFDocument.load(fileBuffer);
        const pageNumbers: number[] = Array((endPage - startPage) - 1).fill(startPage - 1).map((startPage, pageIndex) => pageIndex + startPage);
        const newPDFDoc = await PDFDocument.create();
        const pages = await newPDFDoc.copyPages(fullPDFDoc, pageNumbers)
        pages.forEach(page => newPDFDoc.addPage(page));
        const bytes = await newPDFDoc.save();

Version

1.17.1

What environment are you running pdf-lib in?

Node

Checklist

  • My report includes a Short, Self Contained, Correct (Compilable) Example.
  • I have attached all PDFs, images, and other files needed to run my SSCCE.

Additional Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions