能不能一次性将所有的word文件全部转化成pdf,当然,还需要按节转化为多个pdf文件
可以用python 实现哦
可以借助Word类库来处理,比如spire.doc。看你用C#还是Java, 选择spire.doc for .net 或者spire.doc for java来批量转换word到pdf。
你提到的按节转换也很简单:1. 将 word按节拆分成多个文档 2.再将若干文档分别转换成pdf
以Java为例, 按节拆分word:
https://www.e-iceblue.cn/spiredocforjavaoperating/split-word-by-section-in-java.html
转换word到pdf:
https://www.e-iceblue.cn/spiredocforjavaconversion/java-convert-word-to-pdf.html
Sub 选择文件()
Dim fd As FileDialog
Dim myFileName
Dim i As Integer
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = True
.Title = "选择Word文件"
.Filters.Clear
.Filters.Add "Word文件", "*.doc*;*.dot*", 1
If .Show Then
For Each myFileName In .SelectedItems
Call 按节导出PDF(myFileName)
Debug.Print myFileName, "导出完成"
i = i + 1
Next
End If
End With
Set fd = Nothing
MsgBox "完成,共分节导出了" & i & "个Word文件。"
End Sub
Function 按节导出PDF(myFileName)
Dim aDoc As Document
Dim sec As Section
Dim i As Long
Dim c1 As Boolean
Dim c2 As Boolean
Application.ScreenUpdating = False
Set aDoc = Documents.Open(fileName:=myFileName)
For Each sec In aDoc.Sections
i = i + 1
sec.Range.Select
c1 = (Right(Selection.text, 1) = Chr(12))
c2 = (Right(Selection.text, 2) = Chr(12) & Chr(13))
Do While c1 Or c2
If c1 Then
Selection.MoveLeft wdCharacter, 1, wdExtend
ElseIf c2 Then
Selection.MoveLeft wdCharacter, 2, wdExtend
End If
c1 = (Right(Selection.text, 1) = Chr(12))
c2 = (Right(Selection.text, 2) = Chr(12) & Chr(13))
Loop
Selection.ExportAsFixedFormat outputfilename:=aDoc.Path & "\" & CreateObject("Scripting.FileSystemObject").GetBaseName(myFileName) & "_节" & i & ".pdf", _
openafterexport:=False, ExportFormat:=wdExportFormatPDF, OptimizeFor:= _
wdExportOptimizeForPrint, ExportCurrentPage:=False, Item:= _
wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True
Next
aDoc.Close wdDoNotSaveChanges
Application.ScreenUpdating = True
Set aDoc = Nothing
Set sec = Nothing
End Function