Free Support Forum - aspose.com

Create a form bigger then one page

Hi,

I do have an iteration for creating a form with many fields. When I add about 20 fields (TextField and others) among each other it is bigger then one page. How do I calculate the page size that all fields are compartmentalized into pages with correct page size.

Best regards,
Torsten

@zimmy

Thanks for contacting support.

Would you please share your complete sample code snippet along with output PDF document you generated at your side. We will test the scenario in our environment and address it accordingly.

Here it is:

 private void AddElementsToPage(Document document, Page page, SomeArray elements)
    {
        const int SINGLELINESIZE = 30;

        double upperrightx = page.Rect.Width - 20;  
        double upperrighty = page.Rect.URY - 10;
        double lowerleftx = 20; 
        double lowerlefty = upperrighty - SINGLELINESIZE;

        foreach (var element in elements)
        {
            // create element
            var rectangle = new Rectangle(lowerleftx, lowerlefty, upperrightx, upperrighty);

            if ("text".Equals(surveyElement["type"].ToString()))
            {
                TextBoxField labelField = new TextBoxField(page, rectangle);
                labelField.Value = title;
                labelField.Multiline = true;
                labelField.ReadOnly = true;
                labelField.Name = "textField";
                labelField.Height = 18;

                document.Form.Add(labelField);

                // Eingabefeld
                upperrighty -= 30;
                lowerlefty -= 30;

                rectangle = new Rectangle(lowerleftx, lowerlefty, upperrightx, upperrighty);
                
                TextBoxField textField = new TextBoxField(page, rectangle);
                textField.Value = name; 
                textField.Multiline = false;
                textField.ReadOnly = false;
                textField.Name = "textField";
                textField.Height = 15;

                Border border = new Border(textField);
                border.Width = 1;
                border.Dash = new Dash(1, 1);
                textField.Border = border;

                textField.Color = Color.FromRgb(System.Drawing.Color.AntiqueWhite);
                
                document.Form.Add(textField);
            }

            upperrighty -= 20;
            lowerlefty -= 20;
        }

Best regards,
Torsten

Attached a fully functional sample (except licence of course).

Best regards,
zimmy

AsposeTest.zip (5.0 KB)

@zimmy

Thanks for sharing sample project.

We have checked the sample project and would like to suggest you that you can set page height equal to the sum of textboxes height and bottom/top margin between them. In your particular scenario, you are adding 40 Textboxes having 20 margin value between each pair;

// 20 TextBoxes => Height = 18 => Total = 360
// 20 TextBoxes => Height = 15 => Total = 300
// 20 Margin between => Total = 400
// Total Page Height => 360 + 300 + 400

You can set page height right after adding page to the document using following line of code. An output PDF is also attached for your reference.

page.SetPageSize(PageSize.A4.Width, 360+400+300);
page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);

tmpC13C.pdf (23.2 KB)

In case of any further assistance, please feel free to let us know.

Thanks for your efforts. I do have two problems with that solution:

  1. I some cases I do have a dynamic size of the item control. So I cannont set the page height to a static value. Is there any option to calculate the size of a TextBox (here used as label) after I have added it to a page?
  2. What I need is a pagebreak. When I set the page height to > PageSize.A4.Height it is higher than PageSize.A4.Height (of cource, I did set it). But what I want is that the page height stays at PageSize.A4.Height and the controls are positioned automaticly to the next page.

@zimmy

Thanks for your inquiry.

Once you add the textbox inside PDF, you can use getHeight() method to get height of textbox.

In your above particular scenario, we would like to suggest you to please use tables. You can add textbox inside table cell and add as many rows inside tables as you want with textboxes in them. By default table would shift to subsequent pages after it reaches to maximum available page height. For more information, you may also visit Add Table article in API documentation.