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.
Tue Aug 19, 2014 9:43 am
I am trying to loop through my pages and print some footer info on each page but I always get the same error:
"Page must be added to some section before using."
- Code: Select all
PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();
foreach (PdfPageBase page in section)
{
page.Canvas.DrawString("Page", fontText, brush, 10, page.GetClientSize().Height - 20);
}
-
TempleClause
-
- Posts: 10
- Joined: Fri Aug 15, 2014 9:34 am
Tue Aug 19, 2014 9:47 am
Hello,
Thanks for your inquiry.
You don't add section for the pdfDocument hence caused the error. Please use
- Code: Select all
foreach (PdfPageBase page in doc.Pages)
.
Best wishes,
Amy
E-iceblue support team
-
amy.zhao
-
- Posts: 2767
- Joined: Wed Jun 27, 2012 8:50 am
Tue Aug 19, 2014 10:03 am
- Code: Select all
foreach (PdfPageBase page in doc.Pages)
I get the same error with this piece of code...
-
TempleClause
-
- Posts: 10
- Joined: Fri Aug 15, 2014 9:34 am
Wed Aug 20, 2014 2:13 am
Hello,
I tested the below code and it worked well.
- Code: Select all
PdfDocument doc = new PdfDocument();
PdfPageBase newpage = doc.Pages.Add();
PdfFont fontText = new PdfFont(PdfFontFamily.Helvetica, 30f);
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
foreach (PdfPageBase page in doc.Pages)
{
page.Canvas.DrawString("Page", fontText, brush, 10, page.GetClientSize().Height - 50);
}
doc.SaveToFile("sample.pdf");
Would you please provide all code to help us investigate it?
Thanks.
Best wishes,
Amy
-
amy.zhao
-
- Posts: 2767
- Joined: Wed Jun 27, 2012 8:50 am