Re: [iText-questions] Where can I get the current horizontal positionwithin ColumnText/PDFWriter?
Good morning! I applied and tested the patch this morning. It seems to work great, but only in text-mode. Unfortunately, we are doing everything in composite-mode, where the method getLastX() will always return 0.0. I also noticed that the method writeLineToContent(line, text, graphics, currentValues, ratio) in class PDFDocument is also called in PDFDocument.flushLines() and it loses the x-position there. Unfortunately, that method already has a return parameter. No easy fix, but maybe no problem? Kind regards, Peter Henningsen www.wcenter.de peter.henning...@wcenter.de wrote: Hi, Thanks. I will not look at this again before some time next week. I had a look at the methods you mentioned, and this stuff looks a lot more complicated than I thought. I could not quite make the connection from ColumnText to PdfLine. Anyway, I try again next week. The changes that were just uploaded to the SVN repository work with the simple test samples I made. Please check if the patch works for you. Log Message: --- ColumnText returns the last X position after a non-simulated go(). Modified Paths: -- trunk/src/core/com/itextpdf/text/pdf/ColumnText.java trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java trunk/src/core/com/itextpdf/text/pdf/PdfLine.java Modified: trunk/src/core/com/itextpdf/text/pdf/ColumnText.java === --- trunk/src/core/com/itextpdf/text/pdf/ColumnText.java 2010-04-25 09:50:40 UTC (rev 4490) +++ trunk/src/core/com/itextpdf/text/pdf/ColumnText.java 2010-04-25 11:04:50 UTC (rev 4491) @@ -179,6 +179,12 @@ /** The current y line location. Text will be written at this line minus the leading. */ protected float yLine; + +/** + * The X position after the last line that has been written. + * @since 5.0.3 + */ +protected float lastX; /** The leading for the current line. */ protected float currentLeading = 16; @@ -793,6 +799,7 @@ return NO_MORE_TEXT; descender = 0; linesWritten = 0; +lastX = 0; boolean dirty = false; float ratio = spaceCharRatio; Object currentValues[] = new Object[2]; @@ -894,7 +901,7 @@ if (!simulate) { currentValues[0] = currentFont; text.setTextMatrix(x1 + (line.isRTL() ? rightIndent : firstIndent) + line.indentLeft(), yLine); -pdf.writeLineToContent(line, text, graphics, currentValues, ratio); +lastX = pdf.writeLineToContent(line, text, graphics, currentValues, ratio); currentFont = (PdfFont)currentValues[0]; } lastWasNewline = line.isNewlineSplit(); @@ -987,6 +994,15 @@ public int getLinesWritten() { return this.linesWritten; } + +/** + * Gets the X position of the end of the last line that has been written + * (will not work in simulation mode!). + * @since 5.0.3 + */ +public float getLastX() { +return lastX; +} /** * Gets the arabic shaping options. Modified: trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java === --- trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java 2010-04-25 09:50:40 UTC (rev 4490) +++ trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java 2010-04-25 11:04:50 UTC (rev 4491) @@ -1252,8 +1252,9 @@ * @param currentValues the current font and extra spacing values * @param ratio * @throws DocumentException on error + * @since 5.0.3 returns a float instead of void */ -void writeLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object currentValues[], float ratio) throws DocumentException { +float writeLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object currentValues[], float ratio) throws DocumentException { PdfFont currentFont = (PdfFont)currentValues[0]; float lastBaseFactor = ((Float)currentValues[1]).floatValue(); PdfChunk chunk; @@ -1266,9 +1267,9 @@ float baseWordSpacing = 0; float baseCharacterSpacing = 0; float glueWidth = 0; - +float lastX = text.getXTLM() + line.getOriginalWidth(); numberOfSpaces = line.numberOfSpaces(); -lineLen = line.GetLineLengthUtf32(); +lineLen = line.getLineLengthUtf32(); // does the line need to be justified? isJustified = line.hasToBeJustified() (numberOfSpaces != 0 || lineLen 1); int separatorCount = line.getSeparatorCount(); @@ -1301,6 +1302,9 @@ lastBaseFactor = baseFactor; } } +else if (line.alignment == Element.ALIGN_LEFT) { +lastX -= line.widthLeft(); +} int
Re: [iText-questions] Where can I get the current horizontal positionwithin ColumnText/PDFWriter?
peter.henning...@wcenter.de wrote: Good morning! I applied and tested the patch this morning. It seems to work great, but only in text-mode. Unfortunately, we are doing everything in composite-mode, where the method getLastX() will always return 0.0. I also noticed that the method writeLineToContent(line, text, graphics, currentValues, ratio) in class PDFDocument is also called in PDFDocument.flushLines() and it loses the x-position there. Unfortunately, that method already has a return parameter. No easy fix, but maybe no problem? I have no idea what you're talking about, but this is a fix for composite mode: Modified Paths: -- trunk/src/core/com/itextpdf/text/pdf/ColumnText.java trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java Modified: trunk/src/core/com/itextpdf/text/pdf/ColumnText.java === --- trunk/src/core/com/itextpdf/text/pdf/ColumnText.java2010-04-28 14:27:05 UTC (rev 4495) +++ trunk/src/core/com/itextpdf/text/pdf/ColumnText.java2010-04-28 15:00:19 UTC (rev 4496) @@ -1189,6 +1189,7 @@ compositeColumn.maxY = maxY; boolean keepCandidate = para.getKeepTogether() createHere !firstPass; status = compositeColumn.go(simulate || keepCandidate keep == 0); +lastX = compositeColumn.getLastX(); updateFilledWidth(compositeColumn.filledWidth); if ((status NO_MORE_TEXT) == 0 keepCandidate) { compositeColumn = null; @@ -1285,6 +1286,7 @@ compositeColumn.maxY = maxY; boolean keepCandidate = item.getKeepTogether() createHere !firstPass; status = compositeColumn.go(simulate || keepCandidate keep == 0); +lastX = compositeColumn.getLastX(); updateFilledWidth(compositeColumn.filledWidth); if ((status NO_MORE_TEXT) == 0 keepCandidate) { compositeColumn = null; Modified: trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java === --- trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java 2010-04-28 14:27:05 UTC (rev 4495) +++ trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java 2010-04-28 15:00:19 UTC (rev 4496) @@ -1302,7 +1302,7 @@ lastBaseFactor = baseFactor; } } -else if (line.alignment == Element.ALIGN_LEFT) { +else if (line.alignment == Element.ALIGN_LEFT || line.alignment == Element.ALIGN_UNDEFINED) { lastX -= line.widthLeft(); } -- This answer is provided by 1T3XT BVBA http://www.1t3xt.com/ - http://www.1t3xt.info -- ___ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Re: [iText-questions] Where can I get the current horizontal positionwithin ColumnText/PDFWriter? - Works now!
Yep, that looks very good! Thanks a lot! Kind regards, Peter Henningsen peter.henning...@wcenter.de wrote: Good morning! I applied and tested the patch this morning. It seems to work great, but only in text-mode. Unfortunately, we are doing everything in composite-mode, where the method getLastX() will always return 0.0. I also noticed that the method writeLineToContent(line, text, graphics, currentValues, ratio) in class PDFDocument is also called in PDFDocument.flushLines() and it loses the x-position there. Unfortunately, that method already has a return parameter. No easy fix, but maybe no problem? I have no idea what you're talking about, but this is a fix for composite mode: Modified Paths: -- trunk/src/core/com/itextpdf/text/pdf/ColumnText.java trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java Modified: trunk/src/core/com/itextpdf/text/pdf/ColumnText.java === --- trunk/src/core/com/itextpdf/text/pdf/ColumnText.java 2010-04-28 14:27:05 UTC (rev 4495) +++ trunk/src/core/com/itextpdf/text/pdf/ColumnText.java 2010-04-28 15:00:19 UTC (rev 4496) @@ -1189,6 +1189,7 @@ compositeColumn.maxY = maxY; boolean keepCandidate = para.getKeepTogether() createHere !firstPass; status = compositeColumn.go(simulate || keepCandidate keep == 0); +lastX = compositeColumn.getLastX(); updateFilledWidth(compositeColumn.filledWidth); if ((status NO_MORE_TEXT) == 0 keepCandidate) { compositeColumn = null; @@ -1285,6 +1286,7 @@ compositeColumn.maxY = maxY; boolean keepCandidate = item.getKeepTogether() createHere !firstPass; status = compositeColumn.go(simulate || keepCandidate keep == 0); +lastX = compositeColumn.getLastX(); updateFilledWidth(compositeColumn.filledWidth); if ((status NO_MORE_TEXT) == 0 keepCandidate) { compositeColumn = null; Modified: trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java === --- trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java 2010-04-28 14:27:05 UTC (rev 4495) +++ trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java 2010-04-28 15:00:19 UTC (rev 4496) @@ -1302,7 +1302,7 @@ lastBaseFactor = baseFactor; } } -else if (line.alignment == Element.ALIGN_LEFT) { +else if (line.alignment == Element.ALIGN_LEFT || line.alignment == Element.ALIGN_UNDEFINED) { lastX -= line.widthLeft(); } -- This answer is provided by 1T3XT BVBA http://www.1t3xt.com/ - http://www.1t3xt.info -- ___ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/ testColumnTextImage.pdf Description: Binary data -- ___ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Re: [iText-questions] Where can I get the current horizontal positionwithin ColumnText/PDFWriter? - Works now!
peter.henning...@wcenter.de wrote: Yep, that looks very good! Thanks a lot! Thanks for the feedback. I have very little time for the moment, so I only did a very simple test (with only one example). Let me know if you experience any problems. -- This answer is provided by 1T3XT BVBA http://www.1t3xt.com/ - http://www.1t3xt.info -- ___ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Re: [iText-questions] Where can I get the current horizontal positionwithin ColumnText/PDFWriter?
peter.henning...@wcenter.de wrote: Hi, Thanks. I will not look at this again before some time next week. I had a look at the methods you mentioned, and this stuff looks a lot more complicated than I thought. I could not quite make the connection from ColumnText to PdfLine. Anyway, I try again next week. The changes that were just uploaded to the SVN repository work with the simple test samples I made. Please check if the patch works for you. Log Message: --- ColumnText returns the last X position after a non-simulated go(). Modified Paths: -- trunk/src/core/com/itextpdf/text/pdf/ColumnText.java trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java trunk/src/core/com/itextpdf/text/pdf/PdfLine.java Modified: trunk/src/core/com/itextpdf/text/pdf/ColumnText.java === --- trunk/src/core/com/itextpdf/text/pdf/ColumnText.java2010-04-25 09:50:40 UTC (rev 4490) +++ trunk/src/core/com/itextpdf/text/pdf/ColumnText.java2010-04-25 11:04:50 UTC (rev 4491) @@ -179,6 +179,12 @@ /** The current y line location. Text will be written at this line minus the leading. */ protected float yLine; + +/** + * The X position after the last line that has been written. + * @since 5.0.3 + */ +protected float lastX; /** The leading for the current line. */ protected float currentLeading = 16; @@ -793,6 +799,7 @@ return NO_MORE_TEXT; descender = 0; linesWritten = 0; +lastX = 0; boolean dirty = false; float ratio = spaceCharRatio; Object currentValues[] = new Object[2]; @@ -894,7 +901,7 @@ if (!simulate) { currentValues[0] = currentFont; text.setTextMatrix(x1 + (line.isRTL() ? rightIndent : firstIndent) + line.indentLeft(), yLine); -pdf.writeLineToContent(line, text, graphics, currentValues, ratio); +lastX = pdf.writeLineToContent(line, text, graphics, currentValues, ratio); currentFont = (PdfFont)currentValues[0]; } lastWasNewline = line.isNewlineSplit(); @@ -987,6 +994,15 @@ public int getLinesWritten() { return this.linesWritten; } + +/** + * Gets the X position of the end of the last line that has been written + * (will not work in simulation mode!). + * @since 5.0.3 + */ +public float getLastX() { + return lastX; +} /** * Gets the arabic shaping options. Modified: trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java === --- trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java 2010-04-25 09:50:40 UTC (rev 4490) +++ trunk/src/core/com/itextpdf/text/pdf/PdfDocument.java 2010-04-25 11:04:50 UTC (rev 4491) @@ -1252,8 +1252,9 @@ * @param currentValues the current font and extra spacing values * @param ratio * @throws DocumentException on error + * @since 5.0.3 returns a float instead of void */ -void writeLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object currentValues[], float ratio) throws DocumentException { +float writeLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object currentValues[], float ratio) throws DocumentException { PdfFont currentFont = (PdfFont)currentValues[0]; float lastBaseFactor = ((Float)currentValues[1]).floatValue(); PdfChunk chunk; @@ -1266,9 +1267,9 @@ float baseWordSpacing = 0; float baseCharacterSpacing = 0; float glueWidth = 0; - +float lastX = text.getXTLM() + line.getOriginalWidth(); numberOfSpaces = line.numberOfSpaces(); -lineLen = line.GetLineLengthUtf32(); +lineLen = line.getLineLengthUtf32(); // does the line need to be justified? isJustified = line.hasToBeJustified() (numberOfSpaces != 0 || lineLen 1); int separatorCount = line.getSeparatorCount(); @@ -1301,6 +1302,9 @@ lastBaseFactor = baseFactor; } } +else if (line.alignment == Element.ALIGN_LEFT) { + lastX -= line.widthLeft(); +} int lastChunkStroke = line.getLastStrokeChunk(); int chunkStrokeIdx = 0; @@ -1593,6 +1597,7 @@ text.moveText(baseXMarker - text.getXTLM(), 0); currentValues[0] = currentFont; currentValues[1] = new Float(lastBaseFactor); +return lastX; } protected Indentation indentation = new Indentation(); Modified: trunk/src/core/com/itextpdf/text/pdf/PdfLine.java === --- trunk/src/core/com/itextpdf/text/pdf/PdfLine.java 2010-04-25 09:50:40 UTC
Re: [iText-questions] Where can I get the current horizontal positionwithin ColumnText/PDFWriter?
Hi, Thanks. I will not look at this again before some time next week. I had a look at the methods you mentioned, and this stuff looks a lot more complicated than I thought. I could not quite make the connection from ColumnText to PdfLine. Anyway, I try again next week. Have a nice weekend! Peter Henningsen This answer is provided by 1T3XT BVBA http://www.1t3xt.com/ - http://www.1t3xt.info peter.henning...@wcenter.de wrote: I see two other options to implement the desired functionality: - put code into ColumnText.go() to generate an event whenever the column if full or the text ends. Then pass the current position in that event object - change ColumnText, so the current position can be obtained with getXPos() After reading the initial question, I interpreted it the same way as Paulo. Reading your follow-up, I see that generic tags probably won't help: you don't know in advance where the column will split. I've looked at the code very briefly (I'm sorry, I really don't have much time this week), but maybe the method writeLineToContent in PdfDocument should return an X value that can be captured by ColumnText. What you need is PdfLine.getLeft() + PdfLine.GetLineLengthUtf32() of the last line that is added. However, if there is glue in the line, or if the line is justified, the method writeLineToContent will add extra spacing. 1T3XT info i...@1t3xt.info 22.04.2010 18:48 Please respond to Post all your questions about iText here itext-questions@lists.sourceforge.net To Post all your questions about iText here itext-questions@lists.sourceforge.net cc Subject SPAM Re: [iText-questions] Where can I get the current horizontal positionwithin ColumnText/PDFWriter? peter.henning...@wcenter.de wrote: I see two other options to implement the desired functionality: - put code into ColumnText.go() to generate an event whenever the column if full or the text ends. Then pass the current position in that event object - change ColumnText, so the current position can be obtained with getXPos() After reading the initial question, I interpreted it the same way as Paulo. Reading your follow-up, I see that generic tags probably won't help: you don't know in advance where the column will split. I've looked at the code very briefly (I'm sorry, I really don't have much time this week), but maybe the method writeLineToContent in PdfDocument should return an X value that can be captured by ColumnText. What you need is PdfLine.getLeft() + PdfLine.GetLineLengthUtf32() of the last line that is added. However, if there is glue in the line, or if the line is justified, the method writeLineToContent will add extra spacing. Post a reply to the list if you don't have the time to look at this before Sunday. Maybe I'll find some time to work something out then, or you can share your experience if this (very premature) suggestion leads nowhere (in which case, I'll have to think of another way to achieve what you need). -- -- ___ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/ -- ___ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Re: [iText-questions] Where can I get the current horizontal positionwithin ColumnText/PDFWriter?
Hello Paulo, Thanks for the hint! I had a look at that functinality and checked, if ColumnText.go() supports any column-oriented events. In 2.1.7 I did not see anything. I do not see, how tagged chunks would help me, as I do not know beforehand at what word the end of the column will be reached? The required event is not content-related but rendering-related. Or did you mean - tag all chunks - build a handler, that is called whenever a chunk is processed - make that handler remember the latest position - use that position after go() returns to put the image into the right place ? Still, my chunks hold several words and the words will be hyphenated. So that does not sound precise enough. Also, the book states on page 126, Chp4.6.1 ... this event is not triggered immediately after the Chunk object is added to the document... I guess, the sequence of events is not garanteed too. I see two other options to implement the desired functionality: - put code into ColumnText.go() to generate an event whenever the column if full or the text ends. Then pass the current position in that event object - change ColumnText, so the current position can be obtained with getXPos() Any opinion on those? Kind regards, Peter --- Paulo Soares psoa...@glintt.com 22.04.2010 00:57 Please respond to Post all your questions about iText here itext-questions@lists.sourceforge.net To Post all your questions about iText here itext-questions@lists.sourceforge.net cc Subject SPAM Re: [iText-questions] Where can I get the current horizontal positionwithin ColumnText/PDFWriter? Use a generic tag event. Paulo - Original Message - From: peter.henning...@wcenter.de To: itext-questions@lists.sourceforge.net Sent: Wednesday, April 21, 2010 12:33 PM Subject: [iText-questions] Where can I get the current horizontal positionwithin ColumnText/PDFWriter? Hello, I have to position an image-icon precisely at the end of a text-column (when the ColumnText has more text). The text is left-aligned, so the position of the last glyph varies horizontally. I get the vertical position with ct.getYLine(). But I have not found a similar way to find the horizontal position. The writer also seems to have only the vertical position? Kind regards, Peter -- ___ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/ -- ___ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Re: [iText-questions] Where can I get the current horizontal positionwithin ColumnText/PDFWriter?
peter.henning...@wcenter.de wrote: I see two other options to implement the desired functionality: - put code into ColumnText.go() to generate an event whenever the column if full or the text ends. Then pass the current position in that event object - change ColumnText, so the current position can be obtained with getXPos() After reading the initial question, I interpreted it the same way as Paulo. Reading your follow-up, I see that generic tags probably won't help: you don't know in advance where the column will split. I've looked at the code very briefly (I'm sorry, I really don't have much time this week), but maybe the method writeLineToContent in PdfDocument should return an X value that can be captured by ColumnText. What you need is PdfLine.getLeft() + PdfLine.GetLineLengthUtf32() of the last line that is added. However, if there is glue in the line, or if the line is justified, the method writeLineToContent will add extra spacing. Post a reply to the list if you don't have the time to look at this before Sunday. Maybe I'll find some time to work something out then, or you can share your experience if this (very premature) suggestion leads nowhere (in which case, I'll have to think of another way to achieve what you need). -- This answer is provided by 1T3XT BVBA http://www.1t3xt.com/ - http://www.1t3xt.info -- ___ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Re: [iText-questions] Where can I get the current horizontal positionwithin ColumnText/PDFWriter?
Use a generic tag event. Paulo - Original Message - From: peter.henning...@wcenter.de To: itext-questions@lists.sourceforge.net Sent: Wednesday, April 21, 2010 12:33 PM Subject: [iText-questions] Where can I get the current horizontal positionwithin ColumnText/PDFWriter? Hello, I have to position an image-icon precisely at the end of a text-column (when the ColumnText has more text). The text is left-aligned, so the position of the last glyph varies horizontally. I get the vertical position with ct.getYLine(). But I have not found a similar way to find the horizontal position. The writer also seems to have only the vertical position? Kind regards, Peter -- ___ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/