簡體   English   中英

如何在使用 IronPdf 合並兩個 PDF 時使文件變平?

[英]How to make file flatten while merging two PDF using IronPdf?

I have two PDF files and I want to merge two PDF files in single PDF files using IronPDF (reference from https://ironpdf.com/ ). 這是我正在使用的代碼

            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);

在此處合並兩個 PDF 文件時出現錯誤,顯示“無法從另一個 PdfFile 安全地讀取頁面對象”。 PDF 之一可以在其中包含圖像。 一些圖像 PDF 會出現一些拋出錯誤。 我們怎樣才能消除這個錯誤?

當我嘗試合並使用來自另一個服務的流構建的 PDF 文檔時,我遇到了同樣的錯誤( Could not safely read page objects from AnotherPdfFile )。

為了解決這個問題,我必須首先將每個 stream 復制到MemoryStream中,然后將 memory stream 傳遞到PdfDocument構造函數中。 使用 memory 流,IronPdf 能夠合並這些流。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM