使用 SHMGVW.DLL 从命令行打印 EMF (WMF)
对于 Windows XP / Windows Server 2003,
我尝试使用 Windows 图片和传真查看器 (shimgvw.dll) 从命令行将 EMF(或 WMF)文件格式打印到虚拟打印机“Microsoft XPS Document Writer”。 我希望生成的 XPS 为矢量格式,就像 WMF/EMF 一样。
它适用于除 WMF 和 EMF 之外的所有图像格式。 出现 XPS 打印机保存对话框,但保存的 XPS 文件为空。
如果我加载 WMF 并从 Windows Picture 和 FaxViewer GUI 单击“文件”>“打印”,但不能从命令行单击,则可以执行此操作。 另外,如果我在 Windows 资源管理器中右键单击 WMF 文件并单击“打印”,则将不允许选择打印 WMF 文件(它会从列表中过滤掉 WMF 和 EMF 文件)。
代码:
<代码> ProcessStartInfo info = new ProcessStartInfo();
info.FileName = @"C:\WINDOWS\System32\rundll32.exe";
info.Arguments = @"C:\WINDOWS\System32\shimgvw.dll,ImageView_PrintTo /pt ""c:\vectorImage.emf"" ""Microsoft XPS 文档编写器""";
进程.开始(信息);
我不久前读过很多有关 WMF 漏洞的文章,只能假设这些文件的直接打印已被删除? 但是,如果我可以从 GUI 打印这些 WMF 文件,那么我就看不出如何避免该漏洞。
我想要做的是以编程方式从 WMF/EMF 文件创建 XPS 矢量文件,无需用户交互。我想我应该能够做到这一点,因为涉及的所有格式都属于 Microsoft。
For Windows XP / Windows Server 2003
I'm trying to print an EMF(or WMF) file format to the virtual printer "Microsoft XPS Document Writer" using Windows Picture and Fax Viewer (shimgvw.dll) from the command line. I want the resulting XPS to be in vector format, like the WMF/EMF is.
It works with all image formats except WMF and EMF. The XPS printer save dialog appears but the XPS file that is saved is empty.
I can do it if I load the WMF and click File>Print from the Windows Picture and FaxViewer GUI, but not from the command line. Also if I right click on the WMF file in Windows Explorer and click Print it will not allow the WMF file selected to print (it filters WMF and EMF files out of the list).
Code:
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = @"C:\WINDOWS\System32\rundll32.exe";
info.Arguments = @"C:\WINDOWS\System32\shimgvw.dll,ImageView_PrintTo /pt ""c:\vectorImage.emf"" ""Microsoft XPS Document Writer""";
Process.Start(info);
I've read a lot about the WMF exploit a while back and can only assume that direct printing of these files has been removed? But if I can print these WMF files form the GUI then I don't see how the exploit was avoided.
What I want to do is create an XPS vector file from a WMF/EMF file programatically with no user interaction required. I would imagine that I should be able to do this because all formats involved belong to Microsoft.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看以下 C 语言示例,了解如何将 GDI 命令导入 XPS 文档:
http://blogs.msdn.com/fyuan/archive/ 2005/09/16/469076.aspx
你想要做的是创建打印机DC,调用StartDoc,调用StartPage,然后设置用于放置emf的视口和窗口比例,调用PlayEnhMetaFile(),EndPage,结束文档。
Feng Yuan 展示的技巧是使用 StartDoc 的 DocInfo 参数来指定输出 XPS 文件名,我建议您将图元文件内容播放到打印机 DC 中。
我相信 EMF 漏洞不久前已被 Microsoft 更新关闭。 您可能遇到的问题是由于 GDI 和 XPS 打印路径是分离的,并且在这种极端情况下缺乏桥接它们的努力。
-杰森
Take a look at the following example in C for how to get GDI commands into an XPS document:
http://blogs.msdn.com/fyuan/archive/2005/09/16/469076.aspx
What you want to do, is create the printer DC, call StartDoc, call StartPage, then setup the viewport and window scale for placing the emf, call PlayEnhMetaFile(), EndPage, EndDoc.
The trick Feng Yuan is presenting is using the DocInfo argument to StartDoc to specify the output XPS file name, and what I'm suggesting is that you play the metafile contents into the printer DC.
I believe the EMF exploit was closed a while back by Microsoft Update. The problem you are probably seeing is due to the GDI and XPS print paths being separate and a lack of effort to bridge them in this corner case.
-Jason