Diferencia entre revisiones de «Word y PowerPoint a PDF»
Ir a la navegación
Ir a la búsqueda
(Página creada con «Este [http://www.suodenjoki.dk/us/productions/articles/word2pdf.htm artículo] presenta un método para convertir documentos Word a PDF de forma facil. Yo modifiqué el co...») |
Sin resumen de edición |
||
Línea 6: | Línea 6: | ||
También cree una variante para PowerPoint. | También cree una variante para PowerPoint. | ||
---- | |||
<pre> | |||
'************************************************ | |||
' | |||
' DOC2PDF.VBS Microsoft Scripting Host Script (Requires Version 5.6 or newer) | |||
' -------------------------------------------------------------------------------- | |||
' | |||
' Author: Michael Suodenjoki | |||
' Created: 2007.07.07 | |||
' | |||
' This script can create a PDF file from a Word document provided you're using | |||
' Word 2007 and have the 'Office Add-in: Save As PDF' installed. | |||
' | |||
' Constants | |||
Const WdDoNotSaveChanges = 0 | |||
' see WdSaveFormat enumeration constants: | |||
' http://msdn2.microsoft.com/en-us/library/bb238158.aspx | |||
Const wdFormatPDF = 17 ' PDF format. | |||
Const wdFormatXPS = 18 ' XPS format. | |||
' Global variables | |||
Dim arguments | |||
Set arguments = WScript.Arguments | |||
' *********************************************** | |||
' ECHOLOGO | |||
' | |||
' Outputs the logo information. | |||
' | |||
Function EchoLogo() | |||
End Function | |||
' *********************************************** | |||
' ECHOUSAGE | |||
' | |||
' Outputs the usage information. | |||
' | |||
Function EchoUsage() | |||
If arguments.Count=0 Or arguments.Named.Exists("help") Or _ | |||
arguments.Named.Exists("h") _ | |||
Then | |||
WScript.Echo "Generates a PDF from a Word document file using Word 2007." | |||
WScript.Echo "" | |||
WScript.Echo "Usage: doc2pdf.vbs <options> <doc-file> [/o:<pdf-file>]" | |||
WScript.Echo "" | |||
WScript.Echo "Available Options:" | |||
WScript.Echo "" | |||
WScript.Echo " /nologo - Specifies that the logo shouldn't be displayed" | |||
WScript.Echo " /help - Specifies that this usage/help information " + _ | |||
"should be displayed." | |||
WScript.Echo " /debug - Specifies that debug output should be displayed." | |||
WScript.Echo "" | |||
WScript.Echo "Parameters:" | |||
WScript.Echo "" | |||
WScript.Echo " /o:<pdf-file> Optionally specification of output file (PDF)." | |||
WScript.Echo "" | |||
End If | |||
End Function | |||
' *********************************************** | |||
' CHECKARGS | |||
' | |||
' Makes some preliminary checks of the arguments. | |||
' Quits the application is any problem is found. | |||
' | |||
Function CheckArgs() | |||
' Check that <doc-file> is specified | |||
If arguments.Unnamed.Count <> 1 Then | |||
WScript.Echo "Error: Obligatory <doc-file> parameter missing!" | |||
WScript.Quit 1 | |||
End If | |||
bShowDebug = arguments.Named.Exists("debug") Or arguments.Named.Exists("d") | |||
End Function | |||
' *********************************************** | |||
' DOC2PDF | |||
' | |||
' Converts a Word document to PDF using Word 2007. | |||
' | |||
' Input: | |||
' sDocFile - Full path to Word document. | |||
' sPDFFile - Optional full path to output file. | |||
' | |||
' If not specified the output PDF file | |||
' will be the same as the sDocFile except | |||
' file extension will be .pdf. | |||
' | |||
Function DOC2PDF( sDocFile, sPDFFile ) | |||
Dim fso ' As FileSystemObject | |||
Dim wdo ' As PowerPoint.Application | |||
Dim wdoc ' As PowerPoint.Presentation | |||
Dim wdocs ' As PowerPoint.Presentations | |||
Dim sPrevPrinter ' As String | |||
Set fso = CreateObject("Scripting.FileSystemObject") | |||
Set wdo = CreateObject("PowerPoint.Application") | |||
Set wdocs = wdo.Presentations | |||
sDocFile = fso.GetAbsolutePathName(sDocFile) | |||
' Debug outputs... | |||
If bShowDebug Then | |||
WScript.Echo "Doc file = '" + sDocFile + "'" | |||
WScript.Echo "PDF file = '" + sPDFFile + "'" | |||
End If | |||
sFolder = fso.GetParentFolderName(sDocFile) | |||
If Len(sPDFFile)=0 Then | |||
sPDFFile = fso.GetBaseName(sDocFile) + ".pdf" | |||
End If | |||
If Len(fso.GetParentFolderName(sPDFFile))=0 Then | |||
sPDFFile = sFolder + "\" + sPDFFile | |||
End If | |||
' Enable this line if you want to disable autoexecute macros | |||
' wdo.WordBasic.DisableAutoMacros | |||
' Open the Word document | |||
Set wdoc = wdocs.Open(sDocFile) | |||
' Let Word document save as PDF | |||
' - for documentation of SaveAs() method, | |||
' see http://msdn.microsoft.com/en-us/library/bb251061%28v=office.12%29.aspx | |||
wdoc.SaveAs sPDFFile, 32 | |||
wdoc.Close | |||
wdo.Quit | |||
Set wdo = Nothing | |||
Set fso = Nothing | |||
End Function | |||
' *** MAIN ************************************** | |||
Call EchoLogo() | |||
Call EchoUsage() | |||
Call CheckArgs() | |||
Call DOC2PDF( arguments.Unnamed.Item(0), arguments.Named.Item("o") ) | |||
Set arguments = Nothing</pre> | |||
---- | |||
<pre> | |||
'************************************************ | |||
' | |||
' DOC2PDF.VBS Microsoft Scripting Host Script (Requires Version 5.6 or newer) | |||
' -------------------------------------------------------------------------------- | |||
' | |||
' Author: Michael Suodenjoki | |||
' Created: 2007.07.07 | |||
' | |||
' This script can create a PDF file from a Word document provided you're using | |||
' Word 2007 and have the 'Office Add-in: Save As PDF' installed. | |||
' | |||
' Constants | |||
Const WdDoNotSaveChanges = 0 | |||
' see WdSaveFormat enumeration constants: | |||
' http://msdn2.microsoft.com/en-us/library/bb238158.aspx | |||
Const wdFormatPDF = 17 ' PDF format. | |||
Const wdFormatXPS = 18 ' XPS format. | |||
' Global variables | |||
Dim arguments | |||
Set arguments = WScript.Arguments | |||
' *********************************************** | |||
' ECHOLOGO | |||
' | |||
' Outputs the logo information. | |||
' | |||
Function EchoLogo() | |||
End Function | |||
' *********************************************** | |||
' ECHOUSAGE | |||
' | |||
' Outputs the usage information. | |||
' | |||
Function EchoUsage() | |||
If arguments.Count=0 Or arguments.Named.Exists("help") Or _ | |||
arguments.Named.Exists("h") _ | |||
Then | |||
WScript.Echo "Generates a PDF from a Word document file using Word 2007." | |||
WScript.Echo "" | |||
WScript.Echo "Usage: doc2pdf.vbs <options> <doc-file> [/o:<pdf-file>]" | |||
WScript.Echo "" | |||
WScript.Echo "Available Options:" | |||
WScript.Echo "" | |||
WScript.Echo " /nologo - Specifies that the logo shouldn't be displayed" | |||
WScript.Echo " /help - Specifies that this usage/help information " + _ | |||
"should be displayed." | |||
WScript.Echo " /debug - Specifies that debug output should be displayed." | |||
WScript.Echo "" | |||
WScript.Echo "Parameters:" | |||
WScript.Echo "" | |||
WScript.Echo " /o:<pdf-file> Optionally specification of output file (PDF)." | |||
WScript.Echo "" | |||
End If | |||
End Function | |||
' *********************************************** | |||
' CHECKARGS | |||
' | |||
' Makes some preliminary checks of the arguments. | |||
' Quits the application is any problem is found. | |||
' | |||
Function CheckArgs() | |||
' Check that <doc-file> is specified | |||
If arguments.Unnamed.Count <> 1 Then | |||
WScript.Echo "Error: Obligatory <doc-file> parameter missing!" | |||
WScript.Quit 1 | |||
End If | |||
bShowDebug = arguments.Named.Exists("debug") Or arguments.Named.Exists("d") | |||
End Function | |||
' *********************************************** | |||
' DOC2PDF | |||
' | |||
' Converts a Word document to PDF using Word 2007. | |||
' | |||
' Input: | |||
' sDocFile - Full path to Word document. | |||
' sPDFFile - Optional full path to output file. | |||
' | |||
' If not specified the output PDF file | |||
' will be the same as the sDocFile except | |||
' file extension will be .pdf. | |||
' | |||
Function DOC2PDF( sDocFile, sPDFFile ) | |||
Dim fso ' As FileSystemObject | |||
Dim wdo ' As Word.Application | |||
Dim wdoc ' As Word.Document | |||
Dim wdocs ' As Word.Documents | |||
Dim sPrevPrinter ' As String | |||
Set fso = CreateObject("Scripting.FileSystemObject") | |||
Set wdo = CreateObject("Word.Application") | |||
Set wdocs = wdo.Documents | |||
sDocFile = fso.GetAbsolutePathName(sDocFile) | |||
' Debug outputs... | |||
If bShowDebug Then | |||
WScript.Echo "Doc file = '" + sDocFile + "'" | |||
WScript.Echo "PDF file = '" + sPDFFile + "'" | |||
End If | |||
sFolder = fso.GetParentFolderName(sDocFile) | |||
If Len(sPDFFile)=0 Then | |||
sPDFFile = fso.GetBaseName(sDocFile) + ".pdf" | |||
End If | |||
If Len(fso.GetParentFolderName(sPDFFile))=0 Then | |||
sPDFFile = sFolder + "\" + sPDFFile | |||
End If | |||
' Enable this line if you want to disable autoexecute macros | |||
' wdo.WordBasic.DisableAutoMacros | |||
' Open the Word document | |||
Set wdoc = wdocs.Open(sDocFile) | |||
' Let Word document save as PDF | |||
' - for documentation of SaveAs() method, | |||
' see http://msdn2.microsoft.com/en-us/library/bb221597.aspx | |||
wdoc.SaveAs sPDFFile, wdFormatPDF | |||
wdoc.Close WdDoNotSaveChanges | |||
wdo.Quit WdDoNotSaveChanges | |||
Set wdo = Nothing | |||
Set fso = Nothing | |||
End Function | |||
' *** MAIN ************************************** | |||
Call EchoLogo() | |||
Call EchoUsage() | |||
Call CheckArgs() | |||
Call DOC2PDF( arguments.Unnamed.Item(0), arguments.Named.Item("o") ) | |||
Set arguments = Nothing | |||
</pre> | |||
---- | |||
[[Category:Tips]] | [[Category:Tips]] | ||
[[Category:Windows]] | [[Category:Windows]] |
Revisión del 15:47 29 mar 2018
Este artículo presenta un método para convertir documentos Word a PDF de forma facil.
Yo modifiqué el codigo ligeramente para que no pregunte nada y sea mas automático.
Para usarlo basta con tenerlo en el Escritorio y arrastrar un documento Word y soltarlo sobre el icono del programa.
También cree una variante para PowerPoint.
'************************************************ ' ' DOC2PDF.VBS Microsoft Scripting Host Script (Requires Version 5.6 or newer) ' -------------------------------------------------------------------------------- ' ' Author: Michael Suodenjoki ' Created: 2007.07.07 ' ' This script can create a PDF file from a Word document provided you're using ' Word 2007 and have the 'Office Add-in: Save As PDF' installed. ' ' Constants Const WdDoNotSaveChanges = 0 ' see WdSaveFormat enumeration constants: ' http://msdn2.microsoft.com/en-us/library/bb238158.aspx Const wdFormatPDF = 17 ' PDF format. Const wdFormatXPS = 18 ' XPS format. ' Global variables Dim arguments Set arguments = WScript.Arguments ' *********************************************** ' ECHOLOGO ' ' Outputs the logo information. ' Function EchoLogo() End Function ' *********************************************** ' ECHOUSAGE ' ' Outputs the usage information. ' Function EchoUsage() If arguments.Count=0 Or arguments.Named.Exists("help") Or _ arguments.Named.Exists("h") _ Then WScript.Echo "Generates a PDF from a Word document file using Word 2007." WScript.Echo "" WScript.Echo "Usage: doc2pdf.vbs <options> <doc-file> [/o:<pdf-file>]" WScript.Echo "" WScript.Echo "Available Options:" WScript.Echo "" WScript.Echo " /nologo - Specifies that the logo shouldn't be displayed" WScript.Echo " /help - Specifies that this usage/help information " + _ "should be displayed." WScript.Echo " /debug - Specifies that debug output should be displayed." WScript.Echo "" WScript.Echo "Parameters:" WScript.Echo "" WScript.Echo " /o:<pdf-file> Optionally specification of output file (PDF)." WScript.Echo "" End If End Function ' *********************************************** ' CHECKARGS ' ' Makes some preliminary checks of the arguments. ' Quits the application is any problem is found. ' Function CheckArgs() ' Check that <doc-file> is specified If arguments.Unnamed.Count <> 1 Then WScript.Echo "Error: Obligatory <doc-file> parameter missing!" WScript.Quit 1 End If bShowDebug = arguments.Named.Exists("debug") Or arguments.Named.Exists("d") End Function ' *********************************************** ' DOC2PDF ' ' Converts a Word document to PDF using Word 2007. ' ' Input: ' sDocFile - Full path to Word document. ' sPDFFile - Optional full path to output file. ' ' If not specified the output PDF file ' will be the same as the sDocFile except ' file extension will be .pdf. ' Function DOC2PDF( sDocFile, sPDFFile ) Dim fso ' As FileSystemObject Dim wdo ' As PowerPoint.Application Dim wdoc ' As PowerPoint.Presentation Dim wdocs ' As PowerPoint.Presentations Dim sPrevPrinter ' As String Set fso = CreateObject("Scripting.FileSystemObject") Set wdo = CreateObject("PowerPoint.Application") Set wdocs = wdo.Presentations sDocFile = fso.GetAbsolutePathName(sDocFile) ' Debug outputs... If bShowDebug Then WScript.Echo "Doc file = '" + sDocFile + "'" WScript.Echo "PDF file = '" + sPDFFile + "'" End If sFolder = fso.GetParentFolderName(sDocFile) If Len(sPDFFile)=0 Then sPDFFile = fso.GetBaseName(sDocFile) + ".pdf" End If If Len(fso.GetParentFolderName(sPDFFile))=0 Then sPDFFile = sFolder + "\" + sPDFFile End If ' Enable this line if you want to disable autoexecute macros ' wdo.WordBasic.DisableAutoMacros ' Open the Word document Set wdoc = wdocs.Open(sDocFile) ' Let Word document save as PDF ' - for documentation of SaveAs() method, ' see http://msdn.microsoft.com/en-us/library/bb251061%28v=office.12%29.aspx wdoc.SaveAs sPDFFile, 32 wdoc.Close wdo.Quit Set wdo = Nothing Set fso = Nothing End Function ' *** MAIN ************************************** Call EchoLogo() Call EchoUsage() Call CheckArgs() Call DOC2PDF( arguments.Unnamed.Item(0), arguments.Named.Item("o") ) Set arguments = Nothing
'************************************************ ' ' DOC2PDF.VBS Microsoft Scripting Host Script (Requires Version 5.6 or newer) ' -------------------------------------------------------------------------------- ' ' Author: Michael Suodenjoki ' Created: 2007.07.07 ' ' This script can create a PDF file from a Word document provided you're using ' Word 2007 and have the 'Office Add-in: Save As PDF' installed. ' ' Constants Const WdDoNotSaveChanges = 0 ' see WdSaveFormat enumeration constants: ' http://msdn2.microsoft.com/en-us/library/bb238158.aspx Const wdFormatPDF = 17 ' PDF format. Const wdFormatXPS = 18 ' XPS format. ' Global variables Dim arguments Set arguments = WScript.Arguments ' *********************************************** ' ECHOLOGO ' ' Outputs the logo information. ' Function EchoLogo() End Function ' *********************************************** ' ECHOUSAGE ' ' Outputs the usage information. ' Function EchoUsage() If arguments.Count=0 Or arguments.Named.Exists("help") Or _ arguments.Named.Exists("h") _ Then WScript.Echo "Generates a PDF from a Word document file using Word 2007." WScript.Echo "" WScript.Echo "Usage: doc2pdf.vbs <options> <doc-file> [/o:<pdf-file>]" WScript.Echo "" WScript.Echo "Available Options:" WScript.Echo "" WScript.Echo " /nologo - Specifies that the logo shouldn't be displayed" WScript.Echo " /help - Specifies that this usage/help information " + _ "should be displayed." WScript.Echo " /debug - Specifies that debug output should be displayed." WScript.Echo "" WScript.Echo "Parameters:" WScript.Echo "" WScript.Echo " /o:<pdf-file> Optionally specification of output file (PDF)." WScript.Echo "" End If End Function ' *********************************************** ' CHECKARGS ' ' Makes some preliminary checks of the arguments. ' Quits the application is any problem is found. ' Function CheckArgs() ' Check that <doc-file> is specified If arguments.Unnamed.Count <> 1 Then WScript.Echo "Error: Obligatory <doc-file> parameter missing!" WScript.Quit 1 End If bShowDebug = arguments.Named.Exists("debug") Or arguments.Named.Exists("d") End Function ' *********************************************** ' DOC2PDF ' ' Converts a Word document to PDF using Word 2007. ' ' Input: ' sDocFile - Full path to Word document. ' sPDFFile - Optional full path to output file. ' ' If not specified the output PDF file ' will be the same as the sDocFile except ' file extension will be .pdf. ' Function DOC2PDF( sDocFile, sPDFFile ) Dim fso ' As FileSystemObject Dim wdo ' As Word.Application Dim wdoc ' As Word.Document Dim wdocs ' As Word.Documents Dim sPrevPrinter ' As String Set fso = CreateObject("Scripting.FileSystemObject") Set wdo = CreateObject("Word.Application") Set wdocs = wdo.Documents sDocFile = fso.GetAbsolutePathName(sDocFile) ' Debug outputs... If bShowDebug Then WScript.Echo "Doc file = '" + sDocFile + "'" WScript.Echo "PDF file = '" + sPDFFile + "'" End If sFolder = fso.GetParentFolderName(sDocFile) If Len(sPDFFile)=0 Then sPDFFile = fso.GetBaseName(sDocFile) + ".pdf" End If If Len(fso.GetParentFolderName(sPDFFile))=0 Then sPDFFile = sFolder + "\" + sPDFFile End If ' Enable this line if you want to disable autoexecute macros ' wdo.WordBasic.DisableAutoMacros ' Open the Word document Set wdoc = wdocs.Open(sDocFile) ' Let Word document save as PDF ' - for documentation of SaveAs() method, ' see http://msdn2.microsoft.com/en-us/library/bb221597.aspx wdoc.SaveAs sPDFFile, wdFormatPDF wdoc.Close WdDoNotSaveChanges wdo.Quit WdDoNotSaveChanges Set wdo = Nothing Set fso = Nothing End Function ' *** MAIN ************************************** Call EchoLogo() Call EchoUsage() Call CheckArgs() Call DOC2PDF( arguments.Unnamed.Item(0), arguments.Named.Item("o") ) Set arguments = Nothing