Background Printing PDFs
●
1 minute(s) to read
●
Permalink
●
suggest edit
A common task that developers attempt to do is print PDF files from code. Unfortunately, there is no simple and easy way of doing this. However, I found a work around using the Acrobat Type Library that can assist with this. It’s by no means the best solution, but will allow you to perform background printing:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Public Shared Function PrintPDF(ByVal Filename As String) As Boolean
'Declare Variables
Dim AcrobatApp As New AcroApp
Dim AcrobatDoc As New AcroAVDoc
Dim AcrobatPDFDoc As New AcroPDDoc
Dim TotalPageCount As Integer
Dim ResultsBoolean As Boolean
Dim ReturnBoolean As Boolean = False
Try
'Attempt To Open The Report
AcrobatDoc.Open(Filename, "")
'Pass the Document to the PDF Handler
AcrobatPDFDoc = AcrobatDoc.GetPDDoc
'Grab the total number of pages
TotalPageCount = AcrobatPDFDoc.GetNumPages
'Perform a background print using Acrobat
ResultsBoolean = AcrobatDoc.PrintPagesSilent(0, TotalPageCount - 1, 0, False, True)
If ResultsBoolean = False Then
Throw New Exception("Acrobat returned a False value when attempting to print the pages in the background.")
Else
ReturnBoolean = True
End If
Catch ex As Exception
'Add In Exception Handling
End Try
Return ReturnBoolean
End Function