Setting PDF Page Size Programmatically / PDF Printer
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()
-
{
-
InitializeComponent();
-
}
-
-
private void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
-
{
-
// Output something in the print
-
e.Graphics.DrawString("Page size:\n" + e.PageSettings.PaperSize.ToString(), Font , myBrush, e.MarginBounds.Left, e.MarginBounds.Top);
-
myBrush.Dispose();
-
}
-
-
private void button1_Click(object sender, EventArgs e)
-
{
-
pd.PrinterSettings.PrinterName = "7-PDF Printer";
-
pd.DefaultPageSettings.Landscape = true;
-
pd.Print();
-
}
-
}
-
}
Download Example Files
Example C# source files are included in the zip file.
Downloads
Attachment | Size |
---|---|
Example file | 10.21 KB |