I'm trying to generate a letter, leaving an empty spot and then paste over the top of it the address, depending on where the envelope window is going to be.
So I start off doing this:
Document doc = new Document(PageSize.LETTER, 72, 72, 72, 72);
var w = PdfWriter.GetInstance(doc, output);
Font font = FontFactory.GetFont("arial", 10);
doc.Open();
doc.Add(new Paragraph("date", font) { SpacingAfter = 5 });
doc.Add(new Paragraph("\n\n\n\n\n\n", font));//empty spot
doc.Add(new Paragraph("long\n paragraph\ns panning\ multiple\n lines\n", font) { SpacingAfter = 5 });
doc.Add(new Paragraph("long\n paragraph\ns panning\ multiple\n lines\n", font) { SpacingAfter = 5 });
doc.Add(new Paragraph("long\n paragraph\ns panning\ multiple\n lines\n", font) { SpacingAfter = 5 });
doc.Add(new Paragraph("long\n paragraph\ns panning\ multiple\n lines\n", font) { SpacingAfter = 5 });
doc.Add(new Paragraph("long\n paragraph\ns panning\ multiple\n lines\n", font) { SpacingAfter = 5 });
float llx = 63f, lly = 450f, urx = 387f, ury = 531f;
?? Somehow add "name\n address line 1\n address line2\n city state zip"
doc.Close();
I was hoping to be able to add some text at those coordinates, but I couldn't figure out how... anybody know a way to do it?
An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed). However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.
Absolute positioning defines the position of a given bounding box from the top and left side margins of the web page. This not only allows objects to be placed in an exact location, it also allows objects to be placed one on top of another.
Fixed. The fixed value is similar to absolute as it can help you position an element anywhere relative to the document, however this value is unaffected by scrolling.
Found the answer "Here". (Below is quoted answer from Yannick Smits)
===============
Try this:
ColumnText ct = new ColumnText(cb);
Phrase myText = new Phrase("TEST paragraph\nNewline");
ct.SetSimpleColumn(myText, 34, 750, 580, 317, 15, Element.ALIGN_LEFT);
ct.Go();
parameters of SetSimpleColumn are:
You can also use a ContentByte with a Text Matrix to draw text wherever you want.
PdfContentByte cb = writer.DirectContent;
cb.BeginText();
BaseFont f_cn = BaseFont.CreateFont("c:\\windows\\fonts\\calibri.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.SetFontAndSize(f_cn, 6);
cb.SetTextMatrix(475, 15); //(xPos, yPos)
cb.ShowText("Some text here and the Date: " + DateTime.Now.ToShortDateString());
cb.EndText();
The benefit is that if you don't have to draw the full size of the box the text will go into. With Simple Column, you are drawing a rectangle on the document, and positioning the text within it. With ContentByte, you dodge the rectangle, and position the text by itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With