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

infinite loop of searching for a key in PDResources

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.0
    • 2.0.0
    • PDModel

    Description

      error in code of class - org.apache.pdfbox.pdmodel.PDResources

          private COSName createKey(COSName kind, String prefix)
          {
              COSDictionary dict = (COSDictionary)resources.getDictionaryObject(kind);
              if (dict == null)
              {
                  return COSName.getPDFName(prefix + 1);
              }
      
              // find a unique key
              String key;
              do
              {
                  key = prefix + (dict.keySet().size() + 1);
              }
              while (dict.containsKey(key));    <--------------- infinite loop of searching for a key
              return COSName.getPDFName(key);
          }
      

      my test code:

      public class pdfmain_svg {
      
      	public static void main(String[] args) throws Exception {
      		System.out.println("hello");
      		PDDocument document = PDDocument.load(new File(
      				"d:\\Project\\pdfbox-image\\Acro6JSGuide.pdf"));
      
      		float fontSize = 10f;
      
      		PDFont font = PDType0Font.load(document, new File(
      				"c:\\Windows\\Fonts\\Arial.TTF"));
      
      		for (int pageIndex = 0; pageIndex < document.getNumberOfPages(); pageIndex++) {
      			System.out.println("page index = " + pageIndex);
      			PDPage page = document.getPage(pageIndex);  
      			PDPageContentStream contentStream = new PDPageContentStream(
      					document, page, true, true);
      			contentStream.setFont(font, fontSize); <---------------- hang on page 6
      			contentStream.setNonStrokingColor(Color.LIGHT_GRAY);
      			contentStream.beginText();
      			contentStream.newLineAtOffset(100, 100);
      			contentStream.showText("Test printing");
      			contentStream.endText();
      			contentStream.close();
      		}
      		File f = new File("d:\\work\\kostya.pdf");
      		document.save(f);
      		document.close();
      		System.out.println("f=" + f.getAbsolutePath() + ": " + f.exists());
      	}
      
      }
      
      

      Attachments

        1. Acro6JSGuide.pdf
          885 kB
          Konstantin Kakunin
        2. pdfmain_svg.java
          2 kB
          Konstantin Kakunin

        Issue Links

          Activity

            People

              tilman Tilman Hausherr
              kmwork Konstantin Kakunin
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: