没有PrintDialog无法打印 [英] Cannot print without PrintDialog
问题描述
我正在尝试使用PDF创建器作为默认打印机从WORD文档自动创建PDF文档.但是,我不想每次都使用PrintDialog,我需要通过源代码使其自动(我有成千上万的WORD文档).问题在于,似乎我无法继承PrintDialog附带的所有设置,并且可以
创建一个PDF文件,但它的大小为0kb.它引发所有PrintDocument事件
(BeginPrint,QueryPageSettings,PrintPage,EndPrint),但最终PDF文档为0kb.
有人遇到过这个问题吗?
这是带有静态字段的示例:
I''m trying to create automatically PDF documents from WORD documents, using a PDF creator as a default printer. However, I don''t want to use the PrintDialog everytime, I need to make it automatic by the source code ( I have thousands of WORD documents). The problem is that it seems I cannot inherit all the settings, coming with the PrintDialog and I can
create a PDF file but it''s 0kb. It raises all the PrintDocument events
(BeginPrint,QueryPageSettings,PrintPage,EndPrint), but finally the PDF document is 0kb.
Does anyone met this issue?
Here is a sample with static fields:
private void DocToPdf()
{
PrintDocument pdDoc = new PrintDocument();
try
{
pdDoc.DocumentName = @"C:\Input.doc";
pdDoc.PrinterSettings.PrintToFile = true;
pdDoc.PrinterSettings.PrintFileName = @"C:\Output.pdf";
pdDoc.PrinterSettings.PrinterName = "My_printer";
pdDoc.DefaultPageSettings = new PageSettings(new PrinterSettings());
pdDoc.PrintPage += new PrintPageEventHandler(pdDoc_PrintPage);
pdDoc.BeginPrint += new PrintEventHandler(pdDoc_BeginPrint);
pdDoc.QueryPageSettings += new QueryPageSettingsEventHandler(pdDoc_QueryPageSettings);
pdDoc.EndPrint += new PrintEventHandler(pdDoc_EndPrint);
if (pdDoc.PrinterSettings.IsValid)
pdDoc.Print();
}
catch (Exception ex)
{
string msg = ex.Message;
}
}
推荐答案
您确定您的PrintPage()
方法正确将数据写入输出设备吗?
Are you sure that your PrintPage()
method is correctly writing the data to the output device?
理查德,谢谢你的提示.实际上,我使用互操作函数解决了该问题.你的暗示使我意识到我走错了路. :)
Hi Richard, thanks for the hint. Actually I solved the problem using interop functions. Your hint helped me to realize that I''m on the wrong way . :)
这篇关于没有PrintDialog无法打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!