Ask Your Question

how i export pdf using macro

asked 2019-01-10 03:42:40 +0200

raj80152 gravatar image

how i export pdf file (without prompt) using macro and how i same pdf file is same openoffice file name.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2019-01-10 14:55:14 +0200

Lupp gravatar image

updated 2019-01-10 17:43:47 +0200

General advice: If you think to need "macros", read the guide and study the famous texts by Andrew Pitonyak availabele from his site.
Concerning the specific case: Use the document method storeToURL with the appropriate export filter writer_pdf_Export.
Very specific: The export to pdf supports lots of settings via the FilterData property. For most or all of them you can accept the defaults most likely. However, I don't know exactly which ones of these defaults in fact are the values chosen the last time export to pdf was done. Thus I give the short version here, and attach an example document containing the macro with the huge set of FilterData settings the recorder passes to the .uno:Save... command.

Both the versions contain the composition of the .pdf url from the url of the Writer document replacing its original extension. You may decide to better simply append the .pdf.

===Edit1 2019-01-10 17:43 CET===
Considering the comments below I slightly reworked the posted code. The replacing attachment (both Sub) is reworked in the same way. Old OOo Basic did not accept the rededication of a missing Optional parameter to a variable taking its place. Recent LibreOffice and also Apache Openoffice V 4.1.5 I tested with both accepted that shorthand way.

Code provided as is without any guarantee!

Sub simpleWriterExportToPdf_ToDocumentFolder(Optional pDoc As Object)
REM Reworked to also run in very old versions.
If IsMissing(pDoc) Then 
  theDoc           = ThisComponent
  theDoc           = pDoc
End If
docUrl             = theDoc.URL
If NOT FileExists(docUrl) Then
  MsgBox("The document must be saved to an URL for this routine to work.")
  Exit Sub
End If
If NOT theDoc.supportsService("") Then
  MsgBox("This routine can only export Writer documents.")
  Exit Sub
End If
docURLsplit        = Split(docURL, ".")
docExt             = docURLsplit(Ubound(docURLsplit))
pdfURL             = Left(docURL, Len(docURL) - Len(docExt) -1) & ".pdf"
Dim storeArgs(0) As New
storeArgs(0).Name  = "FilterName"
storeArgs(0).Value = "writer_pdf_Export"
theDoc.storeToURL(pdfUrl, storeArgs())
End Sub

The announced attachment.

edit flag offensive delete link more


thanks for your help. but is not functioning correctly, i am using openoffice 2.0 i think is not support.

raj80152 gravatar imageraj80152 ( 2019-01-10 16:49:30 +0200 )edit

Sory! Sorry! Sorry! I uploaded the demo before I had pasted the "macro" in. Next miute this will be rectified.
However, OOo V 2.0 is very old.( I can't test with it). The oldest version I can test with is OOo V 3.2.
I did. There is a problem that also would break the above originally posted code. Obviously such old versions do not accept the name of a missing Optional parameter in place of a variable. Please, always post the message if you get reported an error. To get compatible with such very old versions I changed the code a bit.

Lupp gravatar imageLupp ( 2019-01-10 17:35:32 +0200 )edit

supper is functioning correctly, thank you very much.

raj80152 gravatar imageraj80152 ( 2019-01-14 04:26:27 +0200 )edit

Glad this helped you.
The askbot (the sofware used by this site) provides the feature "mark this answer as correct" for the case. It is linked to the checkmark left of the first few lines of the answer.
Highlighting accepted answers should help other users searching for suitable answers to similar questions.

Lupp gravatar imageLupp ( 2019-01-14 12:50:29 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-01-10 03:42:40 +0200

Seen: 86 times

Last updated: Jan 10