Hi Thomas,
sorry for that mistake, i thought this is the support forum. Hi Community
Surely we creates a document and also sections to the document. Here's the code:
Code:
public static void CreateDoc(Language language, out Document migraDocument, out Section section, double marginTop = 4.7, double marginLeft = 1.5, double marginBottom = 3.3, int fontSize = 10)
{
// Create a new MigraDoc document
migraDocument = new Document();
CreateSection(language,migraDocument,out section,marginTop,marginLeft,marginBottom,fontSize);
}
public static void CreateSection(Language language, Document migraDocument, out Section section, double marginTop = 4.7, double marginLeft = 1.5, double marginBottom = 3.3, int fontSize = 10)
{
// Create a new MigraDoc document
section = migraDocument.AddSection();
section.PageSetup.LeftMargin = XUnit.FromCentimeter(marginLeft).Point;
section.PageSetup.RightMargin = XUnit.FromCentimeter(marginLeft).Point;
section.PageSetup.TopMargin = XUnit.FromCentimeter(marginTop).Point;
section.PageSetup.BottomMargin = XUnit.FromCentimeter(marginBottom).Point;
}
With these two static methods, we initialize documents for a number of PDFs. A call to these methods looks like as follows:
Code:
public PdfDocument CreatePdf()
{
string titleOfDocument = "Titel";
try
{
Document document;
Section section;
PdfUtil.CreateDoc(_language, out document, out section, 5.0, 1.2, 2.0);
addHeader(section);
CreatePage(section);
addFooter(section);
return PdfUtil.RenderPdf(document, titleOfDocument);
}
catch (Exception ex)
{
PdfUtil.SendErrorMail(ex, titleOfDocument, Context.Language.ToString());
return null;
}
}
The CountPages function call is inside the addFooter function:
Code:
private void addFooter(Section section)
{
Table table;
createTwoColumnTable(section,out table);
Row row = table.AddRow();
row.VerticalAlignment = VerticalAlignment.Bottom;
//Seitenanzahl
Paragraph paragraphFooter = new Paragraph();
paragraphFooter.Format.Font.Size = 9;
paragraphFooter.Format.LineSpacing = 9;
paragraphFooter.Format.Font.Color = _blackColor;
int countPages = PdfUtil.CountPages(section);
paragraphFooter.AddText("Seite " + countPages);
row[0].Add(paragraphFooter);
}
I hope my explanations are comprehensible. Could this issue be associated with the size of a pdf file?
Best regards
Fabian