PDF操作

2022-04-01  本文已影响0人  code_搬运工

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

上一篇下一篇

猜你喜欢

热点阅读