Kategorien
Makros and Automatisation Qlik Tips n Tricks

QlikView Makro PDF Print with BullZip PDFCreator QlikViewPDF

Getting the Printer

First of all you need to download and install the printer from the official BullZip Webpage, which can be found here:

http://www.bullzip.com

After the download and installation (GhostScript Requiered) you’ll find a new Printer in your System Settings.

QlikView Parts

Preparing your System

Go to the macro modul in your QlikView Client. And write the following modules:

Sub PrintReports
  'This macro can be used to print pdf reports into the directory structure using bullzip pdf

  ActiveDocument.GetApplication.Sleep 2000
   ActiveDocument.PrintReport "RP02", "Bullzip PDF Printer"
  ActiveDocument.GetApplication.Sleep 10000

 MyPrintPDFWithBullZip "C:\Temp\18T.pdf"
End Sub

FUNCTION MyPrintPDFWithQlikViewPDF (pdfOutputFile)

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

END FUNCTION

FUNCTION MyPrintPDFWithBullZip (pdfOutputFile)

 'need to init the printername, otherwise the assignment of the values will fail
 Set obj_printer_util = CreateObject("Bullzip.PDFUtil")
 printername = obj_printer_util.defaultprintername

 'init the BullZip preferences object
 set obj = CreateObject("Bullzip.PDFSettings") 'For 32Bit System u use PDFPrinterSettings

 obj.printername = obj_printer_util.defaultprintername 'assign the printername
 obj.SetValue "Output" , pdfOutputFile
 obj.SetValue "ConfirmOverwrite", "no"
 obj.SetValue "ShowSaveAS", "never"
 obj.SetValue "ShowSettings", "never"
 obj.SetValue "ShowPDF", "no"
 obj.SetValue "RememberLastFileName", "no"
 obj.SetValue "RememberLastFolderName", "no"
 obj.SetValue "ShowProgressFinished", "no"
 obj.SetValue "ShowProgress", "no"
 obj.WriteSettings True

END FUNCTION

Advanced Module

Sub PrintReports        
   'Lets create a temporary bookmark, to store the current selection
   ActiveDocument.CreateUserBookmark "PrintMakroStorage"

   'Pls create a tablebox containing all reports and ID's to be printed out
   Set ReportTable = ActiveDocument.GetSheetObject("TB15")

   FOR RowIter = 1 TO ReportTable.GetRowCount - 1

		reportID = (ReportTable.GetCell(RowIter,0).text)
		reportHIRARCHY = (ReportTable.GetCell(RowIter,1).text)
		reportGROUP = (ReportTable.GetCell(RowIter,2).text)
		reportNAME = (ReportTable.GetCell(RowIter,3).text)

		MyFilterField = (ReportTable.GetCell(RowIter,4).text)
		MyFilterSelection = (ReportTable.GetCell(RowIter,5).text)

		'Clear All
		ActiveDocument.ClearAll	

		if MyFilterField <> "" THEN

			ActiveDocument.Fields(MyFilterField).Select MyFilterSelection

		end if

		'call the print job
		Print_PDF reportHIRARCHY, reportNAME, reportID, reportGROUP

		'reset the start selections
		ActiveDocument.RecallUserBookmark "PrintMakroStorage"

	NEXT

	ActiveDocument.RemoveUserBookmark "PrintMakroStorage"
End Sub

Sub Print_PDF(FieldValue, ReportName, ReportID, ReportGroup)

    ' Designed for early bind, set reference to Bullzip PDF Printer
    Dim sPDFName
    Dim sPDFPath

    '/// Change the output file name here! ///
    sPDFName = ReportName '& " - " & FieldValue
    sPDFPath = "C:\Temp\" & FieldValue & "\2012 08 StandardReporting\" & ReportGroup & "\"
    'For monthly publishing :: sPDFPath = "C:\Users\Administrator\Dropbox\" & FieldValue & "\2012 08 StandardReporting\" & ReportGroup & "\"

	MyPrintPDFWithBullZip sPDFPath&sPDFName&".pdf"

    'Wait until the print job has entered the print queue
    ActiveDocument.GetApplication.Sleep 2000

    ' Print the QlikView Report
    ActiveDocument.PrintReport ReportID, "Bullzip PDF Printer"

    'Wait until PDF creator is finished then release the objects
    ActiveDocument.GetApplication.Sleep 1000

End Sub

Full working sample with Print and JobTable

sub CreateReports

        Set WSHNetwork = CreateObject("WScript.Network")
        WSHNetwork.SetDefaultPrinter "QlikViewPDF"

	'Lets create a temporary bookmark, to store the current selection
	ActiveDocument.CreateUserBookmark "PrintMakroStorage"

	'Pls create a tablebox containing all reports and ID's to be printed out
	Set ReportTable = ActiveDocument.GetSheetObject("TB15")

	FOR RowIter = 1 TO ReportTable.GetRowCount - 1

		reportID = (ReportTable.GetCell(RowIter,0).text)
		reportHIRARCHY = (ReportTable.GetCell(RowIter,1).text)
		reportGROUP = (ReportTable.GetCell(RowIter,2).text)
		reportNAME = (ReportTable.GetCell(RowIter,3).text)

		MyFilterField = (ReportTable.GetCell(RowIter,4).text)
		MyFilterSelection = (ReportTable.GetCell(RowIter,5).text)

		'Clear All
		ActiveDocument.ClearAll	

		if MyFilterField <> "" THEN

			ActiveDocument.Fields(MyFilterField).Select MyFilterSelection

		end if

		'call the print job
		PrintPDF reportHIRARCHY, reportNAME, reportID, reportGROUP

		'reset the start selections
		ActiveDocument.RecallUserBookmark "PrintMakroStorage"

	NEXT

	ActiveDocument.RemoveUserBookmark "PrintMakroStorage"

end Sub

function MyPrintPDFWithQlikViewPDF (pdfOutputFile)

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

end function

function MyCheckFolder (pdfPath)
    Dim objFSO
    Dim objFolder
    Dim Overwrite

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Overwrite = objFSO.FolderExists(pdfPath)

    Select Case Overwrite
    Case False: Set objFolder = objFSO.CreateFolder(pdfPath)
    Case Else
    End Select

    Set objFSO = Nothing: Set objFolder = Nothing
end function

Sub PrintPDF(FieldValue, ReportName, ReportID, ReportGroup)

    ' Designed for early bind, set reference to Bullzip PDF Printer
    Dim sPDFName
    Dim sPDFPath

    '/// Change the output file name here! ///
    sPDFName = ReportName '& " - " & FieldValue
    'For monthly publishing :: 
    sPDFPath = "C:\Users\Administrator\Dropbox\" & FieldValue & "\2012 08 StandardReporting\" & ReportGroup & "\"
    
    MyCheckFolder sPDFPath
    MyPrintPDFWithQlikViewPDF sPDFPath & sPDFName & ".pdf"

    'Wait until the print job has entered the print queue
    ActiveDocument.GetApplication.Sleep 20

    ' Print the QlikView Report
    ActiveDocument.PrintReport ReportID, "QlikViewPDF", false

    'Wait until PDF creator is finished then release the objects
    ActiveDocument.GetApplication.Sleep 5000

End Sub

Schreibe einen Kommentar