Bug 45933 - Macro to do a PDF Export does not apply filter settings - Calc & Writer
Summary: Macro to do a PDF Export does not apply filter settings - Calc & Writer
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
(earliest affected)
3.4.5 release
Hardware: All All
: medium major
Assignee: Not Assigned
Depends on:
Reported: 2012-02-11 09:26 UTC by colin.vaughanxx
Modified: 2014-05-28 17:37 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:

Source Text of macro (11.64 KB, text/plain)
2012-02-11 09:26 UTC, colin.vaughanxx

Note You need to log in before you can comment on or make changes to this bug.
Description colin.vaughanxx 2012-02-11 09:26:30 UTC
Created attachment 56899 [details]
Source Text of macro

Within the PDF Export function there is an ability to set required filter options such as exporting bookmarks, initial view etc. These can be set interactively in the associated dialog box. They should also be able to be set from a basic macro by setting them in an array argument to the calc_pdf_Export function to override the current default settings.
This does not happen and the previous defaults are used.
I wished to ensure I created a PDF of a workbook with 3 sheets showing bookmarks, I ran this interactively setting export bookmarks on dialog box.
I then recorded macro running export 3 times switching off then on then off the setting which worked fine. When I rerun the macro the output remains constant - ignoring the settings.
I have tried this with writer as well, and on both XP and Windows7.
I have also written .net program calling the pdf_export routine and the problem is constant.
I believe this is major since one can't automate production of documents to ensure required layout is created.

I attach sample listing of the macro. 
To test create a workbook which has 3 sheets, create a PDF from the dialog with bookmarks off, rerun with bookmarks on, the output file reflects the change. 

Run the main macro which should create 3 pdf's in c:\work to show bookmarks being absent, present and then absent, all 3 have bookmarks.
Comment 1 sasha.libreoffice 2012-02-22 05:41:32 UTC
Thanks for bugreport.
in attached file I see this:

repeated 3 times. Try change this somehow, my be it will begin to work properly.

PS: "record macro" is experimental function, do not expect that it will work properly in near future. Write or edit Basic programs manually meanwhile.
Comment 2 colin.vaughanxx 2012-02-24 09:52:06 UTC
Thanks for response. 
The key to the three lines was that the parameter ExportBookmarks was set alternately to remove impact of default settings.I have simplified code to just use ExportBookmarks and ExportBookmarksToPDFDestination parameters and tried combinations of true and false, problem still remains. 
I dont think that the 2nd param is relevant as according to description of parameters this requests bookmark to be a "named destination" which appears to mean that it can be included in commandline to open document at the specified location, the normal bookmark option allows navigation from open document.
I note your comment about the staus of record macro but I believe basic code used is correct and as I said I also had problems using the calls from a vb.net program.
This seems to been a bug in the previous OO releases
Comment 3 sasha.libreoffice 2012-02-24 22:20:35 UTC
Thanks for additional testing

@ Noel
Please, take look at this bug when will have time. Something with Basic function is wrong
Comment 4 Noel Power 2012-03-07 02:19:30 UTC
(In reply to comment #3)
> Thanks for additional testing
> @ Noel
> Please, take look at this bug when will have time. Something with Basic
> function is wrong

this is a recorded macro right? if so then I think you are on your own, recorded macros ( or junk as I call them ) are unreliable and basically a bad idea and that's why the ability to record marcos was changed to be an experimental feature.
Comment 5 sasha.libreoffice 2012-03-07 05:10:21 UTC
Thanks for reply
After second look at attached file I found this:
in first call to pdf export, then 
in second call, then again the same as in first. We see that in 1-th and 3-th call parameter is set to false and in 2-th to true.
IMHO Macro Recorder recorded in this case right. Problem with parameter. Function ExportToPDF not takes it in account. 

@ colin.vaughanxx
exist examples of code on Java how use exporting, may be useful:
Also try search among OpenOffice and LibreOffice extension for exporting to PDF.
If such extension exist (where we can set options for exporting), try find inside of Basic script inside of extension, how this done
Comment 6 colin.vaughanxx 2012-03-16 08:55:48 UTC
Sasha, thanks for the links, I had used the wiki pages to determine which parameters were needed and based my calls on that.
Unfortunately I'm not Java but used the examples as basis for the vb.net and macros.
I have now found an open source library for .Net I can create my doc with.
I will still try and work out the office problem nut now for interest.

Thanks for your help
Comment 7 Cor Nouws 2012-03-26 08:11:00 UTC
(In reply to comment #4)

> this is a recorded macro right? 

Not the lines that have the problem
Comment 8 Noel Power 2012-03-26 09:14:31 UTC
(In reply to comment #7)
> (In reply to comment #4)
> > this is a recorded macro right? 
> Not the lines that have the problem

eh? what lines do you mean? ( afaics all the code in the attachment is macro-recorder generated junk )
Comment 9 Joel Madero 2012-09-07 02:09:42 UTC
Is this still an UNCONFIRMED bug? Is this just a macro that isn't written properly or a problem with LO? If it's confirmed can we mark as NEW, if not, can we close it as NOTABUG and just keep the dialog open for those who want to help colin try to figure it out. Thanks all
Comment 10 maskamar 2013-06-11 07:15:06 UTC
I think this bug is in ALL versions of LibreOffice and OpenOffice. Few days ago I created new bug in category "Printing and PDF export". Sorry for that. You can look at it on https://www.libreoffice.org/bugzilla/show_bug.cgi?id=65549 or read description here...

I am new here. Can I mark this bug as "NEW" or someone else will do it?

Problem description: 

I want export as PDF part of the Calc document through the recorded macro. I recorded a macro. It is OK. But if I run it, the macro ignore property Range ("Selection") from PDF Options window.

This property is saved in the macro code:

Steps to reproduce:
1. Fill some cells with any data.
2. Start record macro.
3. Select some cells (not all).
4. File/Export as PDF.
5. Select "Selection" in Range setting on General tab.
6. "Export" and choose the destination.
7. Stop record macro and save it.
8. Check created document - it should be OK - only selected cells has been exported.
9. Run the macro.
10. Check created document - whole document has been exported.

I tested it in Ubuntu LibreOffice version (Calc and Writer), Windows Xp LibreOffice (Calc), (Calc) and in some version of OpenOffice (Calc).

All tested versions contain this bug. 
Operating System: All
Comment 11 Cor Nouws 2013-06-11 08:36:45 UTC
(In reply to comment #8)

> eh? what lines do you mean? ( afaics all the code in the attachment is
> macro-recorder generated junk )

I thought that the lines with the values for agrs(n) were not recorded, but that was my mistake. Sorry.
Comment 12 Cor Nouws 2013-06-11 08:44:20 UTC

> afaics all the code in the attachment is macro-recorder generated junk

still one could expect that if a filtername is properly passed as argument to the dispatcher, that something should be done with it .

(lacking time to test on this currently, sorry)
Comment 13 Joel Madero 2014-05-28 17:37:42 UTC
I am closing this bug as Noel is our resident expert here and he has diagnosed the problem - it's with recording macros (which we know is a problem and we're dealing with it slowly). 

That being said I highly recommend going to the user list to learn how to really write the macro without relying on poor recording feature.

Note that I am closing this as INVALID - just because it is a bug that is a meta bug (of what we already know, the recording feature needs help).