android图片合并pdf,Android:使用iText API合并PDF文件不工作

我想通过使用iText API将两个或多个PDF文档合并成一个PDF文件合并。但在结果我得到合并pdf与0字节size.I发布我的代码如下所示。我也尝试了iText.jar文件,但给出相同的0尺寸的PDF。Android:使用iText API合并PDF文件不工作

,并得到这样的: - “找不到类 'com.itextpdf.text.pdf.PdfPrinterGraphics2D',从法com.itextpdf.text.pdf.PdfContentByte.createPrinterGraphicsShapes引用”。 我仍然没有取得任何成功。

代码:

public class ItextMerge {

public static void main() {

List list = new ArrayList();

try {

// Source pdfs

list.add(new FileInputStream(new File("mnt/sdcard/nocturia.pdf")));

list.add(new FileInputStream(new File("mnt/sdcard/Professional Android Application Development.pdf")));

// Resulting pdf

OutputStream out = new FileOutputStream(new File("mnt/sdcard/newmerge.pdf"));

doMerge(list, out);

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (DocumentException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

/**

* Merge multiple pdf into one pdf

*

* @param list

* of pdf input stream

* @param outputStream

* output file output stream

* @throws DocumentException

* @throws IOException

*/

public static void doMerge(List list, OutputStream outputStream)

throws DocumentException, IOException {

Document document = new Document();

PdfWriter writer = PdfWriter.getInstance(document, outputStream);

document.open();

PdfContentByte cb = writer.getDirectContent();

for (InputStream in : list) {

PdfReader reader = new PdfReader(in);

for (int i = 1; i <= reader.getNumberOfPages(); i++) {

document.newPage();

//import the page from source pdf

PdfImportedPage page = writer.getImportedPage(reader, i);

//add the page to the destination pdf

// cb.addTemplate(page, 0, 0);

// cb.addTemplate(page, 0, 0);

}

}

outputStream.flush();

document.close();

outputStream.close();

}

}

任何想法?

谢谢

2013-05-03

kyogs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值