You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Andreas Lehmkühler (Jira)" <ji...@apache.org> on 2020/05/07 15:20:00 UTC
[jira] [Updated] (PDFBOX-4823) After calling pdfont.encode, the
font file is not closed
[ https://issues.apache.org/jira/browse/PDFBOX-4823?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Andreas Lehmkühler updated PDFBOX-4823:
---------------------------------------
Description:
[^webdings.ttf]
1. Run the follows code on linux.
2. When the code is finished executing, use the command "lsof -c java | grep webdings" to check this font file is not released.
{code}
public static void main(String[] args) throws IOException {
System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");
PDDocument doc = new PDDocument();
PDPage page = new PDPage(PDRectangle.A4);
doc.addPage(page);
File file = new File("webdings.ttf");
PDType0Font ttFont = PDType0Font.load(doc, file);
PDPageContentStream contentStream1 = new PDPageContentStream(doc, page);
contentStream1.beginText();
contentStream1.newLineAtOffset(100, 100);
if(isCharacterEncodeable("depending", ttFont))
{
contentStream1.setFont(ttFont, 12);
contentStream1.showText("depending");
}
contentStream1.endText();
contentStream1.close();
doc.save("export.pdf");
doc.close();
System.out.println("aaaaa");
}
private static boolean isCharacterEncodeable(String text, PDType0Font font){
try {
font.encode(text);
return true;
} catch (Exception e) {
return false;
}
}
{code}
was:
[^webdings.ttf]
1. Run the follows code on linux.
2. When the code is finished executing, use the command "lsof -c java | grep webdings" to check this font file is not released.
public static void main(String[] args) throws IOException {
System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");
PDDocument doc = new PDDocument();
PDPage page = new PDPage(PDRectangle.A4);
doc.addPage(page);
File file = new File("webdings.ttf");
PDType0Font ttFont = PDType0Font.load(doc, file);
PDPageContentStream contentStream1 = new PDPageContentStream(doc, page);
contentStream1.beginText();
contentStream1.newLineAtOffset(100, 100);
if(isCharacterEncodeable("depending", ttFont))
{
contentStream1.setFont(ttFont, 12);
contentStream1.showText("depending");
}
contentStream1.endText();
contentStream1.close();
doc.save("export.pdf");
doc.close();
System.out.println("aaaaa");
}
private static boolean isCharacterEncodeable(String text, PDType0Font font){
try {
font.encode(text);
return true;
} catch (Exception e) {
return false;
}
}
> After calling pdfont.encode, the font file is not closed
> --------------------------------------------------------
>
> Key: PDFBOX-4823
> URL: https://issues.apache.org/jira/browse/PDFBOX-4823
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 2.0.12
> Reporter: bai yuan
> Priority: Major
> Attachments: webdings.ttf
>
>
> [^webdings.ttf]
> 1. Run the follows code on linux.
> 2. When the code is finished executing, use the command "lsof -c java | grep webdings" to check this font file is not released.
> {code}
> public static void main(String[] args) throws IOException {
> System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");
> PDDocument doc = new PDDocument();
> PDPage page = new PDPage(PDRectangle.A4);
> doc.addPage(page);
> File file = new File("webdings.ttf");
> PDType0Font ttFont = PDType0Font.load(doc, file);
> PDPageContentStream contentStream1 = new PDPageContentStream(doc, page);
> contentStream1.beginText();
> contentStream1.newLineAtOffset(100, 100);
> if(isCharacterEncodeable("depending", ttFont))
> {
> contentStream1.setFont(ttFont, 12);
> contentStream1.showText("depending");
> }
> contentStream1.endText();
> contentStream1.close();
> doc.save("export.pdf");
> doc.close();
> System.out.println("aaaaa");
> }
> private static boolean isCharacterEncodeable(String text, PDType0Font font){
> try {
> font.encode(text);
> return true;
> } catch (Exception e) {
> return false;
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org