I have drawn my own field with Itextsharp and I want to add text to this field. This code is line.
I write some text, but I cannot write to the field I want. I have to write on the line. So I have to add the title to the top of the page. I tried to adjust the position, but I couldn't.
How do I adjust the text position?
Have you tried spacing?
p.SpacingAfter = 30;
or
p.SpacingBefore = 30;
Basically the iTextSharp has two ways of writing text.
One of them is the ContentByte, I think this is what you need.
I like to declare a global variable that stores the current position of contentByte. From it you can write the next element.
In this case you need to write the text at the top and then draw the shape from the final position of the text.
Related
I’m writing an application that outputs a word file containing text an images. The blocks of text are of variable length. In some cases I want to know how much vertical space a block of text wil use in the document, given a certain width, so I can insert a page break to make it look nicer.
I’m using Microsoft.Office.Interop.Word
So the question is: Is it possible to calculate the resulting height given a certain width and a certain text style.
Cheers!
I have an existing PDF which has couple of lines of text and horizontal line in the top of every page. like full file name, date time, and a horizontal line below that. The positions, height and width are same on all pages/pdf files.
I would like to remove those two lines of text and the horizontal line using ABCPdf.
Thanks
Instead of remove the text (what may not possible), consider place a "white rectangle" hidding it. Then you can "stamp" the doc for a better "cammouflage".
Something like that, for each page:
yourDoc.Rect.SetRect ( coordinates ...)
yourDoc.Color.String = "255 255 255"
yourDoc.FillRect()
...
yourDoc.Flatten etc.
I'm not sure if this is possible or not. I'm interested in being able to find the (x,y) position of a word of text on a WinForm.
For example, in the picture below, I want to be able to pull the (x,y) coordinate of the upper-left hand corner of the letter H in "HERE".
I know how to get the position of textbox, so I can make a rough estimate based off of where the word "HERE" is inside the textbox, but I would like to be able to just ask the program where the word is if that is possible.
Also, if there is a way to get that position, I'd like to be able to get the length and height of the word (Basically I want to know the coordinates of the bounding box of the word "HERE" if possible)
Not sure if this matters, but the textbox is a richTextBox, and the textbox is populated from a string array in the Form1 class.
Thank you in advance!
You can use GetPositionFromCharIndex method, to get position of "HERE" within the TextBox or RichTextBox (it works for both).
As you probably know, to get position in the window you have to sum this up with position of your richTextBox. Like this:
int index = richTextBox1.Text.IndexOf("HERE");
Point textBoxLocation = richTextBox1.GetPositionFromCharIndex(index);
Point windowsLocation = new Point(richTextBox1.Location.X + textBoxLocation.X, richTextBox1.Location.Y + textBoxLocation.Y);
Console.WriteLine("Position in textbox: " + textBoxLocation.ToString());
Console.WriteLine("Position in window: " + windowsLocation.ToString());
In my project I want to count lines displayed by richtextbox in C# with word wrap property set true. For example, in richtextbox, I write a text, and when text reaches the width of the richtextbox, then it automatically goes to second line. So what happens is the text contains actually one line but it is displayed in two lines. So I want to know how can I count this as two lines instead of one? Help will be really appreciated.
You may go for RichTextBox.GetLineFromCharIndex Method
Retrieves the line number from the
specified character position within
the text of the RichTextBox control. If WordWrap is set to false, no portion of the line wraps to the next, and the method returns 0 for the specified character index.
Also, check out this link.
Is there any technique to calculate the height of text in AcroField?
In other words, I have a template PDF with a body section that I want to paste my long text into and I want to get the height of the text. If it overflows, insert a new page for rest of the text.
This will give height and width:
Vector curBaseline = renderInfo.GetBaseline().GetStartPoint();
Vector topRight = renderInfo.GetAscentLine().GetEndPoint();
iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(
curBaseline[Vector.I1], curBaseline[Vector.I2],
topRight[Vector.I1], topRight[Vector.I2]
);
Single curFontSize = rect.Height;
Just set your field to a font size of zero. This will automatically size the font so that the given text will fit into your field... within certain limits. I don't think it'll shrink below 6 points.
Another alternative would be to use a ColumnText and call myColText.go(true). This will "simulate" layout, letting you know what goes where without actually drawing anything to the PDF. Just whip up a columnText with the same dimensions, font&font-size as your field, and your results should be the same.
In fact, I believe iText's text field rendering code uses ColumnText internally. Yep, have a look at the source for TextField.getAppearance().
Note that the bounding box of your field isn't going to match the box the text is laid out into... you have to account for borer style & thickness. That's why I suggest you look at the source.