[英]Convert word document to pdf using CutePdf programatically in C#
I have the following code to convert word document to pdf using CutePdf Writer 我有以下代码使用CutePdf Writer将Word文档转换为pdf
PrintDialog pDia = new PrintDialog();
PrinterSettings ps = new PrinterSettings();
pDia.Document = printDocumentMessageBoxTest;
pDia.Document.DocumentName = "C:\\FinalGap.doc";
ps.PrinterName = "CutePDF Writer";
ps.PrintToFile = true;
ps.PrintFileName = "C:\\" + Path.GetFileNameWithoutExtension(pDia.Document.DocumentName) + ".pdf";
// take printer settings from the dialog and set into the PrintDocument object
pDia.Document.OriginAtMargins = true;
ps.DefaultPageSettings.Margins.Left = 2;
//printDocumentMessageBoxTest.PrinterSettings = ps;
// start the printing process, catch exceptions
try
{
printDocumentMessageBoxTest.Print();
}
catch (Exception exc)
{
MessageBox.Show("Printing error!\n" + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
When I run the application, it is printing the word document bu the output file is not generated. 当我运行该应用程序时,它正在打印word文档,但不会生成输出文件。 Can anyone tell me how to convert word document to pdf using CUTEPDF programatically and waht's wrong with the above code?
谁能告诉我如何通过CUTEPDF程序将Word文档转换为pdf,而上述代码有错吗?
CutePdf Writer does not support automation. CutePdf Writer不支持自动化。 You can't use it the manner you are trying to use it.
您不能以尝试使用它的方式使用它。 You can purchase Custom Pdf Writer from them, then you code will be something like this:
您可以从他们那里购买Custom Pdf Writer ,然后编写如下代码:
string regKey = @"HKEY_CURRENT_USER\Software\Custom PDF Printer";
Registry.SetValue(regKey, "OutputFile", @"C:\Sample.pdf", RegistryValueKind.String);
Registry.SetValue(regKey, "BypassSaveAs", @"1", RegistryValueKind.String);
Application wordApp = new Word.Application();
Document wordDoc = wordApp.Documents.Open(@"C:\test.doc");
wordApp.ActivePrinter = "Custom PDF Printer";
wordApp.PrintOut();
wordDoc.Close();
Registry.SetValue(regKey, "BypassSaveAs", @"0", RegistryValueKind.String);
Also see: 另请参阅:
I personally used ABCPdf for a project and I liked it, however my goal was convert not from doc but from html to pdf and the component were not free. 我个人将ABCPdf用于一个项目,但我很喜欢,但是我的目标不是从doc而是从html转换为pdf,并且该组件不是免费的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.