[
https://issues.apache.org/jira/browse/PDFBOX-854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12970777#action_12970777
]
MH edited comment on PDFBOX-854 at 12/13/10 7:25 AM:
-----------------------------------------------------
Tested with latest snapshots (pdfbox-1.4.0-20101211.181302-26.jar,
fontbox-1.4.0-20101211.181302-27.jar, jempbox-1.4.0-20101211.181302-27.jar),
ensured to recompile everything (log shows new PDFBox version number) but text
"jumped" all over the place. I had to do translations of my "original" x/y
coordinates myself that I expected PDFBox is doing for me:
------------------------------------------------------------------------------
cs.beginText();
cs.setFont(font, sizeOfFont);
final int rotation = page.findRotation();
final PDRectangle pageSize = page.findMediaBox();
final float tf = xf; //temporary save xf value
switch (rotation) {
case 90 :
xf = pageSize.getWidth() - yf;
yf = tf;
cs.setTextRotation(Math.PI/2.0, xf, yf); //rotate text 90° counterclockwise
break;
case 180 : //NOT tested!
xf = -xf;
yf = pageSize.getHeight() - yf;
cs.setTextTranslation(xf, yf); //move to x/y position without text rotation
break;
case 270 : //NOT tested!
xf = -pageSize.getWidth() + yf;
yf = -tf;
cs.setTextRotation(Math.PI/2.0, xf, yf); //rotate text 90° counterclockwise
break;
case 0 :
case 360 : //NOT tested!
default:
cs.setTextTranslation(xf, yf); //move to x/y position without text rotation
break;
}
//cs.moveTextPositionByAmount(xf, yf);
cs.drawString(text);
-------------------------------------------------------------------------
was (Author: mhilpert):
Can't get it to work: I downloaded the latest snapshots
(pdfbox-1.4.0-20101211.181302-26.jar, fontbox-1.4.0-20101211.181302-27.jar,
jempbox-1.4.0-20101211.181302-27.jar), ensured to recompile everything (log
shows new PDFBox version number) text now "jumps" all over the place. I have no
idea what that means:
92 if (rotate)
93 {
94 // rotate the text according to the page rotation
95 contentStream.setTextRotation(Math.PI/2, centeredXPosition,
centeredYPosition);
96 }
97 else
98 {
99 contentStream.setTextTranslation(centeredXPosition, centeredYPosition);
100 }
Why is ther an if/else? What does setTextTranslation do? And what is the
additional parameter in the PDPageContentStream constructor?
> 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.1
> Environment: JDK 1.6.0_21
> Reporter: MH
> Assignee: Andreas Lehmkühler
> Fix For: 1.4.0
>
> Attachments: Text_Added_With_iText.zip,
> Website_A4_Landscape_PDF14.zip, Website_A4_Landscape_PDF14_addedText.pdf
>
>
> 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.