It seems that to add a page element (for example a label) it always requires you to put in and X,Y coordinates. But if you have to dynamically add label after label, you won't know the X,Y coordinates to assign it. Basically I just want each page element to appear next on the page without having to know the XY coordinates. Maybe I am missing something here.
If I need to add 4 Paragraphs, each being dynamic in size, content and language, I am not going to know what XY coordinates to assign in code. I just want each paragraph to display after each other.
Dynamically adding page elements with X, Y coordinates
Re: Dynamically adding page elements with X, Y coordinates
Support · Feb 1, 2012Hello,
When you add page elements to the PDF page using Generator you would need to provide the X & Y coordinates. In order to add labels using the dynamically generated data you can calculate and the keep track of the X & Y coordinates by reading the height and width properties of the Label or other page elements that were added to the page.
For adding paragraphs use the TextArea which has several properties to handle the dynamic content and allows the overflow of content to the next page. Please refer to the Text Continuation
topic.
Also take a look at our ReportWriter
product (Includes Generator) which enables you to design the report template using the DynamicPDF Designer tool and generate the PDF document based on the template.
Thanks,
ceTe Software Support Team.
Re: Dynamically adding page elements with X, Y coordinates
Forum member · Feb 3, 2012If I keep track of the x and y coordinates, is there a way to know the resulting x y coordinates of the textarea or FormattedTextArea you just added.
For example: If I add my first FormattedTextArea with coordinates (0,0). Is there a way to know the resulting x,y coordinates from FormattedTextArea so I can then calculate what the coordinates would be for the next FormattedTextArea I want to add? Most specifically the y coordinates. I need to know the coordinates where the FormattedTextArea ended so I calculate where to add then next FormattedTextArea.
Re: Dynamically adding page elements with X, Y coordinates
Support · Feb 3, 2012Hello,
Yes, you can dynamically calculate the X and Y positions for the page elements. You can set the Y position for the new page element with this newly calculated Y position. Below is the sample code for it.
Document document = new Document();
Page page = new Page();
string formattedText = "Using DynamicPDF Generator for .NET is very straight forward and the object model can be learned very quickly. There are three common objects that are used: Document, Page, and Page Element objects. ";
FormattedTextArea formattedTextArea = new FormattedTextArea(formattedText, 0, 0, 200, 200, FontFamily.Helvetica, 14, true);
page.Elements.Add(formattedTextArea);
float newXposition = formattedTextArea.X;
float newYposition = formattedTextArea.Y + formattedTextArea.GetRequiredHeight()+10;
FormattedTextArea newFormattedTextArea = new FormattedTextArea("New FormattedTextArea", newXposition, newYposition, 200, 200, FontFamily.Helvetica, 14, true);
page.Elements.Add(newFormattedTextArea);
document.Pages.Add(page);
document.Draw(@"C:\MyDocument.pdf");
Thanks,
ceTe Software Support Team