Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-4823

After calling pdfont.encode, the font file is not closed

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Bug
    • 2.0.12
    • None
    • None
    • None

    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.

      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;
               }
           }
      

      Attachments

        1. webdings.ttf
          119 kB
          bai yuan

        Issue Links

          Activity

            People

              Unassigned Unassigned
              berylbai bai yuan
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: