viewtopic.php?f=13&t=76213&p=347235&hil ... df#p347235 see "F3K Total" comment
and
viewtopic.php?f=42&t=77961&p=356774&hil ... RL#p356774 see "Nocton" comment
Both are painless to install , operate well but deliver a writer document, for security reasons I need the document delivered as PDF
In the Forum are many examples on converting a document, (Calc and Writer) to PDF, I can find none that do this from a base Report button, I have tried cobbling many examples to solve this issue but all fail on the final "uno:ExportDirectToPDF" or other PDF conversion string, it seems to me, with my limited skills, to be failing on the document name passing through to the pdf code
here is a code that, with a fixed name pulls a report
viewtopic.php?f=13&t=78386&p=359067&hil ... ts#p359067
here is Zenlord's coding trove.
viewtopic.php?f=21&t=56713&p=249604#p249604
But here is my attempt
Code: Select all
Option Explicit
Sub Reports_PDF(oEvent as object)
Rem Romkes code
REM https://forum.openoffice.org/en/forum/viewtopic.php?f=39&t=45263&p=209235&hilit=ReportDocuments#p209235
DIM oDoc AS Object, oSettings AS Object
dim oCreateButton,oForm ' This are form details
dim oConnection,oReportsDocuments
oCreateButton=oEvent.source.model
if oCreateButton.tag = "" then
msgbox "No report name in the button tag" & chr(13) & "This is the third from below of the property on the common tabpage"
else ' Now we have to start to find all kind of objects
oForm=oCreateButton.parent
oConnection=oForm.Activeconnection
oReportsDocuments=oConnection.parent.DatabaseDocument.ReportDocuments ' This point to the report containers
if oReportsDocuments.hasByHierarchicalName(oCreateButton.tag) then
'Call openreport with the parameters
openReport(oConnection, oReportsDocuments, oCreateButton.tag , oForm.Filter)
else print "There is a wrong report name"
end if
end if
End Sub
Function openReport(oConnection, oReportsDocuments,aReportName,sFilter) as object
dim dispatcher as object
dim aProp(2) as new com.sun.star.beans.PropertyValue
dim aProp2 ' Make a variant
dim oReportDesign
aProp(1).Name = "ActiveConnection"
aProp(1).Value = oConnection
aProp(0).Name = "Hidden"
aProp(0).Value = true
aProp(2).Name = "OpenMode"
aProp(2).Value = "openDesign"
let aProp2=aProp
oReportDesign=oReportsDocuments.loadComponentFromURL(aReportName ,"",0,aProp())
aProp2(0).Value = false
aProp2(2).Value = "open"
REM ***** Pulls ".ODT" report fine from "openReport" and from "oDoc" *******
openReport=oReportsDocuments.loadComponentFromURL(aReportName ,"",23,aProp2())
' oDoc=oReportsDocuments.loadComponentFromURL(aReportName ,"",23,aProp2())
REM
oDoc = ThisComponent.createInstance("com.sun.star.document.Settings")
dispatcher=createUnoService("com.sun.star.frame.DispatchHelper")
Dim a(2) As New com.sun.star.beans.PropertyValue
a(0).Name = "URL" : a(0).Value = "my_file_name_.pdf"
a(1).Name = "FilterName" : a(1).Value = "writer_pdf_Export"
REM ***********************
REM Error Here " Object variable not set. "
REM ***********************
dispatcher.executeDispatch(oDoc, ".uno:ExportDirectToPDF", "", 0, args())
End Function