Home > Java > javaTutorial > body text

How to deal with garbled Chinese characters in java pdf

藏色散人
Release: 2020-04-07 09:35:08
Original
3545 people have browsed it

How to deal with garbled Chinese characters in java pdf

#What should I do if the java pdf has Chinese garbled characters?

Solve the problem of Chinese garbled characters and data misalignment in javapdf export files

Recommended tutorial: "java learning"

First, let’s talk about Chinese garbled characters Problem, javapdf uses ISO-8859-1 encoding internally, and usually our database encoding is UTF-8 or GBK. If transcoding is not performed before javapdf is written, the exported file will be garbled in Chinese, so after traversing each This code should be added to the data of each field

 if(object instanceof String){  
         object = new String(((String)object).getBytes("GBK"),"ISO-8859-1");  
}
Copy after login

The GBK here is the encoding of the database where the data is located, which changes according to your own situation.

Let’s talk about data misalignment, because the maximum field length supported by PDF is only 255, so when the field length you pass in is greater than 255, javapdf will perform a %6 operation with you to ensure that the field length is less than 256 , and data misalignment is usually caused by this operation, so we can only control the length of the incoming field data on the code side and intercept it appropriately to ensure that the length of the field you transfer cannot be greater than 255, while ensuring that your field data It will not be greater than 255, and Chinese must be divided by 2.

The above is the detailed content of How to deal with garbled Chinese characters in java pdf. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template