使用C#创建修改合并PDF文件

iTextSharp

iTextSharp is a library that allows you to generate PDF files on the fly.

 

Report.NET

Report.NET is a powerful library that will help you to generate PDF documents in a simple and flexible manner. The document can be created with data that have been retrieved from any ADO.NET data set.

 

 

PDFsharp

PDFsharp is a C# library that easily creates PDF documents on the fly. The same GDI+ like drawing routines can be used to create PDF documents, draw on the screen, or send output to any printer. PDFsharp can also modify, merge, and split existing PDF files or incorporate pages from existing PDF files into new PDF documents.

 

SharpPDF

SharpPDF is a C# library that implements different objects for the creation of PDF documents with few steps. It is created for .NET framework 1.1 and it can create 100% compatible PDF

 

PDFjet Open Source Edition

PDFjet Open Source Edition is a library for dynamic generation of PDF documents from Java and .NET. The PDFjet Open Source Edition has the following features: 
* Drawing support for: points, lines, boxes, circles, bezier curves, polygons, stars, complex paths and shapes. 
* Text: unicode support, text kerning when using the Helvetica and Times-Roman families of core fonts, embedding hyperlinks.

 

ASP.NET FO PDF

FO PDF is similar to ASP.NET Server Controls, written in C#

 

PDF Clown

PDF Clown is a C# 2.0 library for reading, manipulating and writing PDF files, with multiple abstraction layers to satisfy different programming styles: from the lower level (PDF object model) to the higher (PDF document structure and content streaming). Its primary target platform is GNU/Linux, but thanks to the Mono project it’s virtually platform-agnostic.

 

http://alex.buayacorp.com/merge-pdf-files-with-itext-and-net.html

http://www.wacdesigns.com/2008/10/03/merge-pdf-files-using-c/

http://www.zachhunter.net/blog/2009/04/28/MergeAndCombinePDFsInC.aspx

 

http://stackoverflow.com/questions/177/how-do-i-programmatically-create-a-pdf-in-my-net-application

http://www.aneef.net/2008/07/24/create-pdf-files-on-the-fly-with-c-and-pdfsharp/

 

 

 

 

 

[.Net C#] iTextSharp合併PDF檔

下面為使用iTextSharp來合併PDF檔的function

 

01 using iTextSharp.text;
02 using iTextSharp.text.pdf;
03  
04 using System.IO;
05 using System.Collections;
06 using System.ComponentModel;
07 using System.Text;
08  
09 /// <summary> 合併PDF檔(集合) </summary>
10 /// <param name="fileList">欲合併PDF檔之集合(一筆以上)</param>
11 /// <param name="outMergeFile">合併後的檔名</param>
12 private void mergePDFFiles(string[] fileList,string outMergeFile)
13 {
14     outMergeFile = Server.MapPath(outMergeFile);
15     PdfReader reader;
16     Document document = new Document();
17     PdfWriter writer = PdfWriter.GetInstance(document,new FileStream(outMergeFile,FileMode.Create));
18     document.Open();
19     PdfContentByte cb = writer.DirectContent;
20     PdfImportedPage newPage;
21     for(int i = 0;i < fileList.Length;i++)
22     {
23         reader = new PdfReader(Server.MapPath(fileList[i]));
24         int iPageNum = reader.NumberOfPages;
25         for(int j=1;j<=iPageNum;j++)
26         {
27             document.NewPage();
28             newPage = writer.GetImportedPage(reader,j);
29             cb.AddTemplate(newPage,0,0);
30         }
31     }
32     document.Close();
33 }

 

如要叫用可以用以下方式

 

1 private void mergePDF()
2 {
3     string[] pdflist = new string[3];
4     pdflist[0] = "RPT01.pdf";
5     pdflist[1] = "RPT02.pdf";
6     pdflist[2] = "RPT03.pdf";
7     mergePDFFiles(pdflist,"newpdf1.pdf");
8 }

 

 

 

 

 

 

 

 

posted @   China Soft  阅读(9271)  评论(2编辑  收藏  举报
编辑推荐:
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示