Dynamically add text to Pdf and get next line position for adding new text

Hi all,

Does the pdf document automatically add page to accomodate the text if I add new long text longer than a page,

How do I get the position x, y, page number for the next line after some text added to the document?

Any direction would be much appreciated.

I have not use Apose.pdf before.

Thanks a lot,

Tom

Hi Tom,


Thanks for your interest in our products.

We are working over this query and will get back to you soon. Sorry for the delay and inconvenience.

Hi,

I have read some programmers guides but you could help give me some advice to get started.
what object I should use Apose.Pdf or Apose.Pdf.generator for creating a pdf letter?
The pdf letter has:
- a logo (image) ,
- multiline textbox ( user will open the letter using pdf editor to add data)
- content text (only know at runtime).
- how to break a string into lines to use Addline method,
- how to know when run out of space and to call Pages.Add
- signature image, and other images

Thanks a lot,

Tomlx





Tomlx:
Does the pdf document automatically add page to accomodate the text if I add new long text longer than a page,
Hi Tom,

Thanks for your patience and sorry for delay in response.

When using Aspose.Pdf.Generator namespace to create PDF documents, by default the contents are placed in Flow layout from Top-Left to Bottom-Right. And when adding a Text paragraph whose length is greater than page length, by default the contents are moved to next page.

Tomlx:
How do I get the position x, y, page number for the next line after some text added to the document?
Aspose.Pdf namespace provides set of classes which provide the feature to get the position and various attributes i.e. Formatting information for a particular text string and you may also get the position information for a text object. Please visit the following link for further details on Search and Get Text from All the Pages of PDF Document

Tomlx:
I have read some programmers guides but you could help give me some advice to get started.what object I should use Apose.Pdf or Apose.Pdf.generator for creating a pdf letter?
Hi Tom,

Thanks for sharing the details. Please note that Aspose.Pdf.Generator namespace provides the only feature to create PDF document from scratch. As per your requirement, you can place Text, Image, Logo etc while generating the PDF document. As per DOM (Document Object Model) of Aspose.Pdf.Generator, a PDF file is comprised of Section objects where each Section can have one or more Paragraph elements. Text, Image, Attachment, Form Field, Annotation, Graph object are Paragraph level elements. So if you need to place any specific Text paragraph or Image on a new page, you may simply add it to new Section and it will be displayed over new page. Or you may call Text.IsFirstParagraph property and set its value to True and the paragraph will be displayed on new page.
However Aspose.Pdf provides the capability to Create/Manipulate/Transform new and existing PDF documents.

Tomlx:
The pdf letter has:
- a logo (image) ,
- multiline textbox ( user will open the letter using pdf editor to add data)
- content text (only know at runtime).
- how to break a string into lines to use Addline method,
- how to know when run out of space and to call Pages.Add
- signature image, and other images
In order to add/update/remove Images, Text etc from PDF file, please try using Aspose.Pdf namespace. Please visit the following link for further details on

In case I have not properly understood your requirement or you have any further query, please feel free to contact. We are sorry for your inconvenience.

Hi Nayyer,

Thanks for you advice.

I have a specific need to write text at a fixed position. I have tried many method but they do not work for me.

For example I need to write some text to a page (like a template) which I do not know the length but do know it about from 1 to 5 lines. Then I need to write the next text say at half way down the page. I try to set the textinfor top margin for the second text but the top margin but it is margin from the last line of the first paragraph.It just the gap between the paragraphs.

I am thinking of using the table but need to know the height of the table ..so I can work out write the row for the second text.

Looking forward to your advice.

Best regards,

Tomlx

Hi Tom,

Sorry for replying you late.

Frankly speaking, I am not entirely certain about your requirement. Either you need to place text while creating PDF document from scratch or you need to place the text inside an existing PDF document ?

If you need to place text at a specific location while creating a new PDF document, then you may consider using FloatingBox. The default layout of PDF is flow layout Top-Left to Bottom-Right where as FloatingBox is placed on absolute positioning inside the PDF document. Please visit the following link for further details on Working with Floating Box (Generator)

In case you need to place text inside existing PDF document, you may consider using PdfFileMend class of Aspose.Pdf.Facades namespace, as it provides the option to specify the rectangular region where the text will be placed. Please visit the following link for further details on Add Text in an Existing PDF File (Facades) as

I am thinking of using the table but need to know the height of the table …so I can work out write the row for the second text.

In case of using tables, you may consider using FixedRowHeight property of Row class to get a float value representing row height and when placing rows inside table object, you would be sure about the number of rows placed inside the PDF, so it will be quite easy to calculate the total height of table object.

In case I have not properly understood your requirement or you have any further query, please feel free to contact. We are sorry for your inconvenience.

Hi Nayyer,

I have tried the floating box but I can not set it to the position I want. For example I want to put the box 3 inches from Top and 2 inches from left of the page but I always have the box at position 1 inch from top and 1inch from left of the page.
I modify the example from help, see the codes below.

'Instantiate Pdf instance by calling its empty constructor
Dim pdf1 As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf()
'Create section object and add it to sections collection of PDF
Dim sec1 As Aspose.Pdf.Generator.Section = pdf1.Sections.Add()

'Create FloatingBox with 108 as width and 80 as height
Dim box1 As Aspose.Pdf.Generator.FloatingBox = New Aspose.Pdf.Generator.FloatingBox(108, 80)
'add FloatingBox to paragraphs collection of section object
sec1.Paragraphs.Add(box1)
box1.BoxHorizontalPositioning = 216

box1.BoxVerticalPositioning = 142

’add sample text string to paragraphs collection of FloatingBox object
box1.Paragraphs.Add(New Aspose.Pdf.Generator.Text(“Hello.”))
'save the resultant PDF
pdf1.Save(“d:/test/test.pdf”)

Could you tell me where I go wrong.

Thanks,
Tom

Hi Tom,

Thanks for sharing the code snippet and sorry for the delay in response.

Please note that in order to specify the location for FloatingBox, please try using the Box.Margin.Left property to set the left margin of FloatingBox and in order to specify the top position, please try using the Box.Margin.Topproperty. Please try using the following code lines to accomplish your requirement.

[VB.NET]

' specify the left margin for FloatingBox instance
box1.Margin.Left =2

' specify the top margin for FloatingBox instance
box1.Margin.Top = 3

Also please update your code snippet as specified below.

_box1.BoxHorizontalPositioning  _= BoxHorizontalPositioningType.Margin box1.BoxVerticalPositioning = BoxVerticalPositioningType.Margin

In case the problem still persists, please feel free to contact. We are sorry for this inconvenience.