[Solved] Why PDF password isn't working ?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

[Solved] Why PDF password isn't working ?

Post by arfgh »

Well i have seen some code examples on the forum, but for some reason the export pdf file isnt asking about password... but why ?

Code: Select all

	Dim Args(5) As New com.sun.star.beans.PropertyValue
	Args(0).Name = "SelectPdfVersion"
	Args(0).Value = 0
	Args(1).Name = "Overwrite"
	Args(1).Value = True		
	Args(2).Name = "URL"
	Args(2).Value = file
	Args(3).Name = "FilterName"
	Args(3).Value = "writer_pdf_Export"
	Args(4).Name = "EncryptFile"
	Args(4).Value = True
	Args(5).Name = "DocumentOpenPassword"
	Args(5).Value = "1234"
	ThisComponent.storeToURL(file, Args())
Last edited by MrProgrammer on Mon Oct 26, 2020 7:11 pm, edited 3 times in total.
Reason: tagged solved
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
Bidouille
Volunteer
Posts: 577
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: Why password isnt working ?

Post by Bidouille »

Depends of PDF reader used
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: Why password isnt working ?

Post by arfgh »

in this case i use sumatra pdf... but if ecryption is really enabled, and also open password, that doesnt matters, the asking for password should appears...
i guess that something is not correct in the code...
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
ms777
Volunteer
Posts: 177
Joined: Mon Oct 08, 2007 1:33 am

Re: Why password isnt working ?

Post by ms777 »

... you are doing something fundamentally wrong. See the code below. Look at viewtopic.php?f=44&t=1804 for more pdf export options

Code: Select all

sub main
	file = convertToUrl("C:\Users\Martin\Downloads\OO.pdf")

	Dim filterdata(3) As New com.sun.star.beans.PropertyValue
	filterdata(0).Name = "SelectPdfVersion"
	filterdata(0).Value = 0
	filterdata(1).Name = "EncryptFile"
	filterdata(1).Value = True
	filterdata(2).Name = "DocumentOpenPassword"
	filterdata(2).Value = "1234"
 
	Dim Args(3) As New com.sun.star.beans.PropertyValue
	Args(0).Name = "Overwrite"
	Args(0).Value = True      
	Args(1).Name = "FilterName"
	Args(1).Value = "calc_pdf_Export"
	Args(2).Name = "FilterData"
	Args(2).Value = filterdata

	ThisComponent.storeToURL(file, Args())
end sub
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: Why password isnt working ?

Post by arfgh »

so you are putting a structure into structure ?
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Why password isnt working ?

Post by Villeroy »

It's even an array of structures as a structure value within another array of structures. This is just an unusual implementation of named parameters independent from any existing or not yet existing program language. Language neutrality is one reason why UNO is more complex than other APIs.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: Why password isnt working ?

Post by arfgh »

thx so much ms777, obviously worked, but i didnt know that i have to pass those parameters with other into structure.... Now it is very clear reason why it didnt work.
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
Post Reply