在從PDFPrintTest樣本中進行測試時,我們注意到示例2與事件處理程序的示例1相結合的行爲不正確。Pdfnet打印樣本不工作
例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 Print樣本。從這些示例中,處理程序中只有示例2具有Graphics gr
,它接受用於設置所需頁面中灰度級的顏色矩陣。
任何非PdfNet解決方案都是受歡迎的,但樣例代碼不能正常工作仍然很奇怪。
太好了,謝謝。我們將審查和更新我們的示例代碼。 – Ryan