C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Printing;
using Spire.Pdf;
namespace PdfPrint
{
class Program
{
[STAThread()]
static void Main(string[] args)
{
// Instantiate an object of PdfDocument
PdfDocument doc = new PdfDocument();
string pdfFile = “sample.pdf”;
//load PDF document
doc.LoadFromFile(pdfFile);
//Default printing mode without interaction (default printer to print all pages of the document)
doc.PrintDocument.Print();
//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
printDoc.Print();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Printing;
using Spire.Pdf;
namespace PdfPrint
{
class Program
{
[STAThread()]
static void Main(string[] args)
{
// Instantiate an object of PdfDocument
PdfDocument doc = new PdfDocument();
string pdfFile = “sample.pdf”;
//load PDF document
doc.LoadFromFile(pdfFile);
//Default printing mode without interaction (default printer to print all pages of the document)
doc.PrintDocument.Print();
//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
printDoc.Print();
}
}
}
}
No comments:
Post a Comment