17 Replies Latest reply: Jan 21, 2015 8:35 AM by Geert Haeghebaert RSS

    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

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

          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?

           

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

            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.

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

                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

                 

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

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

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

                       


                      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.

                       

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

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

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

                            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

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

                                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

                                 

                                 

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

                          Hello all,

                          The script is working for me, but it's not autosaving Tongue Tied

                          I work with CutePDF (QV9). When pushing the programmed button, it generates the report but asks me where to save it with which name.

                          Greetings,
                          Jochen

                            • Can I do a "Print as PDF" in macro code?
                              Miguel Angel Baeyens de Arce

                              Hello Jochen

                              I'd recommend you to check the code samples in this post.

                              Hope it helps!

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

                                   


                                  Miguel A. Baeyens wrote:
                                  Hello Jochen
                                  I'd recommend you to check the code samples in this post.
                                  Hope it helps!<div></div>


                                  Tried it, still asks me where and how to save it.

                                    • Can I do a "Print as PDF" in macro code?
                                      Miguel Angel Baeyens de Arce

                                      Hello Jochen,

                                      I've used this code and it's working for me

                                       

                                      '***************************************************'Functions creates the reports in PDF format'***************************************************sub CreateReports tempFolder = "C:\Temp" reportID = "RP01" reportName = reportID'Create the file name with path reportFile = tempFolder & "\" & reportID & "_" & reportName & ".pdf" 'print the report printReportPDF reportID, tempFolder 'Call the function 'Rename the report 'checkOutputFile reportFile, tempFolder 'Call the function'call ClearDefault() 'Call the functionend sub'***************************************************'Actual function to print the PDF format without being asked for location to save'***************************************************function printReportPDF(oReport, pdfLocation) Set WSHShell = CreateObject("WScript.Shell") WSHShell.RegWrite "HKCU\Software\CUSTPDF Writer\DefaultLocation", pdfLocation, "REG_SZ" WSHShell.RegWrite "HKCU\Software\CUSTPDF Writer\UseJobName", "1", "REG_SZ" WSHShell.RegWrite "HKCU\Software\CUSTPDF Writer\UseDefaultLocation", "1", "REG_SZ" 'QV Print ActiveDocument.PrintReport oReport, "PDFCreator",false set WSHShell = nothing end function


                                      Credits to Steve Fish.

                                      Hope that helps

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

                                          Same problem, I think it's a CutePDF-problem. I'll try an other PDF-creator first

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

                                            I blame QlikTech for all the recent questions regarding PDF printing - they have changed the PDF Printer that they provide and the old posts detailing how this works no longer apply.

                                            You can change the registry keys as Miguel suggests or you can just change the settings on the 'New' QlikView PDF Printer as I have detailed here: http://community.qlik.com/forums/t/17253.aspx

                                            Actually, looking at Miguel's code I can't see how that specifies the filename of the output - it just uses the 'tempFolder' variable in the registry modification not the 'reportFile' variable. In the thread I just specified I also detail how you can change the name of the file when using the official QlikView PDF Printer.

                                            The reason this is not working if you are using CutePDF is that I do not think that the registry keys you are trying to change exist for CutePDF. On my machine it looks like the CutePDF keys are here: HKEY_CURRENT_USER\Software\Acro Software Inc\CPW

                                            I don't know if it is possible to manipulate them on the fly, you will have to test. Or just download the QlikView PDF Printer.

                                             

                                    • Re: Can I do a "Print as PDF" in macro code?
                                      Geert Haeghebaert

                                      HI

                                       

                                      I'm struggeling with same problem

                                      Not that I don't know the settings needed for the bullzip pdf printer.

                                      The createobject runs perfect on my Qlikview local client, but NOT in the access point.

                                       

                                      So the createobject to the object Wshell doesn't work neither

                                       

                                      Thanks

                                      • Re: Can I do a "Print as PDF" in macro code?
                                        Geert Haeghebaert

                                        HI

                                         

                                        I'm struggeling with same problem

                                        Not that I don't know the settings needed for the bullzip pdf printer.

                                        The createobject runs perfect on my Qlikview local client, but NOT in the access point.

                                         

                                        So the createobject to the object Wshell doesn't work neither

                                         

                                        Thanks

                                        Did you get it work ?