Sorry for I am just beginner of PDFsharp.
How can I set PageSize to a document? Let's say A4. How to set it? Here it is my code. Thanks.
Document document = new Document();
// Add a section to the document
Section section = document.AddSection();
section.AddParagraph("dddddd");
// Add a section to the document
var table = section.AddTable();
table.AddColumn("8cm");
table.AddColumn("8cm");
var row = table.AddRow();
var paragraph = row.Cells[0].AddParagraph("Left text");
paragraph.AddTab();
paragraph.AddText("Right text");
paragraph.Format.ClearAll();
// TabStop at column width minus inner margins and borders:
paragraph.Format.AddTabStop("27.7cm", TabAlignment.Right);
row.Cells[1].AddParagraph("Second column");
table.Borders.Width = 1;
A4 is the default size.
Every section has a
PageSetup
property where you can set page size, margins and such.You should never modify DefaultPageSetup, use a
Clone()
instead.PageFormat
does not work for theClone()
, becausePageWidth
andPageHeight
are set for the default size A4.To get Letter format, you can use this code to overwrite
PageWidth
andPageHeight
:To get Letter format, you can use this code to reset
PageWidth
andPageHeight
to makePageFormat
work again:Creating a
Clone()
is useful if your code uses e.g. left and right margins to calculate table widths or such. No need to create a Clone if you set all margins explicitly or do not use margins for calculations.If you need
Clone()
you can use the methods shown here to set the page size.