Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Sep 04, 2019 8:20 am

As written by title I would like all the contents that do not enter the current page to change page generating one automatically.
Thanks all!

Chronicles
 
Posts: 3
Joined: Wed Sep 04, 2019 8:07 am

Wed Sep 04, 2019 9:29 am

Hi,

Thanks for your inquiry.
Sorry that I am not quite clear about your detailed situation. To help us solve your issue quickly, please provide following information.
1. The content you want to insert in page
2. The desired result.
3. If there is code you were using, please share it.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Sep 04, 2019 1:38 pm

Code: Select all
page.Canvas.DrawString("Access CoolClass",
                                    new PdfFont(PdfFontFamily.Helvetica, 14f),
                                    new PdfSolidBrush(Color.RoyalBlue),
                                    10, heighttext);
                        heighttext += 20;

                        page.Canvas.DrawString("Nome utente:    coolman\\" + usernametxt.Text + " ",
                                    new PdfFont(PdfFontFamily.Helvetica, 12f),
                                    new PdfSolidBrush(Color.Black),
                                    20, heighttext);
                        heighttext += 12;

                        page.Canvas.DrawString("Password:        " + passwordtxt.Text,
                                    new PdfFont(PdfFontFamily.Helvetica, 12f),
                                    new PdfSolidBrush(Color.Black),
                                    20, heighttext);



I have 10 checkboxes that generate similar content to the one shown above and all 10 do not fit on one page, I can't know if all 10 checkboxes will be generated and therefore I can't manually create the page, how can I move does the content that is created and that is not on the current page go moved to a new page?

Chronicles
 
Posts: 3
Joined: Wed Sep 04, 2019 8:07 am

Thu Sep 05, 2019 3:43 am

Hi,

Thanks for your information.
Your goal could be achieved. You could calculate the position of the checkbox and judge the situation. When the space of the page is not enough to place a new checkbox, then add a new page. Below code for your kind reference:
Code: Select all
            //load a pdf file which only has one page
            PdfDocument doc = new PdfDocument(FilePath + "HelloWorld.pdf");
            doc.AllowCreateForm = true;
            int x = 20;
            int y = 50;
            PdfPageBase page = doc.Pages[0];
            for (int i = 0; i < 10; i++ )
            {
                string name = String.Format("checkbox {0}", i);
                //check if the space is enough to draw checkbox
                if (y < page.ActualSize.Height - 40)
                {
                    PdfCheckBoxField checkbox = new PdfCheckBoxField(page, name);
                    checkbox.Bounds = new RectangleF(new PointF(x, y), new SizeF(40, 40));
                    checkbox.BackColor = Color.Transparent;
                    checkbox.BorderWidth = 0.25f;
                    checkbox.Style = PdfCheckBoxStyle.Check;
                    checkbox.Checked = true;
                    doc.Form.Fields.Add(checkbox);
                    checkbox.TextAlignment = PdfTextAlignment.Center;
                }               
               // if the space is not enough, then add new page
                else
                {
                    page = doc.Pages.Add();
                    x = 10;
                    y = 10;
                    PdfCheckBoxField checkbox = new PdfCheckBoxField(page, name);
                    checkbox.Bounds = new RectangleF(new PointF(x, y), new SizeF(40, 40));
                    checkbox.BackColor = Color.Transparent;
                    checkbox.BorderWidth = 0.25f;
                    checkbox.Style = PdfCheckBoxStyle.Check;
                    checkbox.Checked = true;
                    doc.Form.Fields.Add(checkbox);
                    checkbox.TextAlignment = PdfTextAlignment.Center;
                }
                //the y position of checkbox
                y += 300;               
            }
            doc.SaveToFile("18789AddPageAuto.pdf");


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Sep 05, 2019 6:14 am

Hello and thanks for the answers.

I meant that every checkbox ticked through my winform c # that writes the piece of code I inserted in the previous post onto the pdf, I have to check if those lines are less there and don't write checkboxes on the pdf sheet, thanks

Chronicles
 
Posts: 3
Joined: Wed Sep 04, 2019 8:07 am

Thu Sep 05, 2019 10:00 am

Hi,

Thanks for your inquiry.
Where do you want to insert Checkbox?
I checked again the code you provided before, when drawing text I think you could judge if the position of text( heighttext) exceeds the height of the page.
If you still have the issue, to help us understand your requirement accurately, please provide an example which includes your full code, the output you got and the expected result you want.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Sep 05, 2019 10:48 am

I got it solved off your last reply. thanks..

Safder
 
Posts: 21
Joined: Fri Sep 28, 2018 8:08 am

Fri Sep 06, 2019 1:46 am

Hi Safder,

Thanks for your feedback.
If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF