[英]How can I transform DOCX to PDF with Microsoft Print to PDF in C#?
I'm trying to convert DOCX to PDF with "Microsoft Print to PDF" in C#. 我正在尝试使用C#中的“Microsoft Print to PDF”将DOCX转换为PDF。 Some objects of my document are drawings and i can't "Save As" without destructuration.
我的文档中的某些对象是图纸,我不能在没有破坏的情况下“另存为”。
With a printing "Microsoft Print to PDF", all is fine so I want to do this action with my C# program. 打印“Microsoft Print to PDF”,一切都很好,所以我想用我的C#程序做这个动作。 I've 3000 files to process.
我有3000个文件要处理。
I'm trying this code. 我正在尝试这段代码。 It executes a PDF printing and create the wrong file but, it's only blank pages.
它执行PDF打印并创建错误的文件,但它只是空白页面。
//path is my docx path
Application appWord = new Application();
wordDocument = appWord.Documents.Open(path);
PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = "Microsoft Print to PDF";
pd.PrinterSettings.PrintToFile = true;
pd.PrinterSettings.PrintFileName = pdf_path;
pd.Print();
I'm thinking I miss something by I don't understand what. 我想我错过了一些我不明白的东西。 And I don't know if the
wordDocument
can be the streamReader
in some examples on Internet. 而且我不知道
streamReader
在Internet上的某些示例中wordDocument
可以是streamReader
。
Thanks for your help ! 谢谢你的帮助 !
Thanks for all your aswers. 谢谢你所有的驴子。
This (simple) lines work fine : 这(简单)行很好用:
Application appWord = new Application();
wordDocument = appWord.Documents.Open(path);
wordDocument.PrintOut(
OutputFileName:pdf_path,
PrintToFile: true
);
path
is my docx source path path
是我的docx源路径
pdf_path
is the destination pdf file path pdf_path
是目标pdf文件路径
I hope this topic can help someone. 我希望这个话题可以帮助别人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.