Q: Is there any way to convert all properties included in .Net
System.Drawing.Printing.PrinterSettings into pdftron.PDF.PrinterMode ?
Generally I need to show some print settings dialog, allow the user to
change print properties like printer name, number of copies, etc. and
print PDF document.
----------------
A: You could convert most properties .Net
System.Drawing.Printing.PrinterSettings to pdftron.PDF.PrinterMode
along the following lines:
using (PrinterMode printerMode = new PrinterMode()) {
printerMode.SetAutoCenter(true);
printerMode.SetAutoRotate(true);
printerMode.SetCollation(true);
printerMode.SetCopyCount(pd.PrintTicket.CopyCount.HasValue ?
pd.PrintTicket.CopyCount.Value : 1);
if (pd.PrintTicket.OutputQuality.HasValue) {
switch (pd.PrintTicket.OutputQuality.Value) {
case OutputQuality.Draft:
printerMode.SetOutputQuality(PrinterMode.OutputQuality.e_OutputQuality_Draft);
break;
case OutputQuality.Automatic:
case OutputQuality.High:
case OutputQuality.Photographic:
printerMode.SetOutputQuality(PrinterMode.OutputQuality.e_OutputQuality_High);
break;
case OutputQuality.Fax:
case OutputQuality.Normal:
case OutputQuality.Unknown:
printerMode.SetOutputQuality(PrinterMode.OutputQuality.e_OutputQuality_Medium);
break;
case OutputQuality.Text:
printerMode.SetOutputQuality(PrinterMode.OutputQuality.e_OutputQuality_Low);
break;
}
}
else printerMode.SetDPI(300);
if (pd.PrintTicket.Duplexing.HasValue)
switch (pd.PrintTicket.Duplexing.Value)
{
case Duplexing.OneSided:
case Duplexing.Unknown:
printerMode.SetDuplexing(PrinterMode.DuplexMode.e_Duplex_None);
break;
case Duplexing.TwoSidedLongEdge:
printerMode.SetDuplexing(PrinterMode.DuplexMode.e_Duplex_LongSide);
break;
case Duplexing.TwoSidedShortEdge:
printerMode.SetDuplexing(PrinterMode.DuplexMode.e_Duplex_ShortSide);
break;
}
else
printerMode.SetDuplexing(PrinterMode.DuplexMode.e_Duplex_None);
printerMode.SetNUp(PrinterMode.NUp.e_NUp_1_1,
PrinterMode.NUpPageOrder.e_PageOrder_LeftToRightThenTopToBottom);
if (pd.PrintTicket.PageOrientation.HasValue) {
if (pd.PrintTicket.PageOrientation.Value ==
PageOrientation.Landscape || pd.PrintTicket.PageOrientation.Value ==
PageOrientation.ReverseLandscape)
printerMode.SetOrientation(PrinterMode.Orientation.e_Orientation_Landscape);
else
printerMode.SetOrientation(PrinterMode.Orientation.e_Orientation_Portrait);
}
else
printerMode.SetOrientation(PrinterMode.Orientation.e_Orientation_Portrait);
printerMode.SetOutputAnnot(PrinterMode.PrintContentTypes.e_PrintContent_DocumentAndAnnotations);
if (pd.PrintTicket.OutputColor.HasValue) {
switch (pd.PrintTicket.OutputColor.Value) {
case OutputColor.Color:
printerMode.SetOutputColor(PrinterMode.OutputColor.e_OutputColor_Color);
break;
case OutputColor.Monochrome:
printerMode.SetOutputColor(PrinterMode.OutputColor.e_OutputColor_Monochrome);
break;
default:
printerMode.SetOutputColor(PrinterMode.OutputColor.e_OutputColor_Grayscale);
break;
}
}
else
printerMode.SetOutputColor(PrinterMode.OutputColor.e_OutputColor_Grayscale);
if (pd.PrintTicket.PageBorderless == PageBorderless.Borderless)
printerMode.SetOutputPageBorder(true);
else
printerMode.SetOutputPageBorder(false);
if (pd.PrintTicket.PageMediaSize != null &&
pd.PrintTicket.PageMediaSize.PageMediaSizeName.HasValue &&
pd.PrintTicket.PageMediaSize.PageMediaSizeName.Value ==
PageMediaSizeName.NorthAmericaLegal)
printerMode.SetPaperSize(PrinterMode.PaperSize.e_legal);
else
printerMode.SetPaperSize(PrinterMode.PaperSize.e_letter);
using (PageSet pagesToPrint = new PageSet(pd.PageRange.PageFrom,
pd.PageRange.PageTo == 0 ? pdfDoc.GetPageCount() :
pd.PageRange.PageTo, PageSet.Filter.e_all))
pdftron.PDF.Print.StartPrintJob(pdfDoc, "",
pdfDoc.GetFileName(), "", pagesToPrint, printerMode);
}
/////////////////////////////////
Another way to print using PDFNet is to convert PDF to XPS (using
pdftron.PDF.Convert.ToXps() as shown in the Convert sample -
http://www.pdftron.com/pdfnet/samplecode.html#Convert; please note
that the use of this method requires PDFNet Convert Add-on) and then
use XPS Print API in Windows 7/Vista or using AddJob (http://
msdn.microsoft.com/en-us/library/aa969772.aspx) in .NET Framework.