通过在启用PrintToFile
选项的情况下将PDF文件发送到打印机驱动程序,我已经成功将PDF文件转换为PCL文件。
但是,尽管我为双面打印显式设置了一个值,但是此设置不会传送到PCL文件中。
这是我的代码(使用Pdfium.NET SDK完成渲染):
using (var pd = new PrintDocument()
{
DocumentName = String.Format(PclFile),
PrintController = new StandardPrintController() // suppresses dialog "Printing page X of Y"
})
{
pd.PrinterSettings = new PrinterSettings()
{
PrinterName = printerName,
PrintToFile = true,
PrintFileName = String.Format(DocumentPath, Path.GetFileName(printerName)),
Duplex = Duplex.Horizontal
};
var pageForPrint = 0;
pd.PrintPage += (s, e) =>
{
// Code from http://forum.patagames.com/posts/t6-Print-functionality-in-Pdfium--NET-SDK
e.PageSettings.PaperSize.RawKind = (int)PaperKind.A4;
e.PageSettings.Landscape = false;
var actualWidth = (int)(e.Graphics.DpiX * 210 / 25.4f); // 210x297 - size of paper (A4) in millimeters
var actualHeight = (int)(e.Graphics.DpiY * 297 / 25.4f); // 25.4f - millimeters per inch
// Render to PdfBitmap using page's Render method with FPDF_PRINTING flag
pdf.Pages[pageForPrint].Render(e.Graphics, 0, 0, actualWidth, actualHeight, PageRotate.Rotate180, RenderFlags.FPDF_PRINTING | RenderFlags.FPDF_ANNOT);
// Print next page
if (pageForPrint < pdf.Pages.Count - 1)
{
pageForPrint++;
e.HasMorePages = true;
}
};
pd.Print();
}
这是生成的PCL文件的内容:
%-12345X@PJL JOB Name="765174f8-8824-4318-bac9-e4e6cdae"
@PJL COMMENT Version 3.10
@PJL COMMENT Monochrome
@PJL COMMENT USER=WebApps
@PJL COMMENT Name=765174f8-8824-4318-bac9-e4e6cdae
@PJL SET USERNAME="WebApps"
@PJL SET KCOLORMODE=MONO
@PJL SET KGLOSS=LOW
@PJL SET ECOPRINT=OFF
@PJL SET RESOLUTION=600
@PJL ENTER LANGUAGE = PCL
[binary data]
如您所见,SET DUPLEX
选项缺失。我在做什么错了?
谢谢您的任何建议。
克里斯。