PDFBOX 粘贴pdf文件

目标: 检索一些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);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值