You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "MH (JIRA)" <ji...@apache.org> on 2010/10/06 15:45:31 UTC

[jira] Created: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

PDPageContentStream.drawString() doesn't work with all PDFs
-----------------------------------------------------------

                 Key: PDFBOX-854
                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
             Project: PDFBox
          Issue Type: Bug
          Components: PDModel
    Affects Versions: 1.3.0
         Environment: JDK 1.6.0_21
            Reporter: MH


I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:

----------------------------------
                            final PDPage page = (PDPage) allPages.get(i);
                            final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
                            contentStream.beginText();
                            contentStream.setFont(font, sizeOfFont);
                            contentStream.moveTextPositionByAmount(xf, yf);
                            contentStream.drawString(text);
                            contentStream.endText();
                            contentStream.close();
---------------------------------

I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "MH (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12919003#action_12919003 ] 

MH edited comment on PDFBOX-854 at 10/7/10 2:24 PM:
----------------------------------------------------

The text consists of numbers/digits, spaces and '-' signs. The font doesn't matter as the same behaviour is for arbitrary fonts. Yes I saved the PDF of course, otherwise I wouldn't see the result. This is not a "first implementation" bug, as adding this text was formelry done with iText 2.1.7. Then I change the implementation to use PDFBox and it worked without errors as expected, i.e. the text is written as expected. This works for self-generated PDFs via Apache FOP that are postprocessed with PDFBox (contatenation, properties setting). The last step is adding text to a document. And now I have some external PDFs like I posted as an attachement (generated via Windows print to PDF printer that generates the PDF with Ghostscript). And the very same code that writes the text to all other PDF pages, fails with this PDF - with "fails", I mean: the resulting PDF does not show the text added. I debugged my method to see if there is some swallowed exception, but the debugger steps as expected through each line as with all other PDFs, with same page size, same fonts, same x/y location of the text, even same text content, for not encrypted PDFs. So, no error, no exception, but the resulting PDF does not have/show the added text. 

      was (Author: mhilpert):
    The text consists of numbers/digits, spaces and '-' signs. The font doesn't matter as the same behaviour is for arbitrary fonts. Yes I saved the PDF of course, otherwise I wouldn't see the result. This is not a "first implementation" bug, as adding this text was formelry done with iText 2.1.7. Then I change the implementation to use PDFBox and it worked without errors as expected, i.e. the text is written as expected. This works for self-generated PDFs via Apache FOP that are postprocessed with PDFBox (contatenation, properties setting). The last step is adding text to a document. And now I have some external PDFs like I posted as an attachement (generated via Windows print to PDF printer that generates the PDF with Ghostscript). And the very same code that writes the text to all other PDF pages, fails with this PDF. I debugged my method to see if there is some swallowed exception, but the debugger steps as expected through each line as with all other PDFs, with same page size, same fonts, same x/y locations, even same texts for not encrypted PDFs. So, no error, no exception, but the resulting PDF does not have the added text. 
  
> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "MH (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12919201#action_12919201 ] 

MH edited comment on PDFBOX-854 at 10/8/10 5:20 AM:
----------------------------------------------------

Okay, the text is e.g. "23 - 35". Your questions about the used font are interesting: for the PDFs that "work", they are generated with the same fonts as the font used for the additional text, i.e. the font is also embedded in the PDF. For the external PDF, this must not necessarily be true! 

Just to repeat: if I exchange my method with the iText implementation, the text is written with the same parameters (PDF, Text, Font, etc.) => it's something within PDFBox.

I debugged my code again: I can't see any differences in the PDFBox calls. The font is also loaded. I use:

font = PDTrueTypeFont.loadTTF(doc, nameOfFont);

and the javadoc for this method says:

"This will load a TTF font from a font file.

doc The PDF document that will hold the embedded font.
file The file on the filesystem that holds the font file."

So it loads a font from the file system and embeds it in the destination document => the font has not to be embedded in the destination PDF as it is loaded from the file system and will be embedded in the destination doc.

Perhaps you will see the difference bettwer when you try to add text with a different font than any of the PDF fonts. (As this seems to be the problem.)

      was (Author: mhilpert):
    Okay, the text is e.g. "23 - 35". Your questions about the used font are interesting: for the PDFs that "work", they are generated with the same fonts as the font used for the additional text, i.e. the font is also embedded in the PDF. For the external PDF, this must not necessarily be true! 

Just to repeat: if I exchange my method with the iText implementation, the text is written with the same parameters (PDF, Text, Font, etc.) => it's something within PDFBox.
  
> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "MH (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12918900#action_12918900 ] 

MH edited comment on PDFBOX-854 at 10/7/10 10:26 AM:
-----------------------------------------------------

Example PDF to demonstrate this effect. The website is in A4 as other test PDFs are also A4 and the added text is always printed at the same x/y location. I also upgraded GhostScript to 8.64 and configured to output in PDF-1.4. But this didn't help: the text is still not displayed and no error occurs.

      was (Author: mhilpert):
    Example PDF to demonstrate this effect. The website is in A4 as other test PDFs are also A4 and the added text is always printed at the same x/y location.
  
> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "Andreas Lehmkühler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12918942#action_12918942 ] 

Andreas Lehmkühler commented on PDFBOX-854:
-------------------------------------------

What text did you add to the pdf? What font did you use? Did you save the pdf?

> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "Andreas Lehmkühler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12921271#action_12921271 ] 

Andreas Lehmkühler commented on PDFBOX-854:
-------------------------------------------

The problem is the current transformation matrix (ctm). It is defined for every page and can't be reset to an user-defined value. Every change to it will be done by concatenating a new ctm to it (see cm-operator for further details). The matrix maps positions from user coordinates to device coordinates. In your case it is among other things used to create a landscape pdf. PDFBox provides a sample on how to create landscpae pdfs [1].
I don't know any way to get the ctm without parsing the contentstream before adding further content. Can you attach a iText example pdf? Probably we can learn from that how to compensate a ctm.


[1] http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateLandscapePDF.java?view=markup

> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "MH (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12919269#action_12919269 ] 

MH commented on PDFBOX-854:
---------------------------

I searched for some bug reports concerning coordinates and found e.g. PDFBOX-828 from 30.09.2010. So I reveretd pdfbox/fontbox/jempbox back to the 1.2.1 release but the same problem exists there. I also browsed the PDFBox API to somehow read the coordinate system, also inspected PDPage.getRotation() which returned null or 90 and wasn't related to the "good" and "bad" PDFs.

Is there a way to get the coordinate's system "orientation", so we can at least work around this by transforming x,y location and text rotation?

> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "Andreas Lehmkühler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12919050#action_12919050 ] 

Andreas Lehmkühler commented on PDFBOX-854:
-------------------------------------------

Can you be more specific about the text? I'd like to search for some hints in the resulting pdf and without knowing the exact string that would be difficult. I'd also like to know some details about the used font. Do you use an external font? Is the font embedded into the pdf? Do you try to use a font from the original pdf?


> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "MH (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12919254#action_12919254 ] 

MH commented on PDFBOX-854:
---------------------------

Ha! It's not the font! It's the coordinates! added some "debug" code:

-----------------------
                                contentStream.beginText();
                                contentStream.setStrokingColor(java.awt.Color.red); //test
                                contentStream.setNonStrokingColor(java.awt.Color.blue); //test: text (foreground) color
                                contentStream.drawLine(0.0f, 0.0f, 100.0f, 200.0f); //test
                                contentStream.setFont(font, sizeOfFont);
                                
                                contentStream.moveTextPositionByAmount(xf, yf);
                                contentStream.drawString(text);
                                
                                contentStream.moveTextPositionByAmount(-xf, -yf); //test
                                contentStream.drawString(text+" ***"); //test
                                
                                contentStream.endText();
------------------------

And here's the result:

The "missing" text is probably not missing but drawn at the wrong place! First I added the colors, then the line. For the PDFs with the "visible" (correct) text, the line draws from the bottom left corner upwards+right. For the PDFs with the "missing" text, the line draws from the TOP left corner downwards+right!!! 

Then I added "text+***" and this text also got drawn on the problematic PDFS: for the "good" PDFS, the additional text is written horizontally at the bottom left corner. For the "bad" PDFs, the text is written VERTICALLY starting from the TOP left corner!

=> somehow the coordinates (system) is different in the problematic PDFs!


> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "MH (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12919003#action_12919003 ] 

MH edited comment on PDFBOX-854 at 10/7/10 2:25 PM:
----------------------------------------------------

The text consists of numbers/digits, spaces and '-' signs. The font doesn't matter as the same behaviour is for arbitrary fonts. Yes I saved the PDF of course, otherwise I wouldn't see the result. This is not a "first implementation" bug, as adding this text was formelry done with iText 2.1.7. Then I change the implementation to use PDFBox and it worked without errors as expected, i.e. the text is written as expected. This works for self-generated PDFs via Apache FOP that are postprocessed with PDFBox (contatenation, properties setting). The last step is adding text to a document. And now I have some external PDFs like I posted as an attachement (generated via Windows print to PDF printer that generates the PDF with Ghostscript). And the very same code that writes the text to all other PDF pages, fails with this PDF - with "fails", I mean: the resulting PDF does not show the text added. I debugged my method to see if there is some swallowed exception, but the debugger steps as expected through each line as with all other PDFs, with same page size, same fonts, same x/y location of the text, even same text content, for not encrypted PDFs. So, no error, no exception, but the resulting PDF does not have/show the added text. I also tried the latest 1.3.0-snapshot of PDFBox, but without any progress.

      was (Author: mhilpert):
    The text consists of numbers/digits, spaces and '-' signs. The font doesn't matter as the same behaviour is for arbitrary fonts. Yes I saved the PDF of course, otherwise I wouldn't see the result. This is not a "first implementation" bug, as adding this text was formelry done with iText 2.1.7. Then I change the implementation to use PDFBox and it worked without errors as expected, i.e. the text is written as expected. This works for self-generated PDFs via Apache FOP that are postprocessed with PDFBox (contatenation, properties setting). The last step is adding text to a document. And now I have some external PDFs like I posted as an attachement (generated via Windows print to PDF printer that generates the PDF with Ghostscript). And the very same code that writes the text to all other PDF pages, fails with this PDF - with "fails", I mean: the resulting PDF does not show the text added. I debugged my method to see if there is some swallowed exception, but the debugger steps as expected through each line as with all other PDFs, with same page size, same fonts, same x/y location of the text, even same text content, for not encrypted PDFs. So, no error, no exception, but the resulting PDF does not have/show the added text. 
  
> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "MH (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

MH updated PDFBOX-854:
----------------------

    Attachment: Text_Added_With_iText.zip

Example of text addition with iText 2.1.7. The text added is "1 - 1" at the lower right corner of the landscape page. The same text added with iText on the same source PDF is added somwehere else outside the A4 visibility.

> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Text_Added_With_iText.zip, Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "MH (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12922072#action_12922072 ] 

MH edited comment on PDFBOX-854 at 10/18/10 9:49 AM:
-----------------------------------------------------

Example of text addition with iText 2.1.7. The text added is "1 - 1" at the lower right corner of the landscape page. The same text added with PDFBox on the same source PDF is added somwehere else outside the A4 visibility.

      was (Author: mhilpert):
    Example of text addition with iText 2.1.7. The text added is "1 - 1" at the lower right corner of the landscape page. The same text added with iText on the same source PDF is added somwehere else outside the A4 visibility.
  
> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Text_Added_With_iText.zip, Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "MH (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12919201#action_12919201 ] 

MH commented on PDFBOX-854:
---------------------------

Okay, the text is e.g. "23 - 35". Your questions about the used font are interesting: for the PDFs that "work", they are generated with the same fonts as the font used for the additional text, i.e. the font is also embedded in the PDF. For the external PDF, this must not necessarily be true! 

Just to repeat: if I exchange my method with the iText implementation, the text is written with the same parameters (PDF, Text, Font, etc.) => it's something within PDFBox.

> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "MH (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

MH updated PDFBOX-854:
----------------------

    Attachment: Website_A4_Landscape_PDF14.zip

Example PDF to demonstrate this effect. The website is in A4 as other test PDFs are also A4 and the added text is always printed at the same x/y location.

> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "Andreas Lehmkühler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12922629#action_12922629 ] 

Andreas Lehmkühler commented on PDFBOX-854:
-------------------------------------------

Gotcha!! Instead of just adding a new stream iText first inserts a new stream at the beginning. This stream only contains a "q"-command to save the initial graphics state. After that the original stream is added. Finally a third stream is created, which starts with a "Q-command" to restore the initial graphics state without any modifications especially no changes to the ctm. That's quite smart. I'll improve the PDPageStreamContent constructor to copy that behaviour.

> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Text_Added_With_iText.zip, Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "MH (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12919209#action_12919209 ] 

MH commented on PDFBOX-854:
---------------------------

I tried to trick PDFBox: I called my method 2 times in hope that the first call will embed the font and the second call would be sure that the used font is embedded in the PDF. Here's the result:

1. it didn't help, i.e. the text is still not display. => it seems that the problem is not, that the used font for the additional text is not already embedded in the destination PDF.

2. after the first call, the font is embedded in the destination PDF. The second call loads this PDF and will embed the font A SECOND TIME in the result PDF! So the result PDF after the second call shows 2 times the same font as embedded (viewed with Acrobat Reader). Then I checked all my PDFs (concatenated and postprocessed with PDFBox) and noticed that after each postprocessing status, the fonts get duplicated again and again! => another bug?

> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-854) PDPageContentStream.drawString() doesn't work with all PDFs

Posted by "MH (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12919003#action_12919003 ] 

MH commented on PDFBOX-854:
---------------------------

The text consists of numbers/digits, spaces and '-' signs. The font doesn't matter as the same behaviour is for arbitrary fonts. Yes I saved the PDF of course, otherwise I wouldn't see the result. This is not a "first implementation" bug, as adding this text was formelry done with iText 2.1.7. Then I change the implementation to use PDFBox and it worked without errors as expected, i.e. the text is written as expected. This works for self-generated PDFs via Apache FOP that are postprocessed with PDFBox (contatenation, properties setting). The last step is adding text to a document. And now I have some external PDFs like I posted as an attachement (generated via Windows print to PDF printer that generates the PDF with Ghostscript). And the very same code that writes the text to all other PDF pages, fails with this PDF. I debugged my method to see if there is some swallowed exception, but the debugger steps as expected through each line as with all other PDFs, with same page size, same fonts, same x/y locations, even same texts for not encrypted PDFs. So, no error, no exception, but the resulting PDF does not have the added text. 

> PDPageContentStream.drawString() doesn't work with all PDFs
> -----------------------------------------------------------
>
>                 Key: PDFBOX-854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-854
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.3.0
>         Environment: JDK 1.6.0_21
>            Reporter: MH
>         Attachments: Website_A4_Landscape_PDF14.zip
>
>
> I add custom text to misc exsiting PDF files. Now I wondered why my text doesn't appear for a specific PDF. It is not encrypted, has the same page size and adding Text with iText 2.1.7 works as expected. My code to add text is:
> ----------------------------------
>                             final PDPage page = (PDPage) allPages.get(i);
>                             final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
>                             contentStream.beginText();
>                             contentStream.setFont(font, sizeOfFont);
>                             contentStream.moveTextPositionByAmount(xf, yf);
>                             contentStream.drawString(text);
>                             contentStream.endText();
>                             contentStream.close();
> ---------------------------------
> I tried to find differences between this PDF and other PDFs. What I noticed: the PDF where I can't see the text has a PDF-Version "1.3" and was created by "AFPL Ghostscript 8.54". Is there some known issue with PDFBox and such "older" PDF formats?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.