[
https://issues.apache.org/jira/browse/PDFBOX-5209?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17364700#comment-17364700
]
James Tsou commented on PDFBOX-5209:
------------------------------------
I had run into similar file size issue on using Chinese characters, though I
don't need to procude editable acroForm field in the output PDF that contains
chinese characters.
A workaround will be drawing the chinese fonts directly using contentStream,
starting on the bottom left coordinates of the acroform text box field.
{code:java}
// ... code omitted
PDDocument pdDocument = ...;
PDField yourAcroFormField = ...;
PDFont your_font = PDType0Font.load(pdDocument, new FileInputStream("path to
the font file"), true);
// Pass page number as argument
PDPage page = pdDocument.getPage(...);
// Start the stream as append mode, if you enter here you should be certain the
text you are entering are not english
PDPageContentStream stream = new PDPageContentStream(pdDocument, page,
PDPageContentStream.AppendMode.APPEND, false)
COSArray fieldAreaArray = (COSArray)
yourAcroFormField.getCOSObject().getDictionaryObject(COSName.RECT);
// Start drawing, specify your font size, etc
stream.setFont(your_font, 10f);
stream.beginText();
// This specifies where to draw, x-coordinates and y-coordinates
// We want to start at the bottom left coordinate of the text field, and start
drawing the text.
stream.newLineAtOffset(((COSFloat)(fieldAreaArray.get(0))).floatValue(),
((COSFloat)(fieldAreaArray.get(1))).floatValue());
stream.showText("一二三四五六七八");
stream.endText();
stream.close(){code}
You can call acroForm.flatten and the end of your processing to remove all the
acroForm fillable fields in your result PDF.
The result should be generating PDFs that does not need to embed full chinese
characters.
If you don't mind slower methods, and are happy to use alternative methods to
generate PDF that can display chinese character without embedding the full
chinese font (20MB+), I suggest using OpenHTMLToPDF and JSoup.
You could insert the data like chinese characters into the HTML, and generate
PDF on the fly. Generation takes few seconds depends on the complexity, but you
don't have to worry about file size and font issue.
> Using Chinese character make the file size increases
> -----------------------------------------------------
>
> Key: PDFBOX-5209
> URL: https://issues.apache.org/jira/browse/PDFBOX-5209
> Project: PDFBox
> Issue Type: Improvement
> Components: AcroForm
> Affects Versions: 2.0.15
> Environment: java jdk 1.8
> Reporter: LI MING
> Priority: Blocker
> Labels: FileSize
> Attachments: picture1.jpg, picture2.jpg, picture3.jpg
>
>
> Like the title,we use Chinese Character to generate PDF form file ,it is
> successed.but the file size is larger than 10mb.except change the font
> file,Is there any other way we can solve this problem?
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]