PDF操作

作者: code_搬运工 | 来源:发表于2022-04-01 10:25 被阅读0次

    http://www.pdfsharp.net/wiki/ConcatenateDocuments-sample.ashx

    多个PDF文件合成一个

     string[] files = new string[3] { @"D:\ee\1.pdf", @"D:\ee\2.pdf", @"D:\ee\3.pdf" };
    
                try
                {
                    Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
    
                    // Open the output document
    
                    PdfDocument outputDocument = new PdfDocument();
                    // Iterate files
                    foreach (string file in files)
    
                    {
    
                        // Open the document to import pages from it.
                        PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import);
    
                        // Iterate pages
                        int count = inputDocument.PageCount;
                        for (int idx = 0; idx < count; idx++)
                        {
                            // Get the page from the external document...
                            PdfPage page = inputDocument.Pages[idx];
                            // ...and add it to the output document.
                            outputDocument.AddPage(page);
    
                        }
    
                    }
    
                    // Save the document...
                    const string filename = @"D:\ee\new.pdf";
                    outputDocument.Save(filename);
    
                    // ...and start a viewer.
    
                    //Process.Start(filename);
                }
                catch (Exception ex)
                {
    
                    throw;
                }
    
    

    相关文章

      网友评论

          本文标题:PDF操作

          本文链接:https://www.haomeiwen.com/subject/mdrnjrtx.html