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

Creating a macro - Writing a Script - Using the API

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

Postby gluehbirne » Wed Feb 06, 2019 10:38 pm

Hi,

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
OpenOffice and LibreOffice on MacOS High Sierra 10.13.6
gluehbirne
 
Posts: 1
Joined: Wed Feb 06, 2019 10:32 pm

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

Postby JeJe » Thu Feb 07, 2019 8:52 pm

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("com.sun.star.frame.DispatchHelper")


rem ----------------------------------------------------------------------
   dim args2(0) as new com.sun.star.beans.PropertyValue
   args2(0).Name = "Tables"
   args2(0).Value = Array(0)

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

rem ----------------------------------------------------------------------
   dim args3(2) as new com.sun.star.beans.PropertyValue
   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,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Quality",0,90,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ReduceImageResolution",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("MaxImageResolution",0,300,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("UseTaggedPDF",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("SelectPdfVersion",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportNotes",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportBookmarks",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("OpenBookmarkLevels",0,-1,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("UseTransitionEffects",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("IsSkipEmptyPages",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("IsAddStream",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EmbedStandardFonts",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("FormsType",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportFormFields",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("AllowDuplicateFieldNames",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerToolbar",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerMenubar",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerWindowControls",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ResizeWindowToInitialPage",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("CenterWindow",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("OpenInFullScreenMode",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("DisplayPDFDocumentTitle",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("InitialView",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Magnification",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Zoom",0,100,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PageLayout",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("FirstPageOnLeft",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("InitialPage",0,1,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Printing",0,2,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Changes",0,4,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EnableCopyingOfContent",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EnableTextAccessForAccessibilityTools",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportLinksRelativeFsys",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PDFViewSelection",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ConvertOOoTargetToPDFTarget",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportBookmarksToPDFDestination",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("_OkButtonString",0,"",com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EncryptFile",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PreparedPasswords",0,,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("RestrictPermissions",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PreparedPermissionPassword",0,Array(),com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("",0,,com.sun.star.beans.PropertyState.DIRECT_VALUE))

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

end sub

Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 484
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby Sébastien C » Fri Feb 08, 2019 4:15 pm

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.
LibreOffice 5.2.7.2 under GNU-Linux ARMbian on the Rock64 and M$-W XP
User avatar
Sébastien C
 
Posts: 81
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 5 guests