biopdf logo

Setting PDF Page Size Programmatically

A great deal of users asks us how to set the page size of the PDF from your program. To answer this question we have made this small example that will show you how to do it from a C# program.  

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace PrintForms
   public partial class Form1 : Form
       public Form1()

       private void pd_PrintPage(object sender,
        System.Drawing.Printing.PrintPageEventArgs e)
           // Output something in the print
           SolidBrush myBrush = new SolidBrush(Color.Blue);
           e.Graphics.DrawString("Page size:\n" + e.PageSettings.PaperSize.ToString(),
            Font , myBrush, e.MarginBounds.Left, e.MarginBounds.Top);

       private void button1_Click(object sender, EventArgs e)
           pd.PrinterSettings.PrinterName = "PDF Writer - Biopdf";
           pd.DefaultPageSettings.Landscape = true;
           pd.DefaultPageSettings.PaperSize = new PaperSize("My Paper", 500, 700);

Example source files are included in the zip file that can be downloaded here.

Example Source Files  

McAfee SiteAdvisor Norton Safe Web