Use setKeepWithNext in IText7.0.2 - java

I need to keep more than one paragraph in the same area. See the image, I want title "Proposal Summary Report", solid line, and next paragraph in the same area. When I used the method setKeepWithNext, it just keep two paragraph in the same area. How can I do it?

You could check the remaining space available on the page, and compare that to the height of the elements you want to render. If there is not enough room to have all of these elements on the same page, insert a new page and then insert the elements.
The wonderful thing about this approach is that it becomes very modular. You can create a virtual element used solely for grouping elements together that imbues this logic. Then, whenever you want elements held together, use this container-element to ensure the logic.

Related

iText - add Table at the end of last page IF Space available

I am using iText 2.1.7
I write a pdf document for which the page size and contant can differ each time. What i want to achieve is a table at the very last page and at the bottom of that page. I am aware of the method 'writeSelectedRows', but with this it could happen that i overwrite text on the page, because i dont know if there is space for my table.
So in conclusion:
If i have reached the last page i want to add my table at the bottom of the page. But if the table does not fit, i want a new page and on this page i want to add the table at the bottom.
I could not find a solution so far.
Use this http://developers.itextpdf.com/de/node/1910 to calculate the height of a table and then check the available space on a page with PdfWriter.GetVerticalPostition(). You might want to consider your Document.BottomMargin or some other offset in your space calculation. (v4.1.6)
Check out this link:
http://developers.itextpdf.com/content/best-itext-questions-stackoverview/general-questions-about-itext/itext7-how-find-out-current-cursor-position-page
I suppose that once you know the current cursor position on this page, you can write a simple if-statement to add a new page, or not.
Kind regards,
Joris

Avoid carriage return in paragraph with doxc4j

I think that paragraph elements by definition creates a new line but I need to insert elements as the first element of a page not moving down existing elements.
Is there another element I can use instead of paragraph? I think that only tables and paragraphs are available and I understand that tables contains paragraphs so they don't work for my purpose.
Or maybe exists any property I can set to avoid the new paragraph moving the other elements?
I tried keepNext and keepLines but is not what I'm looking for.
You can absolutely position an ellipse, without it being in the first paragraph on the page.
In Word, on your ellipse, right click and choose "More layout options". On the position tab, eg 1" below page.
This creates something like:
<w:r>
<w:pict>
<v:oval strokecolor="#243f60 [1604]" strokeweight="2pt"
style="position:absolute;margin-left:41.25pt;margin-top:1in;
width:207.35pt;height:1in;z-index:251659264;visibility:visible;mso-wrap-style:square;mso-width-percent:0;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:absolute;mso-position-horizontal-relative:text;mso-position-vertical:absolute;mso-position-vertical-relative:page;mso-width-percent:0;mso-width-relative:margin;v-text-anchor:middle" id="Oval 1" o:spid="_x0000_s1026">
<w10:wrap anchory="page"/>
</v:oval>
</w:pict>
</w:r>
If for some reason you want to add a new first paragraph, you could make the paragraph have a small font, with no space before or after. r:Pr/r:vanish causes the ellipse to vanish, so don't try that!

Make Label Displayed Inside a Vertex Box (jgraphx library)

I need my vertex label displayed entirely inside vertex bounds. I mean if my label is too long then part of it will be displayed outside the vertex box. Is there any way to automatically split label into multiple lines and make it fit the vertex bounds? This line breaks should be recalculated after vertex resize. Can i do it using styles? mxUtils.wordWrap() seems to be the way but i cannot figure out how to use it properly. Give me an example of using it please. Thanks for your answers
Another similar question: Calculate the display width of a string in Java
Abstract:
Graphics.getFontMetrics + FontMetrics.stringWidth
From this, I suppose you could create a List<String> and add the words of the text one at a time until you reach your max length, then add a new node to the list for the overflow. Finally, append each node in the List to each other with a line break in between.
On another note, from what research I did, it seems jGraphX runs on swing. Swing now supports HTML. Here's a link to further info: http://docs.oracle.com/javase/tutorial/uiswing/components/html.html.
I will see if I can get a quick test coded up, but that must wait until I get home.

How to make detail section undivided in JasperReport

How can i be ensured that every detail section won't be separated in diffenent pages?
If two detail sections aren't able to fit into one page without second devision into two parts, then they must be set into two pages. I don't want the second detail section been divided.
thank you
Are you using iReport? If so, simply click the detail node in the outline window (that tree structure on the left of the screen) to bring up the properties for that band. The properties window will appear on the right side of the screen. Where it says Split Type, select "Prevent" from the drop down menu. If you are coding your report in jrxml, when you get to the <detail> tag, in its first child tag, <band> set the attribute splitType="Prevent".
I am not sure that this is a better way of doing it but you can do it by checking the sum of the sizes divisions being greater than or less than the total size total size of page. If it is less than the size of the page you don't need to do anything but if it is greater you can simply take out the last division and put it on the other page. There would be some way of pagination in JasperReport, try googling it. Hope it works for you.

JList strike through

I have a list of data in a JList component in my GUI.
I would like to know if there is a method that i can call on the list element(s) to strike through a particular element in the list. I would like to draw a line through the element to appear as if that element is canceled.
I want a similar thing like the strike through functionality in Microsoft Word document whereby a line i drawn through the text.
thanks for your help
You can apply html formating to each element of a list. Therefore if you know what element you want struck through you can modify the string held by that element as such:
<html><strike>this text will be struck through</strike></html>
Edit: I should note that I haven't tested this so if the strike tag isn't supported in Java try just s. One of those should work
JIDE Common Layer has a StyledListCellRenderer that can be used to provide this functionality.

Categories