Developer Tools
|
Office Productivity Applications
|
Enterprise Solutions
|
|||||||||||||||||||||||







Printing a PDF document using PDFOne is very simple - create a
PDFPrinter instance, load the PDF document, and call
the "Print" method.
The PDF printer component exposes a System.Drawing.Printing.PrinterSettings property for full .NET printing support. This allows your .NET application to enumerate available printers, paper sizes, media trays and other settings and choose appropriate ones for PDF print jobs. Apart from this, the PDF printer component has numerous printing settings of its own, such as the ability to:
The following code snippet illustrates how to a PDF document in C# using PDFOne .NET.
using System;
using System.Collections.Generic;
using System.Text;
using Gnostice.PDFOne;
using Gnostice.PDFOne.PDFPrinter;
using System.Drawing.Printing;
class PDF_Printer_Demo {
static void Main(string[] args) {
PDFPrinter PDFPrinter1
= new PDFPrinter("your license key");
PDFPrinter1.PasswordRequired
+= new PasswordRequiredEventHandler(PDFPrinter1_PasswordRequired);
PDFPrinter1.PrintError
+= new PrintErrorDelegate(PDFPrinter1_PrintError);
PDFPrinter1.RenderError
+= new RenderErrorHandler(PDFPrinter1_RenderError);
PDFPrinter1.AfterPrintPage
+=new PrintPageDelegate(PDFPrinter1_AfterPrintPage);
try {
Console.Write("Opening document ... ");
// Load document for printing
PDFPrinter1.LoadDocument("sample_doc.pdf");
Console.WriteLine("Done");
// Specify print settings
PDFPrinter1.AutoCenter = true;
PDFPrinter1.AutoRotate = true;
PDFPrinter1.PageScaleType = PrintScaleType.None;
PDFPrinter1.PrintOptions.PrintRange = PrintRange.Selection;
PDFPrinter1.SelectedPages = "2,4";
Console.Write("Selecting printer ... ");
// Select first one among installed printers
PDFPrinter1.PrintOptions.PrinterName
= (String) PrinterSettings.InstalledPrinters[0];
Console.WriteLine("Done");
Console.WriteLine("Sending print output to selected printer [" +
PDFPrinter1.PrintOptions.PrinterName + "] ... ");
// Start printing
PDFPrinter1.Print();
Console.Write("\r ");
Console.WriteLine("\rDone.");
} catch (Exception Exception1) {
Console.WriteLine("\nError: " + Exception1.Message);
} finally {
try {
Console.Write("Closing document ... ");
// Close printed document
PDFPrinter1.CloseDocument();
Console.WriteLine("Done.");
} catch (Exception Exception2) {
Console.WriteLine("\nError: " + Exception2.Message);
} finally {
// Clean up
PDFPrinter1.Dispose();
Console.WriteLine("Press Enter to exit.");
Console.In.ReadLine();
}
}
}
// Event handler for PDFPrinter.PrintError
private static void PDFPrinter1_PrintError(
object sender,
int pageNumber,
Exception e) {
Console.WriteLine("\nError: While creating print output on page #" +
pageNumber.ToString() +
"\nOriginal Error Message: " +
e.Message);
}
// Event handler for PDFPrinter.RenderError
private static void PDFPrinter1_RenderError(
object sender,
int pageNum,
Exception renderError,
ref bool continueRendering) {
Console.WriteLine("\n\nError: While rendering page #" +
pageNum.ToString() + " on printer." +
"\nOriginal Error Message: " +
renderError.Message);
}
// Event handler for PDFPrinter.AfterPrintPage
private static void PDFPrinter1_AfterPrintPage(
object sender,
int pageNumber,
PrintPageEventArgs e) {
// Clear the current line
Console.Write("\r ");
// Write number of last page that was printed
Console.Write("\rPrinting page #" + pageNumber.ToString());
}
// Event handler for PDFPrinter.PasswordRequired
private static void PDFPrinter1_PasswordRequired(
object sender,
ref string password,
ref bool continueLoading) {
// Prompt for password
Console.WriteLine("\n\nEnter a password to open this document: ");
// Obtain password entered by user
String sPassword = Console.In.ReadLine();
// Open document with obtained password
password = sPassword;
continueLoading = true;
}
}
---o0O0o---
| Our Developer Tools | |
|---|---|
eDocEngine VCLA Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools. |
PDFtoolkit VCLA Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents. |
XtremePDFConverter VCLA Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents. |
|
PDFOne .NETA .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications. |
XtremeDocumentStudio .NETMulti-format document-processing component suite for .NET developers |
PDFOne (for Java™)A Java™ PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java™ applications. |
XtremeFontEngine (for Java)Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts |
| Our Office Productivity Applications |
|---|
Free PDF ReaderA free, fast, and portable application for viewing, printing and converting PDF documents. |
| Privacy | Legal | Feedback | Newsletter | Resellers | © 2002-2013 Gnostice Information Technologies Private Limited. All rights reserved. |
This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).