PDF-List (Calc),Hyperlinks,pdftk,read-write metadata, merge

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

PDF-List (Calc),Hyperlinks,pdftk,read-write metadata, merge

Post by musikai »

The attached .ods-file has a Toolbar with 4 Buttons. You can import all PDFs of a chosen folder (optional with Subfolders) as Hyperlinks. Besides the usual ctrl-click on Hyperlink a custom set App can be used to open a selected PDF.

If the commandline-tool pdftk is installed you have more features:
- The list also shows the Page Count and the MetaData (Infokeys) of the PDFs.
- MetaData can be written back into the PDFs.
- PDFs can be merged.


There are 4 Buttons in the Toobar:
1.ListPDFs
Please edit the first lines of Sub listPDFs to you liking (especially if you want to use pdftk or not.

Code: Select all

sub listPDFs
Folderpath="E:\PDF"   'edit your default path here
subdirs=1   'to not list subfolders use subdirs=0
pdftkapp="pdftk"   'if you don't use pdftk then use: pdftkapp=""
You get a Folder-Selector. The list of imported PDFs will contain:

Without pdftk:

Code: Select all

PDF-Name (Hyperlinked) - Size
With pdftk also the Page-Count and all available MetaData will be listed:

Code: Select all

PDF-Name (Hyperlinked) - Size - Pages - Title - Author - Subject - Keywords - ...
PDF-List.PNG
If the Page-Count of a PDF is missing then the PDF was skipped on import because it probalby was password-protected.


2.open_pdf_in_app
The PDF of the row you have selected will be opened in the given external App.
Please edit the first line of sub open_pdf_in_app to give the path to your external App.

Code: Select all

sub open_pdf_in_app
PDF_App="E:\Installationsprogramme\Sumatra\SumatraPDF.exe"   'edit this path
Next 2 Buttons only work with installed pdftk:
3.Write_Info_to_new_PDF(s)
The Metadata of all PDFs of a selection range will be written back into the PDFs. The Original PDF will be moved into a subfolder called "!.OriginalPDFs", so you have a backup. (This subfolder "!.OriginalPDFs" will always be skipped when listing with Button 1)

You also can create new custom MetaData-Fields (in the Header-Row). Only filled cells will be written back into the PDF.
PDFs with missing Page-Count will be skipped because they likely are password-protected.


4.mergePDFs
All PDFs of a selection range will be merged into a new PDF. This will be called "mergedPDFs.pdf" and will be located in the Folder that is shown in cell A1.
Attachments
PDF_List.ods
(13.41 KiB) Downloaded 243 times
Last edited by musikai on Wed Jan 08, 2020 11:34 pm, edited 1 time in total.
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: PDF-List (Calc),Hyperlinks,pdftk,read-write metadata, me

Post by Zizi64 »

2.open_pdf_in_app
The PDF of the row you have selected will be opened in the given external App.
Please edit the first line of sub open_pdf_in_app to give the path to your external App.

Code: Select all

sub open_pdf_in_app
    PDF_App="E:\Installationsprogramme\Sumatra\SumatraPDF.exe"   'edit this path

A tip:
You can open any type of documents with the default assigned editor/viewer software by the usage of this code:

Code: Select all

Sub Open_a_Document(sDocUrl as string)
 Dim oSys as Object
 
	oSys = CreateUnoService("com.sun.star.system.SystemShellExecute")
	oSys.execute(sDocUrl, "", 0)

End Sub
Tested on Windows XP-7-10 operating systems
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.
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: PDF-List (Calc),Hyperlinks,pdftk,read-write metadata, me

Post by musikai »

Thank you,
the purpose of this button is to be able to use an alternative app for opening the pdf. Other than the default associated viewer which would be used anyway by ctrl-clicking the hyperlink. (It was a request)

Your code sure is worth mentioning. (and it is also used in my code in the pdf-merger when the created pdf is auto-opened in the end)
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Post Reply