Page 1 of 1

CALC: Save DINA4 Sheet as PDF named as Calc-File

PostPosted: Wed Feb 06, 2019 10:38 pm
by gluehbirne

i came from MS Office VBA and do my first steps on OO and LO Basic. I got several Problems (missing auto fill on IDE etc.), but learning by doing :-D

I am looking for a Basic Code which allows me to save a DINA4 Sheet to a normal PDF automatically. Usually i use the macro recorder and customize the recorded macro to get my first ideas. but i cannot record macros - do not know why.

Has somebody a code snippet which could help me to save the first sheet of an calc document as pdf?

thx in advance

Re: CALC: Save DINA4 Sheet as PDF named as Calc-File

PostPosted: Thu Feb 07, 2019 8:52 pm
by JeJe
Well, this is what I get with the macro recorder... change args3(0).Value to the URL of the pdf file you want to create.

Code: Select all   Expand viewCollapse view

   REM  *****  BASIC  *****

sub Main
rem ----------------------------------------------------------------------
   rem define variables
   dim document   as object
   dim dispatcher as object
rem ----------------------------------------------------------------------
   rem get access to the document
   document   = ThisComponent.CurrentController.Frame
   dispatcher = createUnoService("")

rem ----------------------------------------------------------------------
   dim args2(0) as new
   args2(0).Name = "Tables"
   args2(0).Value = Array(0)

   dispatcher.executeDispatch(document, ".uno:SelectTables", "", 0, args2())

rem ----------------------------------------------------------------------
   dim args3(2) as new
   args3(0).Name = "URL"
   args3(0).Value = "file:///C:/Users/BlahBlah/Desktop/Untitled%203.pdf"
   args3(1).Name = "FilterName"
   args3(1).Value = "calc_pdf_Export"
   args3(2).Name = "FilterData"
   args3(2).Value = Array(Array("UseLosslessCompression",0,false,,Array("Quality",0,90,,Array("ReduceImageResolution",0,false,,Array("MaxImageResolution",0,300,,Array("UseTaggedPDF",0,false,,Array("SelectPdfVersion",0,0,,Array("ExportNotes",0,false,,Array("ExportBookmarks",0,true,,Array("OpenBookmarkLevels",0,-1,,Array("UseTransitionEffects",0,true,,Array("IsSkipEmptyPages",0,true,,Array("IsAddStream",0,false,,Array("EmbedStandardFonts",0,false,,Array("FormsType",0,0,,Array("ExportFormFields",0,true,,Array("AllowDuplicateFieldNames",0,false,,Array("HideViewerToolbar",0,false,,Array("HideViewerMenubar",0,false,,Array("HideViewerWindowControls",0,false,,Array("ResizeWindowToInitialPage",0,false,,Array("CenterWindow",0,false,,Array("OpenInFullScreenMode",0,false,,Array("DisplayPDFDocumentTitle",0,true,,Array("InitialView",0,0,,Array("Magnification",0,0,,Array("Zoom",0,100,,Array("PageLayout",0,0,,Array("FirstPageOnLeft",0,false,,Array("InitialPage",0,1,,Array("Printing",0,2,,Array("Changes",0,4,,Array("EnableCopyingOfContent",0,true,,Array("EnableTextAccessForAccessibilityTools",0,true,,Array("ExportLinksRelativeFsys",0,false,,Array("PDFViewSelection",0,0,,Array("ConvertOOoTargetToPDFTarget",0,false,,Array("ExportBookmarksToPDFDestination",0,false,,Array("_OkButtonString",0,"",,Array("EncryptFile",0,false,,Array("PreparedPasswords",0,,,Array("RestrictPermissions",0,false,,Array("PreparedPermissionPassword",0,Array(),,Array("",0,,

   dispatcher.executeDispatch(document, ".uno:ExportToPDF", "", 0, args3())

end sub

Re: CALC: Save DINA4 Sheet as PDF named as Calc-File

PostPosted: Fri Feb 08, 2019 4:15 pm
by Sébastien C
gluehbirne wrote:but i cannot record macros - do not know why.

Maybe I know...

On LibreOffice, (I suppose similar in OpenOffice) : choose Tools - Options - LibreOffice - Advanced - Enable macro recording

Do not forget somethink : the recorder of macros, in LibreOffice or OpenOffice is the dispatcher. It is so much different of the API and not very efficient, especialy if you want to learn the suite’s programming. And the recorder of macros work JUST for Writer and Calc. Not for Draw, Impress or Base.