你好,我有一个问题,我想使用来自文本的pdf文件,我已经从itextpdf学习了,我已经遵循了所有教程,但是我仍然不知道文件成功创建后已损坏,有人可以帮我吗,这是我的代码
OutputStream stream=new FileOutputStream(Environment.getExternalStorageDirectory()+"/fileTest/cxz.pdf");
Document document=new Document();
PdfWriter.getInstance(document,stream);
document.open();
document.addTitle("cxcxcxcx");
document.addSubject("cxcxccx");
document.addCreator("cxcxcxcx");
document.add(new Paragraph("cxcxcxcx"));
document.close();
预先感谢
答案 0 :(得分:0)
编译'com.itextpdf:itextg:5.5.10'
try {
String parsedText="";
PdfReader reader = new PdfReader(yourPdfPath);
int n = reader.getNumberOfPages();
for (int i = 0; i <n ; i++) {
parsedText = parsedText+PdfTextExtractor.getTextFromPage(reader, i+1).trim()+"\n"; //Extracting the content from the different pages
}
System.out.println(parsedText);
Document document=new Document();
PdfWriter.getInstance(document,parsedText);
document.open();
document.addTitle("FileName");
document.addSubject("MyFile");
document.addCreator("cxcxcxcx");
document.add(new Paragraph("cxcxcxcx"));
reader.close();
} catch (Exception e) {
System.out.println(e);
}