Nag*_*eep 3 c# pdf ms-word office-interop
背景:我正在尝试使用c#和Interop生成一个word文档.我成功地插入了表格,页眉,页脚,图表......大部分工作都很好.下一步,我希望将其转换为pdf.
流程改编:由于我使用的是word 2011和word 2007(安装saveaspdf插件之后),我使用"另存为"将文档保存为pdf,然后将文件类型保存为pdf.
引发的问题:我已使用以下代码成功地将pdf嵌入到我的文档中.
Object oIconLabel = new FileInfo(file_path).Name;
Object oFileDesignInfo = file_path;
Object oClassType = "AcroExch.Document.7";
Object oTrue = true;
Object oFalse = false;
Object oMissing = System.Reflection.Missing.Value;
Object index = 0;
Range r = d.Bookmarks.get_Item(ref eod).Range;
r.InlineShapes.AddOLEObject(
ref oClassType, ref oFileDesignInfo, ref oFalse, ref oTrue, ref oMissing,
ref index, ref oIconLabel, ref oMissing);
Run Code Online (Sandbox Code Playgroud)
这里d是Document对象.现在,当我尝试将此word文档保存为pdf时,使用
d.SaveAs(ref filename, ref filetype, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
Run Code Online (Sandbox Code Playgroud)
pdf正在生成.但是我嵌入的文档没有嵌入到生成的pdf中.而是只显示一个图标.
如何将文档嵌入pdf中.我们通常如何处理这种情况.如果问题不明确,请告诉我.
这是我选择的错误的选择.它不应该是SaveAs.它是ExportAsFixedFormat.
文档存在于此处
样品用量可以
d.ExportAsFixedFormat(filename.ToString(), WdExportFormat.wdExportFormatPDF,false,WdExportOptimizeFor.wdExportOptimizeForOnScreen,
WdExportRange.wdExportAllDocument,1,1,WdExportItem.wdExportDocumentContent,true,true,
WdExportCreateBookmarks.wdExportCreateHeadingBookmarks,true,true,false,ref oMissing);
Run Code Online (Sandbox Code Playgroud)
小智 5
这段代码非常适合我处理 Word 文档中的文本、表格、图表和图像。
需要在服务器上安装Word。
我用的是Word 2013,没问题。
Microsoft.Office.Interop.Word.Application wordApplication = new Microsoft.Office.Interop.Word.Application();
object oMissing = System.Reflection.Missing.Value;
Object oFalse = false;
Object filename = (Object)path;
Microsoft.Office.Interop.Word.Document doc = wordApplication.Documents.Open(ref filename, ref oMissing,
ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
doc.Activate();
var pathfilename = Path.Combine(Server.MapPath("~/UploadDocuments/PDF"), fileName).Replace(".docx", ".pdf"); ;
Object filename2 = (Object)pathfilename;
doc.SaveAs(ref filename2, WdSaveFormat.wdFormatPDF,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
// close word doc and word app.
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
((_Application)wordApplication).Quit(ref oMissing, ref oMissing, ref oMissing);
wordApplication = null;
doc = null;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10559 次 |
最近记录: |