Paragraph starting positioning itext - itext

I am using IText library. I am using Paragraph in it cause the text is running and may be larger then one page. My problem is that I have to give paragraph starting positioning and I am unable to see any method regarding positioning it. Any help?
Something like that
page 2 is new page.... And this is whole one paragraph. I have starting coordinate of paragraph.

As explained in the comment section, you need ColumnText to achieve what you want. See for instance the MovieColumns1 example. You add text to a ColumnText instance with the addText() method. Then you set some parameters, such as the coordinates of the rectangle defining the absolute positions. This is done with the setSimpleColumn() method. To draw the text, you invoke the go() method. If the text didn't fit in the rectangle, ColumnText.hasMoreText(status) will return true, in which case, you trigger newPage(), define a new rectangle, change the Y position, and go() again as long as the column contains content.
All of this is explained in the documentation of which I'm the author. Reading the documentation saves time: your time as well as the time of the people on StackOverflow.

You could try searching for the first occurrence of a line break or carriage return, ie: Chr(13) and Chr(20).

Related

Placing cursor in the document for a given position using PyUNO

I am having Libreoffice7 installed with custom python 3.8.6 in Windows.
I want to use PyUNO to navigate the view cursor to a specific position based on the X, Y coordinates(of instance com.sun.star.awt.Point) in a writer document.
Is there a way by which this can be achieved? I am unable to find any resource or documentation that helps.
Please let me know if any other info or clarifications needed.
Thank you in advance.
Precise positioning using points and pixels is difficult or impossible with the UNO API. The numbers seem to be unpredictable, for example https://ask.libreoffice.org/t/what-is-the-base-for-cursor-x-position-in-basic/71827.
Instead, move the cursor to a character or paragraph or object, for example with goRight().
To investigate point positioning further, take a look at this discussion on positioning a dialog in Calc: https://ask.libreoffice.org/t/dynamically-position-a-dialog/67289/39

SetFixedPosition of Parapgraph or Image results in wrong display order

With itext7 in VB.NET i create a PDF.
There I have this code-snippet:
Dim img As New Image(ImageDataFactory.Create(imagePath))
img.SetWidth(varImgWidth)
img.SetHeight(varImgHeight)
img.SetFixedPosition(100,100)
doc.add(img)
doc.add(new Paragraph("This is a test"))
The set position of the image overlaps with the text of the parapgraph. I expected, that the image is set to the document at the given position and then - afterwards - the text is "printed" above the image, because it is defined "after" the image in the code.
But what I see is, that the image positioned with SetFiexedPosition is always above other elements. I get the behaviour when positioning a text via SetFixedPosition on the Paragraph containing the text.
My question is: Is there any possibility to tell the element which is positioned, that it should be behind other elements.
Or - better question - is there any "positioning possibility" which allows a positioning of an element and considering the "order" in which it is "printed" in the code.
Do you understand what I mean?
(Sorry, it´s not easy for me to express it in English)
Thank you for any help
Regards
Benjamin

stretch a textField to a max height in jasper reports

I think this is more of a general issue. I would like to use a textfield that gets dynamic data and doesn't stretch more than a given max height. For instance, I have a textfield that, if it gets text that fits in one line, the textfield will be one line height, and i have other elements under it, that will move up with float positioning. Or, if I want a 3 line max height and if the text exceeds that space, then the rest will be trimmed.
I don't want to use java expressions to trim that text, as it is not always accurate. I am new to jasper and I am trying to know if there is any way to do this. I did a lot of searches, but maybe there is something that i missed, and i hope someone can help me. Thank you
I managed to solve this by extending net.sf.jasperreports.engine.fill.TextMeasurer and overriding initialize() method; also I had to extend net.sf.jasperreports.engine.util.AbstractTextMeasurerFactory and override the createMeasurer() method.
Now, whenever I want to have max # of lines, with no overflow, I add a property to that text field (e.g. maxLines) which is being passed to my custom TextMeasurerFactory. I hope this helped you.
We had a similar problem at work with JASPER Reports 4.5, where we had an invoice with a header and a table. We wanted the header to have dynamic height based on the lengths of certain fields (like address, partner name, etc,), but not more than a critical limit, otherwise the header will push the table and thus making a mess by splitting it across multiple pages. Also, the invoice shouldn't exceed 1 page.
We eventually had to move the header in the background section, where we also put a background for the table consisting of vertical lines (so it will extend to the end of an A4 page) and a white opaque square.
This way, if the header exceeds the max height it will go underneath the table's background, cropping the text. This was the desired effect we were looking for.
Sounds crazy, but it worked ...

Text not fitting into form fields (iTextSharp)

I created a .PDF file using Adobe Acrobat Pro. The file has several text fields. Using iTextSharp, I'm able to populate all the fields and mail out the .PDF.
One thing is bugging me - some of the next will not "fit" in the textbox. In Adobe, if I type more that the allocated height, the scroll bar kicks in - this happens when font size is NOT set to auto and multi-line is allowed.
However, when I attempt to set the following properties:
//qSize is float and set to 15;
//auto size of font is not being set here.
pdfFormFields.SetFieldProperty("notification_desc", "textsize", qSize, null);
// set multiline
pdfFormFields.SetFieldProperty("notification_desc", "setfflags", PdfFormField.FF_MULTILINE, null);
//fill the field
pdfFormFields.SetField("notification_desc", complaintinfo.OWNER_DESC);
However upon compilation and after stamping, the scroll bar does not appear in the final .PDF.
I'm not sure if this is the right thing to do. I'm thinking that perhaps I should create a table and flood it with the the text but the documentation makes little or no reference to scroll bars....
When you flatten a document, you remove all interactivity. Expecting working scroll bars on a flattened form, is similar to expecting working scroll bars on printed paper. That's why you don't get a lot of response to your question: it's kind of absurd.
When you fill out a rectangle with text, all text that doesn't fit will be omitted. That's why some people set the font size to 0. In this case, the font size will be adapted to make the text fit. I don't know if that's an option for you as you clearly state that the font size must be 15 pt.
If you can't change the font size, you shouldn't expect the AcroForm form field to adapt itself to the content. ISO-32000-1 is clear about that: the coordinates of a text field are fixed.
Your only alternative is to take control over how iText should fill the field. I made an example showing how to do this in the context of my book: MovieAds.java/MovieAds.cs. In this example, I ask the field for its coordinates:
AcroFields.FieldPosition f = form.GetFieldPositions(TEXT)[0];
This object gives you the page number f.page and a Rectangle f.position. You can use these variables in combination with ColumnText to add the content exactly the way you want to (and to check if all content has been added).
I hope you understand that:
it's only normal that there are no scroll bars on a flattened form,
the standard way of filling out fields clips content that doesn't fit,
you need to do more programming if you want a custom result.
For more info: please consult "iText in Action - Second Edition".

PPTX - Finding out whether text is bulleted from OpenXML

I have not been able to find any indicator which could tell me whether text in txBody tag is bulleted or not, can you please me in identifying which indicator should I use to understand whether the text is bulleted or plain ?
-Thank you
Inside the txBody tag, you can look for the tags "a:buFont" and "buChar" which helps you identify that the text is bulleted. eg.
<a:buFont typeface="Arial" pitchFamily="34" charset="0"/>
<a:buChar char="•"/>
Update:
Hi, +1 For posting this question, learnt a lot from it.
After googling I found this link which addresses similar issue, the resoponse from Adamm clears this,
"Ok, so i think ive got this figured out. Basically if no formatting
is specified in the layout or the slide, it goes to the master, and if
its a 'title' or 'ctrTitle' shape it uses the formatting in
and it defaults to lvl1. Same goes for text that is not
in a title shape, for these it defaults to the formatting in
and if no lvl is specified it defaults to lvl1. And
another piece of advice, although not pertinent to my original
question, there is another txStyle in the slideMaster,
which is used for text in a shape that is not in a txBody."
Now the slide in your pptx is using "Office Theme" and the text you are interested in is in the format shape within the slide design. The bulletted text is inheriting from the slideMaster1.xml in SlideMasters.
As mentioned in the above quote the buletted text is getting inherited from "a:lvl1pPr" of "p:bodyStyle" in the slideMaster1.xml, also you can see the level 2 bullet is defaulted to "-" for the office Theme slide master there.
I tried to confirm this by changing the char = "•" to ">" to see the bulleting changed to ">" in the below line
<p:bodyStyle>
<a:lvl1pPr marL="342900" indent="-342900" algn="l" defTabSz="914400" rtl="0" eaLnBrk="1" latinLnBrk="0" hangingPunct="1">
<a:spcBef>
<a:spcPct val="20000"/>
</a:spcBef>
<a:buFont typeface="Arial" pitchFamily="34" charset="0"/>
<a:buChar char="•"/>
....
Now if you want to change it programatically you can do this from slide master 1. But the only problem here is When we change the bulletted style here(like above), it is changing for all the slides and also for the future slides you will be creating with the same theme within your ppt.
Hope this helps.
Regards.