Welcome
Guest
•
Login
PDFsharp and MigraDoc Wiki
Navigation
¶
Main Page
Random Page
Create a new Page
All Pages
Categories
Navigation Paths
File Management
Create Account
Quick Search
»
Back
PDFsharp Sample: Page Sizes
Modified on 2015/09/14 10:22
by
Thomas Hövel
Categorized as
PDFsharp Samples
,
Samples
{s:navigationPrevUpNext|MultiplePages-sample|PDFsharpSamples|Preview-sample} This sample shows a document with different page sizes. {s: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: {s:PdfLink|PageSizes-sample%2fPageSizes_output.pdf|output.pdf} (40 kB) ==Screen Shots== Here is a sample screen shot: {s:ImageThumbLink|The PageSize sample|PageSizes-sample%2fPageSizesth.png|PageSizes-sample%2fPageSizes.png} ==Source Code== This is the whole source code needed to create the PDF file: {s:beginCsharp} // 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); {s:endCsharp} {s:sampleSourceCode}
Meta Keywords:
Meta Description:
Change Comment:
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