[Dropped] Add export as PDF to a current macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Alexys4530
Posts: 4
Joined: Fri Mar 12, 2021 11:31 pm

[Dropped] Add export as PDF to a current macro

Post by Alexys4530 »

Hi,
I have a calc document, its used as a packing slip.

We currently have a macro that :
1- set the date in a specific cell
2- Get order number, get invoice number, get pack slip number from specific cell
3- Export as .ods with name set from data collected at step 2
4- print a copy
5- Add 1 to the pack slip number in specific cell
6- Clear data from some cells
7- then save as .ods as an empty pack slip for next one

We would need to also save sheet 1 as a PDF between step 3 and 4

Here is what we have:

Thanks alot!
Last edited by MrProgrammer on Sun Mar 26, 2023 5:42 pm, edited 2 times in total.
Reason: Dropped: No attachment provided when requested -- MrProgrammer, forum moderator
OpenOffice 4.1.7 on Windows 10
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Add export as PDF to a current macro

Post by John_Ha »

Search the forum with PDF - there are lots of posts about exporting to PDF.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
Alexys4530
Posts: 4
Joined: Fri Mar 12, 2021 11:31 pm

Re: Add export as PDF to a current macro

Post by Alexys4530 »

John_Ha wrote: Fri Jan 13, 2023 6:48 pm Search the forum with PDF - there are lots of posts about exporting to PDF.
Hi John,
I did. I played a bith with :

Code: Select all

sub mypdf

dim args2(1) as new com.sun.star.beans.PropertyValue
dim Arg(0) as new com.sun.star.beans.PropertyValue
Doc   = ThisComponent
Controller = Doc.CurrentController
Sheet = Doc.Sheets.getByName("BE")
CellRange = Sheet.getCellRangeByName("$A$1:$G$37")
Controller.select(CellRange)
Cell = Sheet.getCellByPosition(6,10)

'Got this here http://wiki.services.openoffice.org/wiki/API/Tutorials/PDF_export
'See also http://user.services.openoffice.org/en/forum/viewtopic.php?f=44&t=1804
Arg(0).Name = "Selection"
Arg(0).Value = CellRange

args2(0).Name = "FilterName"
args2(0).Value = "calc_pdf_Export"
args2(1).Name = "FilterData"
args2(1).Value = Arg()
Doc.storeToURL("\\BACKUP2\partage\PIÈCES\Arcelor Mittal\Bon d'envoi Arcelor\"& Cell.getString()&".pdf",args2())
end sub
But I cant get it to work, I keep getting error for my last line : Image

Thank you
OpenOffice 4.1.7 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Add export as PDF to a current macro

Post by Zizi64 »

Please uplopad your ODF type sample file here with the embedded macro code.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Add export as PDF to a current macro

Post by John_Ha »

Searching the forum with PDF finds lots of threads.

One was Macro export to PDF andrOpen Office which says record a macro so I recorded this. If it works you will need to record one with your parameters.

Code: Select all

sub Exp_PDF
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 args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = "file:///C:/Users/johnr/Desktop/Untitled%201.pdf"
args1(1).Name = "FilterName"
args1(1).Value = "calc_pdf_Export"
args1(2).Name = "FilterData"
args1(2).Value = Array(Array("UseLosslessCompression",0,true,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, args1())

end sub
Another was [Solved] [Basic] Export Calc range to PDF
Last edited by John_Ha on Fri Jan 13, 2023 7:40 pm, edited 3 times in total.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
Alexys4530
Posts: 4
Joined: Fri Mar 12, 2021 11:31 pm

Re: Add export as PDF to a current macro

Post by Alexys4530 »

Zizi64 wrote: Fri Jan 13, 2023 7:18 pm Please uplopad your ODF type sample file here with the embedded macro code.
Hi Zizi64,
See https://filebin.net/xirsie13m5om6m6x

Thank you for your Help

 Edit: As of 2023-03-26 the link above says: This bin is no longer available. 
-- MrProgrammer, forum moderator  
OpenOffice 4.1.7 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Add export as PDF to a current macro

Post by Zizi64 »

Try to use the ConvertToURL function to create a real URL, or use a URL string, constans because the path containing \ character is not a standard URL. See John Ha's sample code.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Post Reply