在 PDFPrintTest 的示例中进行测试时,我们注意到示例 2 与事件处理程序的示例 1 的行为不正常。
PrintPage 事件处理程序示例 1:
void PrintPage(object sender, PrintPageEventArgs ev)
{
Graphics gr = ev.Graphics;
gr.PageUnit = GraphicsUnit.Inch;
Rectangle rectPage = ev.PageBounds; //print without margins
//Rectangle rectPage = ev.MarginBounds; //print using margins
float dpi = gr.DpiX;
if (dpi > 300) dpi = 300;
int example = 1;
bool use_hard_margins = false;
// Example 1) Print the Bitmap.
if (example == 1)
{
pdfdraw.SetDPI(dpi);
Bitmap bmp = pdfdraw.GetBitmap(pageitr.Current());
//bmp.Save("tiger.jpg");
gr.DrawImage(bmp, rectPage, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel);
}
完整的示例代码在这里:https ://www.pdftron.com/pdfnet/samplecode/PDFPrintTest.cs.html
您会注意到bmp.Save("tiger.jpg");
注释中的注释,这就是出错的地方。如果我们运行代码并保存 bmp,我们会在 jpg 文件中得到我们需要的内容。但是,gr.DrawImage(bmp, rectPage, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel);
打印一个纯空的 pdf 页面。这是为什么 ?
我们的目标:在某些情况下,我们需要强制打印 40% 灰度的打印作业。Winforms 不支持这一点,我们只能设置灰度,不能指定百分比,所以我们希望截取打印并将输出更改为 40% 灰度,这将我们引向 PdfNet 打印示例。从这些示例中,只有处理程序中的示例 2Graphics gr
接受颜色矩阵来为页面设置所需的灰度。
也欢迎任何非 PdfNet 解决方案,但奇怪的是示例代码不能开箱即用。