Me gustaría tener la forma más rápida de exportar mi informe..docxarchivo a.pdfy distribuirlo a otros cada vez que tenga una versión nueva y actualizada.
Estoy buscando un enfoque de línea de comandos que automatice los siguientes pasos que hasta ahora tengo que realizar manualmente con el mouse:
File -> Save as -> Browse for location
¿Cuáles son mis opciones de comando para un archivo por lotes?
Respuesta1
Cree una macro global en Word 2013:
' The Word macro for exporting to PDF (the Word window closes after finishing)
Sub ExportToPDFext()
ChangeFileOpenDirectory ThisDocument.Path
ActiveDocument.ExportAsFixedFormat _
OutputFileName:=Left(ActiveDocument.FullName, InStrRev(ActiveDocument.FullName, ".")) + "pdf", _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, _
From:=1, _
To:=1, _
Item:=wdExportDocumentContent, _
IncludeDocProps:=True, _
KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=False
Application.Quit SaveChanges:=wdDoNotSaveChanges
End Sub
Después de eso, puedes convertir un documento de Word a PDF en la línea de comando:
"C:\Program Files\Microsoft Office\Office15\WINWORD.EXE" /mExportToPDFext /q "your_document_path.docx"
La ventana de Word ni siquiera aparecerá porque está configurada para cerrarse después de que la macro termine de funcionar, y el parámetro /q desactiva la ventana de presentación cuando se carga Word.
Aquí están las instrucciones detalladas alternativas.en GitHub. Además, la opción del menú contextual permite la conversión por lotes incluso sin la línea de comando. Se puede agregar al registro. Para DOC y DOCX:
[HKEY_CLASSES_ROOT\Word.Document.8\shell\SavePDFhere]
@="Save PDF here"
[HKEY_CLASSES_ROOT\Word.Document.8\shell\SavePDFhere\command]
@="\"C:\\Program Files\\Microsoft Office\\Office15\\WINWORD.EXE\" /mExportToPDFext /q \"%1\""
[HKEY_CLASSES_ROOT\Word.Document.12\shell\SavePDFhere]
@="Save PDF here"
[HKEY_CLASSES_ROOT\Word.Document.12\shell\SavePDFhere\command]
@="\"C:\\Program Files\\Microsoft Office\\Office15\\WINWORD.EXE\" /mExportToPDFext /q \"%1\""
Respuesta2
Para obtener una herramienta de línea de comandos sencilla para convertir por lotes, puede utilizar docx2pdf
:https://github.com/AlJohri/docx2pdf/
Instalar:
pip install docx2pdf
Correr:
docx2pdf myFolderOfWordDocs
Descargo de responsabilidad: soy el autor de esta herramienta.
Respuesta3
Aquí está la solución deOleksiy Kovtunadoptado al actual Office 16 (Office 360).
En la macro de Word tuve que cambiar ThisDocument.Path
a ActiveDocument.Path
.
' The Word macro for exporting to PDF (the Word window closes after finishing)
Sub ExportToPDFext()
ChangeFileOpenDirectory ActiveDocument.Path
ActiveDocument.ExportAsFixedFormat _
OutputFileName:=Left(ActiveDocument.FullName, InStrRev(ActiveDocument.FullName, ".")) + "pdf", _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, _
From:=1, _
To:=1, _
Item:=wdExportDocumentContent, _
IncludeDocProps:=True, _
KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=False
Application.Quit SaveChanges:=wdDoNotSaveChanges
End Sub
Para el registro, Office 16 utiliza rutas ligeramente diferentes:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Word.Document.8\shell\SavePDFhere]
@="Save PDF here"
[HKEY_CLASSES_ROOT\Word.Document.8\shell\SavePDFhere\command]
@="\"C:\\Program Files\\Microsoft Office\\root\\Office16\\WINWORD.EXE\" /mExportToPDFext /q \"%1\""
[HKEY_CLASSES_ROOT\Word.Document.12\shell\SavePDFhere]
@="Save PDF here"
[HKEY_CLASSES_ROOT\Word.Document.12\shell\SavePDFhere\command]
@="\"C:\\Program Files\\Microsoft Office\\root\\Office16\\WINWORD.EXE\" /mExportToPDFext /q \"%1\""