itext 合并多个pdf为一个pdf 报错
public class MergePdfs {
public static void mergePdfFiles(String[] files, String savepath) throws DocumentException {
try {
// ITextFontResolver fontResolver = renderer.getFontResolver();
// fontResolver.addFont("c:/Windows/Fonts/simsun.ttc", BaseFont.IDENTITY_H,
// BaseFont.NOT_EMBEDDED);
//
Document document = new Document(new PdfReader(files[0]).getPageSize(1));
File outFile = new File(savepath);
if(!outFile.exists()){
outFile.createNewFile();
}
PdfCopy copy = new PdfCopy(document, new FileOutputStream(outFile));
document.open();
for (int i = 0; i < files.length; i++) {
PdfReader reader = new PdfReader(files[i]);
int n = reader.getNumberOfPages();
for (int j = 1; j <= n; j++) {
document.newPage();
PdfImportedPage page = copy.getImportedPage(reader, j);
copy.addPage(page);
}
}
document.close();
} catch (IOException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
}
}
报错显示:
com.itextpdf.text.exceptions.InvalidPdfException: PDF header signature not found.
at com.itextpdf.text.pdf.PRTokeniser.getHeaderOffset(PRTokeniser.java:227)
at com.itextpdf.text.pdf.PdfReader.getOffsetTokeniser(PdfReader.java:486)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:176)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:219)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:207)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:197)
at cn.yitongwang.utils.MergePdfs.mergePdfFiles(MergePdfs.java:18)
at cn.yitongwang.service.CommonServiceImpl.slectAllPdfTasks(CommonServiceImpl.java:1487)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy8.slectAllPdfTasks(Unknown Source)
at cn.yitongwang.utils.PDFtransferEntrance.main(PDFtransferEntrance.java:14)
怎么解决!!
相关推荐
java使用iText实现PDF的输出
java使用iText实现PDF的输出 java使用iText实现PDF的输出 java使用iText实现PDF的输出 java使用iText实现PDF的输出
java实现docx,pdf文件动态填充数据
根据需求引入自己所需pom。
freemarker+Aspose.word实现模板生成word并转成pdf
使用itext模板导出pdf适用范围业务生成的 pdf 是具有固定格式或者模板的文字及其图片等内容,使用模板,只需要将不一致的地方改成文本域,然后进行文字填充就可以了;如果涉及的业务不能有模块化可以提取出来东西,从开头一步一步去绘画。参考链接JAVA 使用Itext模板生成pdf,解决图片插入,文本域超出字体缩放,半自动换行[https://blog.csdn.net/a_lllk/article/details/109450972]
PDFBox解析PDF报错Missing root object specification in trailer的解决方案
PDF文件格式作为一种广泛应用的文档标准,其内部结构遵循ISO 32000规范,由头部、主体、交叉引用表和尾部(Trailer)等部分组成。Trailer作为文件的导航终点,包含指向文档目录(Catalog)的根对象(Root)引用,这是解析器定位文档逻辑起点的关键。当文件在传输、存储或生成过程中发生损坏,导致Trailer信息缺失或无效时,解析器将无法正确读取文档结构,从而影响文本提取、内容分析等下游处理流程。Apache PDFBox作为Java生态中广泛使用的PDF处理库,在工程实践中常遇到此类文件结
iText-2.1.7.jar+iTextAsian.jar+ireport报错分析
ireport导出pdf格式出错分析及解决方案,其中包含iText-2.1.7.jar iTextAsian.jar


