Welcome GuestLogin

PDFsharp and MigraDoc Wiki

RSS RSS

Navigation




Quick Search
»

PoweredBy

Visit the new Website for PDFsharp & MigraDoc Foundation 6.0 for .NET 6 and find information about the new version for Windows, Linux, and other platforms.

<< Previous^UpNext >>
This sample shows a document with different page sizes.

Note:  You can set the size of a page to any size using the Width and Height properties. This sample just shows the predefined sizes.

PDF Output File

See the PDF file created by this sample: output.pdf (40 kB)

Screen Shots

Here is a sample screen shot:

The PageSize sample

Source Code

This is the whole source code needed to create the PDF file:
// Create a new PDF document
PdfDocument document = new PdfDocument();
 
// Create a font
XFont font = new XFont("Times", 25, XFontStyle.Bold);
 
PageSize[] pageSizes = (PageSize[])Enum.GetValues(typeof(PageSize));
foreach (PageSize pageSize in pageSizes)
{
  if (pageSize == PageSize.Undefined)
    continue;
 
  // One page in Portrait...
  PdfPage page = document.AddPage();
  page.Size = pageSize;
  XGraphics gfx = XGraphics.FromPdfPage(page);
  gfx.DrawString(pageSize.ToString(), font, XBrushes.DarkRed,
    new XRect(0, 0, page.Width, page.Height),
    XStringFormats.Center);
 
  // ... and one in Landscape orientation.
  page = document.AddPage();
  page.Size = pageSize;
  page.Orientation = PageOrientation.Landscape;
  gfx = XGraphics.FromPdfPage(page);
  gfx.DrawString(pageSize + " (landscape)", font,
    XBrushes.DarkRed, new XRect(0, 0, page.Width, page.Height),
    XStringFormats.Center);
}
 
// Save the document...
const string filename = "PageSizes_tempfile.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);

Note: The samples on this site usually show and discuss code snippets only. The complete source code of the samples with solutions for Visual Studio is available from the download area on CodePlex.


Visit the new Website for PDFsharp & MigraDoc Foundation 6.0 for .NET 6 and find information about the new version for Windows, Linux, and other platforms.



Miscellaneous
Home
PDFsharp
FAQ
Samples
Articles
MigraDoc
FAQ
Samples
Articles

ScrewTurn Wiki version 3.0.5.600. Some of the icons created by FamFamFam.

Impressum - Privacy Policy, Data Protection Declaration, Legal Notice