[ 
https://issues.apache.org/jira/browse/PDFBOX-2822?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Konstantin Kakunin updated PDFBOX-2822:
---------------------------------------
    Description: 
error in code of class - org.apache.pdfbox.pdmodel.PDResources
{code}
    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);
    }
{code}
my test code:
{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());
        }

}

{code}

  was:
error in code of class - org.apache.pdfbox.pdmodel.PDResources
{code}
    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:
{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());
        }

}

{code}


> infinite loop of searching for a key in PDResources
> ---------------------------------------------------
>
>                 Key: PDFBOX-2822
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2822
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 2.0.0
>            Reporter: Konstantin Kakunin
>
> error in code of class - org.apache.pdfbox.pdmodel.PDResources
> {code}
>     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);
>     }
> {code}
> my test code:
> {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());
>       }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to