目标: 检索一些pdf文件,然后将这些pdf中的某一些页append在一起,生成新的pdf文件
应用的DLL文件,PDFBox.
http://sourceforge.net/projects/pdfbox/ 下载dll
引用:PDFBox-0.7.3.dll
IKVM.GNU.Classpath
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using org.pdfbox.pdmodel;
using org.pdfbox.pdmodel.common;
using org.pdfbox.util;
using org.pdfbox.pdfwriter;
using org.pdfbox.io;
protected void Page_Load(object sender, EventArgs e)
{
/*PDDocument doc = PDDocument.load("c://test//a.pdf");
java.util.List list = doc.getDocumentCatalog().getAllPages();
PDPage page1 = list.get(0) as PDPage;
PDPage page2 = list.get(1) as PDPage;
PDDocument newDoc = new PDDocument();
newDoc.addPage(page1);
newDoc.addPage(page2);
newDoc.save("c://test//test.pdf");
*/
PDDocument newDoc = new PDDocument();
ProcessDoc(newDoc, "c://test//a.pdf");
ProcessDoc(newDoc, "c://test//circ92.pdf");
ExportDoc(newDoc);
}
private void ExportDoc(PDDocument newDoc)
{
java.io.ByteArrayOutputStream output = new java.io.ByteArrayOutputStream();
newDoc.save(output);
byte[] data = output.toByteArray();
string attachment = "attachment; filename=Contacts.pdf";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/pdf";
Response.BinaryWrite(data);
Response.End();
}
private void ProcessDoc(PDDocument newDoc, string oldDocName)
{
PDDocument doc = PDDocument.load(oldDocName);
java.util.List list = doc.getDocumentCatalog().getAllPages();
PDPage page1 = list.get(0) as PDPage;
PDPage page2 = list.get(1) as PDPage;
newDoc.addPage(page1);
newDoc.addPage(page2);
}