Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Can I do a "Print as PDF" in macro code?

Hi All,

I have a basic report that needs to be "printed" showing the selected criteria and the results. No problem. I put a button on the sheet to do the PrintReport function so the user doesn't try and print when they have not made sufficient selections. (i.e. massive report).

The question that has come up is: You can right click on a listbox etc. and select Print as PDF and Qlikview knows how to automatically select whichever PDF writer / driver you have installed. Can the same thing be done from the buttons macro code? I can get it to work when I know the name of the driver, such as "CutePDF" but since this is from an access point I won't know the name therefore can I select the PDF writer the same way that menu option does?

Thanks!

Rob

V 8.5

17 Replies
Not applicable
Author

hi, im looking to do the same thing. Create a button that prints a PDF via Access Point. We use CutePDF here.

Did you find a solution to the problem?

Not applicable
Author

I did not,

Most users have the PDF software set as their default, so it is not a huge issue for me, but I was never able to get this to work in v8.5

pkelly
Specialist
Specialist

The attached word document may partly help you.

This shows how we export to a PDF but we use a set printer (QlikViewPDDF)...

Hope this helps you get somewhere down the line to solving your issue.

Not applicable
Author

Hi Paul, thanks for your help and suggestion.

I tried using your code (adapting it for CutePDF) but it didnt work when executed.

------

sub PrintReport
printReportPDF "C:\qlikviewreport.pdf"
ActiveDocument.GetApplication.Sleep 2000
ActiveDocument.PrintReport "test", "CutePDF"
ActiveDocument.GetApplication.Sleep 10000
end sub
'===========================================================================
Function printReportPDF(pdfOutputFile)

Set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKCU\Software\CutePDF\OutputFile", pdfOutputFile, "REG_SZ"
WSHShell.RegWrite "HKCU\Software\CutePDF\BypassSaveAs", "1", "REG_SZ"
Set WSHShell = nothing

End function
'===========================================================================

-------------

Somehow i dont thinks it likes the line in bold.

Its a shame QlikView doesnt clarify exactly how to configure the use of pdfs in QV documents.

Regards

j

pkelly
Specialist
Specialist

I am assuming that test is your report name. You need to use the report id which is RP01 (or similar)....

nathanfurby
Specialist
Specialist


J Trof wrote:ActiveDocument.PrintReport "test", "CutePDF"


I believe the second parameter also needs to be the name of the printer as installed on your machine. By default I think it is actually "CutePDF Writer"

Also - the functionality of the printReportPDF function will not work as the registry keys you are trying to edit do not exist for Cute PDF.

pkelly
Specialist
Specialist

based upon what Nathan is saying can i suggest that you download QlikViewPDF which is free?

Not applicable
Author

Thanks for the tips. I modified my script to the following:

----

sub PrintReport
printReportPDF "qlikviewreport.pdf"
ActiveDocument.GetApplication.Sleep 2000
ActiveDocument.PrintReport "RP01", "CutePDF Writer"
ActiveDocument.GetApplication.Sleep 10000
end sub
'===========================================================================
Function printReportPDF(pdfOutputFile)

Set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKCU\Software\CutePDF Writer\OutputFile", pdfOutputFile, "REG_SZ"
WSHShell.RegWrite "HKCU\Software\CutePDF Writer\BypassSaveAs", "1", "REG_SZ"
Set WSHShell = nothing

End function
'===========================================================================

-----

This worked well and printed the report in pdf using 'CutePDF Writer' . Would anyone have any idea how to do the following with my script:

  • Print current sheet on QV document (not a specified report)?
  • Print to desktop (without user input)

Any help would be great

Thanks

pkelly
Specialist
Specialist

On printing without user input, what I did was create a button on a hidden sheet then created the VBS below which was called from windows scheduler at various points......

Dim objQV

Dim boolLoopAgain

boolLoopAgain = False

Do

On Error Resume Next

boolLoopAgain = False

' Try to grab a running instance of QlikView...

Set objQV = GetObject(, "QlikTech.QlikView")

' MsgBox objQV

If TypeName(objQV) = "Global" Then

' QlikView is Running

boolLoopAgain = True

Else

Set MyApp = CreateObject("QlikTech.QlikView")

Set MyDoc = MyApp.OpenDoc ("C:\QlikViewDocuments\Timbmet_Live\Reports\15TS.qvw","","")

Set ActiveDocument = MyDoc

ActiveDocument.Reload

ActiveDocument.GetSheetObject("BU104").Press

End If

Loop While boolLoopAgain