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

How to print individual sheets to separate PDFs with a script?

I've been working with script, for the first time, trying to print 20 separate sheets as PDFs in an automated way (or maybe to write one large PDF).  I have not (as yet) defined reports for these sheets.  At this time I just want to print them as sheets.

1. What is the script equivilent to menu: File, Print Sheet? (its not Print Report, PrintDocReport or PrintReportEx)

2. If I decided to use doc1.PrintAllSheets, how can I pass in the name of the PDF printer and the PDF file name I wish to write to?

Thx,

Brooks


15 Replies
Not applicable
Author

I use a macro and the follwing script works for me.

Sub printRP

ActiveDocument.GetApplication.WaitForIdle(1000)

  ActiveDocument.PrintReport "RP01", "PDF-XChange 3.0", false

  ActiveDocument.GetApplication.Sleep 10000

  ActiveDocument.PrintReport "RP02", "PDF-XChange 3.0", false

  ActiveDocument.GetApplication.Sleep 10000

   ActiveDocument.PrintReport "RP03", "PDF-XChange 3.0", false

  ActiveDocument.GetApplication.Sleep 10000

  

   ActiveDocument.PrintReport "RP04", "PDF-XChange 3.0", false

  ActiveDocument.GetApplication.Sleep 10000

End Sub

Regards,

Gerrit

Not applicable
Author

Thanks for the post.

How do you specify the PDF file?

I don't see PDF-XChange 3.0 in my printer list in QV ...


Not applicable
Author

You have to Install PDF printer, There are many PDF printers

CutePDF

Bullzipp

PDFCreator

PDF-XChange 3.0

Not applicable
Author

As far as I know PDF-XChange 3.0 is installed out of the box together with QV.

However I am not the technical one here, and did not install QV.

Probably others may know where XChange 3.0 can be obtained.

Regards,

Gerrit

Not applicable
Author

Ok, I have CutePDF.

What is the code in the script to specify the PDF file name?

Not applicable
Author

You need to create a macro.

In the following lines i Have 4 reports RP01, RP02, RP03 and RP04.

These are my report names.

Sub printRP

ActiveDocument.GetApplication.WaitForIdle(1000)

  ActiveDocument.PrintReport "RP01", "PDF-XChange 3.0", false

  ActiveDocument.GetApplication.Sleep 10000

  ActiveDocument.PrintReport "RP02", "PDF-XChange 3.0", false

  ActiveDocument.GetApplication.Sleep 10000

   ActiveDocument.PrintReport "RP03", "PDF-XChange 3.0", false

  ActiveDocument.GetApplication.Sleep 10000

 

   ActiveDocument.PrintReport "RP04", "PDF-XChange 3.0", false

  ActiveDocument.GetApplication.Sleep 10000

End Sub

Regards,

Gerrit

Not applicable
Author

I understand that.  But where is it specified what folder to write to and what PDF file name to use?

Not applicable
Author

Here is the Code

sub PrintReportPDFCreatorone

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

end sub

Sub printReportPDF (oReport, pdfLocation)

Set WSHShell = CreateObject("WScript.Shell")

  WSHShell.RegWrite "HKEY_CURRENT_USER\Software\PDFCreator\OutputFile", pdfLocation

  WSHShell.RegWrite "HKEY_CURRENT_USER\Software\PDFCreator\BypassSaveAs", "1", "REG_SZ"

  msgbox("Before Print")

  ActiveDocument.PrintReport oReport, "CutePDF",false

  set WSHShell = nothing

end sub

Not applicable
Author

Thanks for the code, making progress.  Still a bit to go ...

I changed to:

PrintReportPDF reportID, reportFile

Also on my system the printer is named: "CutePDF Writer"

The problem is that bypassing the Save As is not working.  A Save As dialog window is appearing.

Maybe "1" should be something else?