From cc436650ab631e094db0d79ce1aaf3ffe2a58a6d Mon Sep 17 00:00:00 2001 From: Rafael Lima Date: Tue, 30 Nov 2021 03:09:28 +0200 Subject: Document ExportAsPDF method from SF Document service Change-Id: I00421d36f7315ec7ec62eac39c44ea4433078685 Reviewed-on: https://gerrit.libreoffice.org/c/help/+/126091 Tested-by: Jenkins Reviewed-by: Rafael Lima (cherry picked from commit 51f94e35a9b401f2cbc59e57221ce1a4f2edc639) Reviewed-on: https://gerrit.libreoffice.org/c/help/+/126931 Reviewed-by: Olivier Hallot --- source/text/sbasic/shared/03/sf_document.xhp | 58 +++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/source/text/sbasic/shared/03/sf_document.xhp b/source/text/sbasic/shared/03/sf_document.xhp index c8926d6c52..2a7f2d0840 100644 --- a/source/text/sbasic/shared/03/sf_document.xhp +++ b/source/text/sbasic/shared/03/sf_document.xhp @@ -294,20 +294,21 @@ Activate
CloseDocument
- PrintOut
+ ExportAsPDF
+ PrintOut
RunCommand
Save
- SaveAs
+ SaveAs
SaveCopyAs
- SetPrinter

+ SetPrinter
@@ -370,6 +371,53 @@ +
+ ExportAsPDF -------------------------------------------------------------------------------------------- + + Document service;ExportAsPDF + +

ExportAsPDF

+ Exports the document directly as a PDF file to the specified location. Returns True if the PDF file was successfully created. + The export options can be set either manually using the File - Export As - Export as PDF dialog or by calling the methods GetPDFExportOptions and SetPDFExportOptions from the Session service. + + + svc.ExportAsPDF(filename: str, overwrite: bool = False, opt pages: str, opt password: str, opt watermark: str): bool + + + filename: The full path and file name of the PDF to be created. It must follow the SF_FileSystem.FileNaming notation. + overwrite: Specifies if the destination file can be overwritten (Default = False). An error will occur if overwrite is set to False and the destination file already exists. + pages: String specifying which pages will be exported. This argument uses the same notation as in the dialog File - Export As - Export as PDF. + password: Specifies a password to open the PDF file. + watermark: Text to be used as watermark in the PDF file, which will be drawn in every page of the resulting PDF. + + + The following example exports the current document as a PDF file, defines a password and overwrites the destination file if it already exists. + + oDoc.ExportAsPDF("C:\User\Documents\myFile.pdf", Password := "1234", Overwrite := True) + + The code snippet below gets the current PDF export options and uses them to create the PDF file. + + Dim exportSettings as Object, oSession as Object + oSession = CreateScriptService("Session") + exportSettings = oSession.GetPDFExportOptions() + ' Sets to True the option to export comments as PDF notes + exportSettings.ReplaceItem("ExportNotes", True) + oSession.SetPDFExportOptions(exportSettings) + oDoc.ExportAsPDF("C:\User\Documents\myFile.pdf") + + + + doc.ExportAsPDF(r"C:\User\Documents\myFile.pdf", password = "1234", overwrite = True) + + + session = CreateScriptService("Session") + exportSettings = oSession.GetPDFExportOptions() + exportSettings.ReplaceItem("ExportNotes", True) + session.SetPDFExportOptions(exportSettings) + doc.ExportAsPDF(r"C:\User\Documents\myFile.pdf") + +
+
PrintOut ---------------------------------------------------------------- @@ -384,7 +432,7 @@ pages: The pages to print as a string, like in the user interface. Example: "1-4;10;15-18". Default is all pages. - copies: The number of copies. Default is 1. + copies: The number of copies. Default is 1. @@ -426,7 +474,7 @@ doc = CreateScriptService("Document", "MyFile.ods") doc.RunCommand("SelectData") - The example above actually runs the UNO command uno:SelectData. Hence, to use the RunCommand method it is necessary to remove the "uno:" substring. + The example above actually runs the UNO command .uno:SelectData. Hence, to use the RunCommand method it is necessary to remove the ".uno:" substring. Each LibreOffice component has its own set of commands available. One easy way to learn commands is going to Tools > Customize > Keyboard. When you position your mouse over a function in the Function list, a tooltip will appear with the corresponding UNO command.
-- cgit