Currently, I am using
document.add( Chunk.NEWLINE );
after each paragraph to generate space between two paragraphs. What is the way to generate a spacing of any height I specify?
The space between two lines of the same Paragraph is called the leading. See Changing text line spacing
If you want to introduce extra spacing before or after a Paragraph, you can use the setSpacingBefore() or setSpacingAfter() method. See itext spacingBefore property applied to Paragraph causes new page
For instance:
Paragraph paragraph1 = new Paragraph("First paragraph");
paragraph1.setSpacingAfter(72f);
document.add(paragraph1);
Paragraph paragraph2 = new Paragraph("Second paragraph");
document.add(paragraph2);
This puts 72 user units of extra white space between paragraph1 and paragraph2. One user unit corresponds with one point, so by choosing 72, we've added an inch of white space.
Related
when width is sufficient to hold all characters
when characters exceed width
i have used set_line_wrap(True).There are two labels in each row as shown in picture, right label in each row has set_line_wrap(True), why is the label in the second row not starting from the beginning? when characters exceeds, i expect it to start from same position where it started before when characters were not exceeding.
Code:
descriptionLabel=Gtk.Label(description)
descriptionLabel.set_line_wrap(True)
Try setting halign to Gtk.AlignSTART and xalign to 0. This should ensure that both the label as a whole and each individual line starts at the very left of the available space.
I use the following code to get everyline of a text that I have in Text. but the code does not return the lines that are showing in the game, it returns what I have entered in inspector.
myText = GetComponent<Text>();
string[] lines = myText.text.Split('\n');
try{print(lines[0]);}catch{}
try{print(lines[1]);}catch{}
//real output :
//New Text
//What I expect:
//New
//Text
There is a picture :
Screen Shot
How can I get lines that are in the game window?
This is my first post, so excuse any mistakes
The text is displayed as two lines because of the the Text.horizontalOverflow property of the Text component is set to Wrap, but that not means it has been changed to two lines like "New \nText". It is still "New Text".
If you set horizontalOverflow to Wrap, Text will word-wrap when reaching the horizontal boundary. So the output becomes two lines in your case.
You need to set it to Overflow so the text can exceed the horizontal boundary. Then the text will not be influenced by the border of the text GameObject.
Is the same text, the problem is that the width of the RectTransform of the Text Object is too small, increase the width or decrease the text size.
I am trying to extract the headlines of some pdf files to sort them. Unfortunately there's a space between every letters with the spaces between words bigger than the ones between letters of the same word.
Here's my extraction method:
PdfReader reader = new PdfReader(filename);
Rectangle rect = new Rectangle(0, 0, 1000, 1000);
RenderFilter regionFilter = new RegionTextRenderFilter(rect);
FontRenderFilter fontFilter = new FontRenderFilter();
FilteredTextRenderListener strategy = new FilteredTextRenderListener(
new LocationTextExtractionStrategy(), regionFilter, fontFilter);
string result = PdfTextExtractor.GetTextFromPage(reader, 1, strategy);
reader.Close();
Is there a way to filter out the smaller spaces?
iText uses the distance of the rendered glyphs as base to decide if a space is present or not. The general rule applied is, if the distance is larger than the width of a normal space, devided by 2, than a space character is recognized. While this works quite well in most cases, it doesn't work at all, if the width of a space character could not be determined for the font used. In my case the width of a space was recognized as 0, thus the smallest distance between glyphs was recognized as a space. I based my solution on another answer from mkl to a question that is very similar to yours.
In short: You need to derive from e.g. SimpleTextExtractionStrategy or LocationTextExtractionStrategy and override the methods that convert the distance between glyphs into spaces (renderText or isChunkAtWordBoundary respectively).
You can also refer to the answer I gave here or the original solution by mkl.
When I call setFixedHeight() on a PdfPCell, and add more text than fits in the given height, iText seems to print the prefix of the string which fits.
Can I control this clipping algorithm? For example:
Print a suffix of the string rather than a prefix.
Mark a substring of the string as not to be removed. This is with footnote references. If I add text saying "Hello World [1]", the [1] is a reference to a footnote and should not be removed. It's okay to remove the other characters of the string, like "World".
When there are multiple words in the string, iText seems to eliminate a word that doesn't fit, while I would like it partially printed. That is, if the string is "Hello World", and the cell has room only for "Hello Wo...", I would like that to be printed, rather than just "Hello", as iText prints.
Rather than printing characters in their entirety, print only part of them. Imagine printing the text to a PNG and chopping off the top and/or bottom part of the PNG to fit it in the space available. For example, notice that the top line and the bottom line are partially clipped here:
Are any of these possible? Does iText give me any control over how text is clipped? Thanks.
This is with reference to iText 2.1.6.
I have written a proof of concept, ClipCenterCellContent, where we try to fit the text "D2 is a cell with more content than we can fit into the cell." in a cell that is too small.
Just like in your other question ( iText -- How do I get the rendered dimensions of text? ), we add the content using a cell event, but we now add it twice: once in simulation mode (to find out how much space is needed vertically) and once for real (using an offset).
This adds the content in simulation mode (we use the width of the cell and an arbitrary height):
PdfContentByte canvas = canvases[PdfPTable.TEXTCANVAS];
ColumnText ct = new ColumnText(canvas);
ct.setSimpleColumn(new Rectangle(0, 0, position.getWidth(), -1000));
ct.addElement(content);
ct.go(true);
float spaceneeded = 0 - ct.getYLine();
System.out.println(String.format("The content requires %s pt whereas the height is %s pt.", spaceneeded, position.getHeight()));
We now know the needed height and we can add the content for real using an offset:
float offset = (position.getHeight() - spaceneeded) / 2;
System.out.println(String.format("The difference is %s pt; we'll need an offset of %s pt.", -2f * offset, offset));
PdfTemplate tmp = canvas.createTemplate(position.getWidth(), position.getHeight());
ct = new ColumnText(tmp);
ct.setSimpleColumn(0, offset, position.getWidth(), offset + spaceneeded);
ct.addElement(content);
ct.go();
canvas.addTemplate(tmp, position.getLeft(), position.getBottom());
In this case, I used a PdfTemplate to clip the content.
I also have answers to your other questions, but I don't have the time to answer them right now.
For straight Text box clipping, I adapted the C# code given here
http://itextsharp.10939.n7.nabble.com/Limiting-Text-Width-using-PdfContentByte-td2481.html
to the Java code below. The clipping area ends up outside this rectangle, so you can still draw a rectangle on the same exact coordinates.
cb.saveState();
cb.rectangle(left,top,width,height);
cb.clip();
cb.newPath();
// perform clipped output here
cb.restoreState();
I used a try/finally to ensure restoreState() was called.
does anyone know how I can draw a line under a heading (a short line of bold text) that may be located in a random location on a page.
e.g.
My Heading 1
----------------------------------------------
Some random paragraph
My Heading 2
----------------------------------------------
I can do it as I have done above using a line of Underscores _ but in order to get the line anywhere near the heading I have to set the font size at 2 which results in a spotty ugly line.
I can also add two chunks over the top of each other (one with the heading and one with _) similar to the first example in this article http://www.mikesdotnetting.com/Article/82/iTextSharp-Adding-Text-with-Chunks-Phrases-and-Paragraphs using the same font size but it seems that this only works at the top of the page, once I add other paragraphs and try to do it mid-way down the page the two chunks separate with a clear line-break at the end of the first chunk.
It seems you can draw lines in iTextSharp but I have no idea how to calculate the coordinates, as all the examples I have seen use this method to place a line at the top or bottom of the page in a fixed location.
Any help greatly appreciated.
Cheers
Rob
The LineSeperator object might be what you're looking for. Wrap it with a chunk and put it where you need it.
Here's a sample line seperator:
Chunk linebreak = new Chunk(new LineSeparator(4f, 100f, colorGrey, Element.ALIGN_CENTER, -1));
doc.Add(linebreak);
I know this is an older post but, maybe this will help somebody.
//Create Chunk for underline
Chunk chkHeader = new Chunk("My Title", fnt13Bold);
chkHeader.SetUnderline(1f, -2f);
//Add Chunk to paragraph
Paragraph pHeader = new Paragraph(chkHeader);