You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Gregor Ambrozic (JIRA)" <ji...@apache.org> on 2016/03/14 19:55:33 UTC
[jira] [Reopened] (PDFBOX-3272) Loaded fonts file descriptors open
after closing document
[ https://issues.apache.org/jira/browse/PDFBOX-3272?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gregor Ambrozic reopened PDFBOX-3272:
-------------------------------------
Reopening for the reasons in my last comment.
> Loaded fonts file descriptors open after closing document
> ---------------------------------------------------------
>
> Key: PDFBOX-3272
> URL: https://issues.apache.org/jira/browse/PDFBOX-3272
> Project: PDFBox
> Issue Type: Bug
> Components: FontBox
> Affects Versions: 2.0.0
> Environment: Apache Tomcat, Linux
> Reporter: Gregor Ambrozic
> Assignee: Andreas Lehmkühler
> Fix For: 2.0.0
>
> Attachments: OpenSans-Regular.ttf
>
>
> I am experiencing problems with TTF fonts loaded for generating PDFs which eventually result in too many open files on Linux. The PDFBox version I tested last was 2.0.0-RC3.
> Basically for each PDF I create a document and load two fonts which I want to use. After the document is generated I close all the resources, but the file descriptors for both fonts remain open.
> The file descriptors should be automatically closed or an API should exist to close font resources.
> My basic code:
> {code}
> import java.io.File;
> import java.io.IOException;
> import java.lang.management.ManagementFactory;
> import org.apache.commons.io.output.ByteArrayOutputStream;
> import org.apache.pdfbox.pdmodel.PDDocument;
> import org.apache.pdfbox.pdmodel.PDPage;
> import org.apache.pdfbox.pdmodel.PDPageContentStream;
> import org.apache.pdfbox.pdmodel.common.PDRectangle;
> import org.apache.pdfbox.pdmodel.font.PDFont;
> import org.apache.pdfbox.pdmodel.font.PDType0Font;
> public class FontTest
> {
> // Run the program which will create 1 PDF document and close all resources per second for 100 seconds.
> // The font open file descriptor count will increase all the time, until the program finishes.
> // Command to check open files: lsof -p PID | grep ttf
> public static void main(String[] args)
> {
> // should print out PID before @<hostname>
> System.out.println("process id: " + ManagementFactory.getRuntimeMXBean().getName());
> for (int i = 0; i < 100; i++)
> {
> createPDF();
> try
> {
> Thread.sleep(1000);
> }
> catch (InterruptedException e)
> {
> e.printStackTrace();
> }
> }
> }
> private static void createPDF()
> {
> PDDocument doc = null;
> PDPage page = null;
> ByteArrayOutputStream bos = null;
> try
> {
> doc = new PDDocument();
> page = new PDPage(PDRectangle.A4);
> doc.addPage(page);
> // using standard font
> PDFont font = PDType0Font.load(doc, new File("./pdf/OpenSans-Regular.ttf"));
> PDPageContentStream content = new PDPageContentStream(doc, page);
> content.beginText();
> content.setFont(font, 72);
> content.showText("OMG");
> content.endText();
> content.close();
> bos = new ByteArrayOutputStream();
> doc.save(bos);
> byte[] bytes = bos.toByteArray();
> System.out.println("create new pdf with size: " + bytes.length);
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> finally
> {
> try
> {
> doc.close();
> bos.close();
> }
> catch (IOException e)
> {
> e.printStackTrace();
> }
> }
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org