1

I have two PDF files and I want to merge two PDF files in single PDF files using IronPDF (reference from https://ironpdf.com/). Here is the code I am using

            var PDFs = new List<PdfDocument>();

            foreach (var file in files)
            {
                PDFs.Add(PdfDocument.FromFile(file));
            }

            PdfDocument PDF = PdfDocument.Merge(PDFs);
            newFileName = Path.Combine(TEMP_PDF_FILESTORE_LOCATION, newFileName);
            PDF.SaveAs(newFileName);

While merging two PDF files here is the error it showing "Could not safely read page objects from AnotherPdfFile". One of PDF can contain image in that. Some image PDF it will take some throw error. How we can remove this error?

Tejas
  • 107
  • 4
  • 13

1 Answers1

2

I got the same error (Could not safely read page objects from AnotherPdfFile) when I tried to merge PDF documents that were constructed using streams that came from another service.

In order to solve this, I had to first copy each stream into a MemoryStream and then passing in the memory stream into the PdfDocument constructor. Using memory streams, IronPdf was able to merge these.

Dejan
  • 9,150
  • 8
  • 69
  • 117