Dim wjm As String = "纸质"
Dim app As New MSWord.Application
Dim fileName1 = "F:\CS20200310001\" & wjm & "水印.docx"
Dim fileName2 = "F:\CS20200310001\" & wjm & "水印2.docx"
FileSys.CopyFile(fileName1 , fileName2 ,True)
ShowAppWindow( wjm & "水印2.docx",5)
Dim doc = app.Documents.Open(fileName2)
'''添加水印,带页眉页脚
For i As Integer = 1 To 2
Output.Show("3.1---" & Date.Now)
doc.Activate
doc.Sections(1).Range.Select '数字为第几节
app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader '插入水印前需更改视图样式为页眉视图
app.Selection.HeaderFooter.Shapes.AddPicture(ProjectPath & "Images\yemei.png", False, True,-23, -20, 570, 85)
app.Selection.HeaderFooter.Shapes.AddPicture(ProjectPath & "Images\yejiao.png", False, True,-23, 760, 570, 50)
app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument '恢复视图样式到原来样式
Output.Show("3.2---" & Date.Now)
Dim rng As MSWord.Range = doc.Range(Start:=i, End:=i)
rng.copy
Dim doc2 = app.Documents.Open(fileName2.replace(".docx", i & "000.docx"))
doc2.Content.Paste()
doc2.save
'app.Documents(fileName2.replace(".docx","." & i & "docx")).ExportAsFixedFormat(fileName2.replace(".docx","." & i & "pdf")), MSWord.WdExportFormat.wdExportFormatPDF)
Output.Show("3.3---" & Date.Now)
Next
app.Quit
老师,会提示下面这个错误
我希望得到的结果是,比如一份文档有4页,前2页导出为一份pdf文件,后2页也导出为1份pdf文件
上面蓝色的代码是整份文档导出为pdf,而不是单页pdf

此主题相关图片如下:微信截图_20220318120012.png
