Recently, I used itextpdf to print invoices, but there was an error when reading the file stream. The following is the key code
ClassPathResource classPathResource = new ClassPathResource("/template/RU_HK_INVOICE_TEMPLATE.pdf");
InputStream inputStream = classPathResource.getInputStream();
reader = new PdfReader(inputStream);// read the template of pdf
The following errors are reported in the new PdfReader(inputStream) each time:
com.itextpdf.text.exceptions.InvalidPdfException: Rebuild failed: trailer not found.; Original message: xref subsection not found at file pointer
Maven will use pom XML configuration files uniformly encode the project, but some files do not need to be re encoded, such as PDF template files; After recoding, the PDF template structure may be damaged, resulting in the unavailability of the files generated after compilation, as shown in the following figure
Therefore, it is necessary to filter out the files that do not need to be encoded: filter all files with the suffix .pdf or .p8 and do not encode them uniformly. Need to be configured in the pom.xml file nonFilteredFileExtension tag
<!-- Filter the suffixes of files that do not need to be transcoded pdf -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<encoding>UTF-8</encoding>
<useDefaultDelimiters>false</useDefaultDelimiters>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>pdf</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
Read More:
- [Solved] The war package Error: The reason why the XSD file could not be found
- [Solved] Could not find resource COM / atguigu / Dao / studentdao.xm, the mapper file for storing SQL statements could not be found and an error occurred
- [Solved] ImageIO.read(inputStream) Read .webp Format Image Error
- [Solved] Read the resources resource and convert it to file error: java.io.filenotfoundexception
- [Maven] maven filtering OTS parsing error incorrect file size in WOFF head [Two Methods to Solve]
- JAVA: How to Convert PDF from Color to Grayscale
- Failed to restart redis-server.service Unit not found [How to Solve]
- springboot jsp: There was an unexpected error (type=Not Found, status=404). No message available
- [Solved] maven Error: Failed to read artifact descriptor for org.
- ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration…
- [Solved] Mac Maven Command Error: zsh: command not found
- BeanDefinitionStoreException: Failed to read candidate component class probably due to a new Java
- [Solved] com.alibaba.druid.filter.FilterManager : load filter error, filter not found : sl4j
- Java: How to use itext to export PDF text absolute positioning (implementation method)
- [Solved] Mybatis-Plus Error: Invalid bound statement (not found)
- Mybatis Error: Invalid bound statement (not found)
- [How to Solve] Invalid bound statement (not found)
- How to Solve Mybatis error: invalid bound statement (not found)
- Maven (http://repo1.maven.org/maven2/): Failed to transfer file and PKIX path building failed: sun.secu
- [Javac compilation exception] javac compilation prompts that the package in jdk cannot be found error: package jdk.internal.org.objectweb.asm does not exist and error: cannot find symbol