在.NET中打印到XPS文件时如何默认文件名
从我的.NET应用程序中选择Microsoft XPS Document Writer进行打印时,将向用户显示一个文件对话框,其中文件名最初为"* .XPS".我希望它默认使用一个更有用的名称(理想情况下,使用我提供的文档名称).
When the Microsoft XPS Document Writer is selected for printing from my .NET application, the user is presented with a file dialog where the file name is initially "*.XPS". I'd like it to default to a more useful name instead (ideally, using the document name I am providing).
我阅读了以下问题:
...并尝试按照答案中的建议设置PrinterSettings.PrintFileName,但这似乎不起作用...
...and tried setting the PrinterSettings.PrintFileName as suggested in the answers, but it does not seem to work...
PrintDialog printDlg = new PrintDialog();
PrintDocument printDoc = new PrintDocument();
printDoc.DocumentName = name;
printDlg.Document = printDoc;
printDlg.AllowSelection = true;
printDlg.AllowSomePages = true;
//Call ShowDialog
if (printDlg.ShowDialog() == DialogResult.OK)
{
if (!printDoc.PrinterSettings.IsValid)
{
throw new Exception("Error: cannot find the default printer.");
}
else
{
if (printDoc.PrinterSettings.PrinterName.Contains("XPS"))
{
printDoc.PrinterSettings.PrintFileName = name + ".XPS";
}
// Actual printing code from this point onward...
如果我打印到Adobe PDF,则默认文件名为打印文档名称+".PDF"(理想行为),但是内置XPS打印驱动程序似乎缺少此功能,甚至似乎忽略了PrintFileName属性.我是在做错什么,还是XPS打印驱动程序有问题?
If I print to Adobe PDF, it defaults the file name to the print document name + ".PDF" (ideal behavior), but the built-in XPS print driver seems to lack this feature, and even seems to be ignoring the PrintFileName property. Am I doing something wrong, or is this an issue with the XPS print driver?
顺便说一句,我正在Vista Business SP2上使用VS 2010/.NET 4.0(均为SP1)
BTW, I am using VS 2010 / .NET 4.0 (both SP1) on Vista Business SP2
我相信这是XPS Document Writer的局限性. Win2PDF 打印机驱动程序可以另存为XPS ,默认使用打印文档名称.您可以尝试使用它代替Microsoft XPS Document Writer.
I believe this is a limitation of the XPS Document Writer. The Win2PDF printer driver can save as XPS, and defaults to using the print document name. You could try using it instead of the Microsoft XPS Document Writer.