![](/img/trans.png)
[英]how can i open .pdf file in office word 2013(in c#) and save as it in .docx (code in c#)?
[英]How can I transform DOCX to PDF with Microsoft Print to PDF in C#?
我正在尝试使用C#中的“Microsoft Print to PDF”将DOCX转换为PDF。 我的文档中的某些对象是图纸,我不能在没有破坏的情况下“另存为”。
打印“Microsoft Print to PDF”,一切都很好,所以我想用我的C#程序做这个动作。 我有3000个文件要处理。
我正在尝试这段代码。 它执行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();
我想我错过了一些我不明白的东西。 而且我不知道streamReader
在Internet上的某些示例中wordDocument
可以是streamReader
。
谢谢你的帮助 !
谢谢你所有的驴子。
这(简单)行很好用:
Application appWord = new Application();
wordDocument = appWord.Documents.Open(path);
wordDocument.PrintOut(
OutputFileName:pdf_path,
PrintToFile: true
);
path
是我的docx源路径
pdf_path
是目标pdf文件路径
我希望这个话题可以帮助别人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.