1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > android图片合并pdf Android:使用iText API合并PDF文件不工作

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

时间:2022-08-24 07:12:19

相关推荐

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();

}

}

任何想法?

谢谢

-05-03

kyogs

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。