结合PDF c#

如何在没有第三方组件的情况下将多个PDF组合成一个PDF?

我认为你不能。 Opensource组件PDFSharp具有该function,并且是文件组合的一个很好的源代码示例

.NET Framework不包含修改/创建PDF的function。 您需要第三方组件才能完成您所需的任务。

正如其他人所说的那样,没有任何内容可以完成这项任务。 将iTextSharp与此示例代码一起使用 。

AFAIK C#没有内置的处理PDF的支持,所以如果不使用第三方组件或COTS库,就无法完成。

关于图书馆,有无数的可能性。 仅举几点:

http://csharp-source.net/open-source/pdf-libraries

http://www.codeproject.com/KB/graphics/giospdfnetlibrary.aspx

http://www.pdftron.com/net/index.html

我不认为.NET Framework包含类似库。 我使用iTextsharp和c#来组合pdf文件。 我认为iTextsharp是最简单的方法。 这是我使用的代码。

string[] lstFiles=new string[3]; lstFiles[0]=@"C:/pdf/1.pdf"; lstFiles[1]=@"C:/pdf/2.pdf"; lstFiles[2]=@"C:/pdf/3.pdf"; PdfReader reader = null; Document sourceDocument = null; PdfCopy pdfCopyProvider = null; PdfImportedPage importedPage; string outputPdfPath=@"C:/pdf/new.pdf"; sourceDocument = new Document(); pdfCopyProvider = new PdfCopy(sourceDocument, new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create)); //Open the output file sourceDocument.Open(); try { //Loop through the files list for (int f = 0; f < lstFiles.Length-1; f++) { int pages =get_pageCcount(lstFiles[f]); reader = new PdfReader(lstFiles[f]); //Add pages of current file for (int i = 1; i <= pages; i++) { importedPage = pdfCopyProvider.GetImportedPage(reader, i); pdfCopyProvider.AddPage(importedPage); } reader.Close(); } //At the end save the output file sourceDocument.Close(); } catch (Exception ex) { throw ex; } private int get_pageCcount(string file) { using (StreamReader sr = new StreamReader(File.OpenRead(file))) { Regex regex = new Regex(@"/Type\s*/Page[^s]"); MatchCollection matches = regex.Matches(sr.ReadToEnd()); return matches.Count; } } 

ITextSharp是要走的路

虽然已经说过,但您无法使用.NET Framework的内置库来操作PDF。 但我可以推荐iTextSharp ,它是Java iText的.NET端口。 我玩过它,发现它是一个非常容易使用的工具。