如何在使用C#从Word文档中导出PDF文件时保持表格布局

问题描述 投票:0回答:1

我正在尝试将包含表格的Word文档导出为PDF格式,导出成功完成,但是导出后表格的布局与之前不同。

从Word文档导出PDF文件时如何保持表格布局?

导出之前(Word格式):-

enter image description here

导出后(PDF格式:-

enter image description here

我使用的代码:-

doc.ExportAsFixedFormat(targetDocPathPDF, WdExportFormat.wdExportFormatPDF, false, WdExportOptimizeFor.wdExportOptimizeForOnScreen,
                     WdExportRange.wdExportAllDocument, 1, 1, WdExportItem.wdExportDocumentContent, true, true,
                     WdExportCreateBookmarks.wdExportCreateHeadingBookmarks, true, true, false, ref oMissing);

doc.ExportAsFixedFormat(targetDocPathPDF, WdExportFormat.wdExportFormatPDF);
Microsoft.Office.Interop.Word.WdSaveFormat wdSaveFmt = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
object oWdSaveFmt = wdSaveFmt, oSaveAsSpec = targetDocPathPDF;
doc.SaveAs2(ref oSaveAsSpec, ref oWdSaveFmt);
c# pdf office-interop
1个回答
0
投票

我遇到了类似的问题,并通过将列宽设置为小10%来解决了。它取消了Word文档中的格式,但PDF正确地出现了。

© www.soinside.com 2019 - 2024. All rights reserved.