[Solved] Print Calc sheet to PDF, using a macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
martius
Posts: 60
Joined: Sat Feb 05, 2011 9:41 pm
Location: São Paulo, Brasil

[Solved] Print Calc sheet to PDF, using a macro

Post by martius »

How to make a macro that exports a specific spreadsheet to PDF, considering the print area already defined in LibreOffice Calc?
Last edited by MrProgrammer on Mon Jul 15, 2024 5:16 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
LibreOffice 6.2.8.2 (x64), Windows 10 Home
User avatar
MrProgrammer
Moderator
Posts: 5373
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Print a specific sheet of Calc as a PDF file, using a macro

Post by MrProgrammer »

martius wrote: Sat Jul 06, 2024 10:16 pm How to make a macro that exports a specific spreadsheet to PDF, considering the print area already defined in LibreOffice Calc?
Please search first before posting. I found this in a few seconds. I do not offer to help further with writing macros.
[Solved] Save PrintRange as PDF to Desktop of Any User

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
martius
Posts: 60
Joined: Sat Feb 05, 2011 9:41 pm
Location: São Paulo, Brasil

Re: Print a specific sheet of Calc as a PDF file, using a macro

Post by martius »

Thank you!
LibreOffice 6.2.8.2 (x64), Windows 10 Home
User avatar
Zizi64
Volunteer
Posts: 11497
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Print a specific sheet of Calc as a PDF file, using a macro

Post by Zizi64 »

The "Print" method can use a virtual PDF printer (if it is exist).
Ther "Export" method uses the built-in export feature

You you can use the "Export the Selection" option. Of course you must SELECT the cell range to export (by the macro) before you use that option.

Code: Select all

	Arg(0).Name = "Selection"
	Arg(0).Value = oRange

	args2(0).Name = "FilterName"
	args2(0).Value = "calc_pdf_Export"
	args2(1).Name = "FilterData"
	args2(1).Value = Arg()

	ThisComponent.storeToURL(Pdf_Local_URL, args2())

Where the oRange is a cell range object (you must get an Select it by your macro), and the Pdf_Local_URL is the place where you want to save the pdf file to.
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