Wednesday, 17 July 2013

PdfDocument code in c#


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Drawing.Printing;

using Spire.Pdf;

namespace PdfPrint


class Program



static void Main(string[] args)


// Instantiate an object of PdfDocument

PdfDocument doc = new PdfDocument();

string pdfFile = “sample.pdf”;

//load PDF document


//Default printing mode without interaction (default printer to print all pages of the document)


//Interaction printing mode(page range,printer,and properties of printing can be freely to selected and set)

PrintDialog dialogPrint = new PrintDialog();

dialogPrint.AllowPrintToFile = true;

dialogPrint.AllowSomePages = true;

dialogPrint.PrinterSettings.MinimumPage = 1;

dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count;

dialogPrint.PrinterSettings.FromPage = 1;

dialogPrint.PrinterSettings.ToPage = doc.Pages.Count;

if (dialogPrint.ShowDialog() == DialogResult.OK)


//the startpage was selected to be printed

doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage;

//the endpage was selected to be printed

doc.PrintToPage = dialogPrint.PrinterSettings.ToPage;

//Choose printer to print pdf document

doc.PrinterName = dialogPrint.PrinterSettings.PrinterName;

PrintDocument printDoc = doc.PrintDocument;

dialogPrint.Document = printDoc;

//Realize printing






No comments:

Post a Comment