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;
}
网友评论