AddImageWatermark and AddTextWatermark for API
Posted: Fri Apr 13, 2012 3:46 pm
I downloaded the latest PDF-XChange PRO 4 sdk
which was the PDFSDKPRO4.zip file.
I openned the VbExCom vb6 project and modified the code to use the AddImageWatermark and AddTextWatermark based on other examples seen earlier. I didn't see either of the watermarks added to the PDF.
The code is below. Let me know why the Watermarks are not there.
Regards,
Kevin
'''''''''''''''''''''''''''''''''''' CODE STARTS HERE
Option Explicit
Const SW_MINIMIZE = 11
Dim PDFPFactory As New PXCComLib.CPXCControlEx
Dim WithEvents PDFPrinter As PXCComLib.CPXCPrinter
' Attribute m_PDFPrinter.VB_VarHelpID = -1
Public vFrame As Integer
Dim pname As String
Private Declare Function ShellExecute Lib "Shell32" Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function ExtEscape Lib "Gdi32" (ByVal hDC As Long, _
ByVal nEscape As Long, ByVal cbInput As Long, ByVal lpInData As String, _
ByVal cbOutput As Long, ByVal lpOutData As Long) As Long
Private Sub Form_Unload(Cancel As Integer)
PDFPrinter.RestoreDefaultPrinter
Set PDFPrinter = Nothing
End Sub
Private Sub InitSaverObj()
Set PDFPrinter = PDFPFactory.Printer("", "PDF-XChange 4.0 Sample", "<YOUR REG CODE>", "<YOUR DEV CODE>")
pname = PDFPrinter.Name
PDFPrinter.SetAsDefaultPrinter
End Sub
Public Sub Form_Load()
InitSaverObj
TypeOption(1).Value = True
End Sub
Private Sub btnAbout_Click()
frmAbout.Show vbModal, Me
End Sub
Private Sub btnBrowseDoc_Click()
dlgOpen.FileName = m_File.Text
dlgOpen.ShowOpen
m_File.Text = dlgOpen.FileName
End Sub
Private Sub btnClose_Click()
Unload Me
End Sub
Private Sub Make_ShowHide(Index As Integer, bShow As Boolean)
frType(Index).Visible = bShow
End Sub
Private Sub btnGo_Click()
Dim fn As String
Dim D As Long
Dim D2 As Long
Dim DD As Byte
Dim P As Printer
Dim bVal As Boolean
Dim s As String
PDFPrinter.ResetDefaults
PDFPrinter.Option("Save.File") = fName.Text
PDFPrinter.Option("Save.SaveType") = "Save"
PDFPrinter.Option("Save.ShowSaveDialog") = "No"
PDFPrinter.Option("Save.WhenExists") = "Overwrite"
bVal = doCompress.Value
If (bVal = True) Then
With PDFPrinter
.Option("Compression.Graphics") = "Yes"
.Option("Compression.Text") = "Yes"
.Option("Compression.ASCII") = "No"
.Option("Compression.Color.Enabled") = "Yes"
.Option("Compression.Color.Method") = "Auto"
.Option("Compression.Indexed.Enabled") = "Yes"
.Option("Compression.Indexed.Method") = "Auto"
.Option("Compression.Mono.Enabled") = "Yes"
.Option("Compression.Mono.Method") = "Auto"
End With
Else
PDFPrinter.Option("Compression.Graphics") = "No"
PDFPrinter.Option("Compression.Text") = "No"
End If
bVal = doEmbedd.Value
PDFPrinter.Option("Fonts.EmbedAll") = IIf(bVal = True, 1, 0)
bVal = doRun.Value
PDFPrinter.Option("Save.RunApp") = bVal
If bVal = True Then
PDFPrinter.Option("Save.RunCustom") = "No"
End If
' To Hide progress window uncomment the next line
PDFPrinter.Option("Saver.ShowProgress") = "No"
PDFPrinter.Option("Watermarks.Enabled") = "Yes"
PDFPrinter.AddImageWatermark "I", "P:\DOCTRAK FORMS\temp\Lake\Older Stuff\LAKOrderVerification.bmp", -1, 210, 297, 17, 0, 0, 0, 50, 796, 0, ""
PDFPrinter.AddTextWatermark "T", "TEST", "Arial", 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 50, 28, 0, ""
PDFPrinter.Option("Watermarks.Watermarks") = "I;T"
PDFPrinter.ApplyOptions 0
If (TypeOption(2).Value) Then
IE_WebBrowser.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
ElseIf (TypeOption(1).Value) Then
ShellExecute 0, "printto", m_File.Text, """" + pname + """", vbNull, SW_MINIMIZE
ElseIf (TypeOption(0).Value) Then
For Each P In Printers
If P.DeviceName = pname Then
' Set printer as default for current session
Set Printer = P
' Stop looking for a printer
Exit For
End If
Next
'
'initialize printer
D = Printer.TwipsPerPixelX
Printer.Orientation = vbPRORPortrait
'initialized
D = Printer.hDC
'
Printer.FontName = "Arial"
Printer.FontSize = 12
Printer.CurrentX = 1000
Printer.CurrentY = 1000
Printer.Print "Sample printing from VB using PDF-XChange 4.0"
Printer.Circle (3000, 3000), 1000
Printer.NewPage
Printer.EndDoc
End If
End Sub
Private Sub doBrowseRes_Click()
dlgDest.FileName = fName.Text
dlgDest.ShowSave
fName.Text = dlgDest.FileName
End Sub
Private Sub IE_GO_Click()
Dim URL As String
URL = IE_URL.Text
IE_WebBrowser.Navigate URL
End Sub
Private Sub PDFPrinter_OnEndDoc(ByVal JobID As Long, ByVal bOK As Long)
'
End Sub
Private Sub PDFPrinter_OnEndPage(ByVal JobID As Long, ByVal nPageNumber As Long)
'
End Sub
Private Sub PDFPrinter_OnError(ByVal JobID As Long, ByVal dwErrorCode As Long)
'
End Sub
Private Sub PDFPrinter_OnFileSaved(ByVal JobID As Long, ByVal lpszFileName As String)
MsgBox "PDF file was saved as '" + lpszFileName + "'"
End Sub
Private Sub PDFPrinter_OnFileSent(ByVal JobID As Long, ByVal lpszFileName As String)
'
End Sub
Private Sub PDFPrinter_OnStartDoc(ByVal JobID As Long, ByVal lpszDocName As String, ByVal lpszAppName As String)
MsgBox "Document '" + lpszDocName + "' started."
End Sub
Private Sub PDFPrinter_OnStartPage(ByVal JobID As Long, ByVal nPageNumber As Long)
'
End Sub
Private Sub TypeOption_Click(Index As Integer)
If (Index = vFrame) Then
Exit Sub
End If
Make_ShowHide vFrame, False
vFrame = Index
If (Index = 2) Then
If IE_URL.Text = "" Then
IE_URL.Text = "http://www.microsoft.com/"
IE_GO_Click
End If
End If
Make_ShowHide vFrame, True
End Sub
which was the PDFSDKPRO4.zip file.
I openned the VbExCom vb6 project and modified the code to use the AddImageWatermark and AddTextWatermark based on other examples seen earlier. I didn't see either of the watermarks added to the PDF.
The code is below. Let me know why the Watermarks are not there.
Regards,
Kevin
'''''''''''''''''''''''''''''''''''' CODE STARTS HERE
Option Explicit
Const SW_MINIMIZE = 11
Dim PDFPFactory As New PXCComLib.CPXCControlEx
Dim WithEvents PDFPrinter As PXCComLib.CPXCPrinter
' Attribute m_PDFPrinter.VB_VarHelpID = -1
Public vFrame As Integer
Dim pname As String
Private Declare Function ShellExecute Lib "Shell32" Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function ExtEscape Lib "Gdi32" (ByVal hDC As Long, _
ByVal nEscape As Long, ByVal cbInput As Long, ByVal lpInData As String, _
ByVal cbOutput As Long, ByVal lpOutData As Long) As Long
Private Sub Form_Unload(Cancel As Integer)
PDFPrinter.RestoreDefaultPrinter
Set PDFPrinter = Nothing
End Sub
Private Sub InitSaverObj()
Set PDFPrinter = PDFPFactory.Printer("", "PDF-XChange 4.0 Sample", "<YOUR REG CODE>", "<YOUR DEV CODE>")
pname = PDFPrinter.Name
PDFPrinter.SetAsDefaultPrinter
End Sub
Public Sub Form_Load()
InitSaverObj
TypeOption(1).Value = True
End Sub
Private Sub btnAbout_Click()
frmAbout.Show vbModal, Me
End Sub
Private Sub btnBrowseDoc_Click()
dlgOpen.FileName = m_File.Text
dlgOpen.ShowOpen
m_File.Text = dlgOpen.FileName
End Sub
Private Sub btnClose_Click()
Unload Me
End Sub
Private Sub Make_ShowHide(Index As Integer, bShow As Boolean)
frType(Index).Visible = bShow
End Sub
Private Sub btnGo_Click()
Dim fn As String
Dim D As Long
Dim D2 As Long
Dim DD As Byte
Dim P As Printer
Dim bVal As Boolean
Dim s As String
PDFPrinter.ResetDefaults
PDFPrinter.Option("Save.File") = fName.Text
PDFPrinter.Option("Save.SaveType") = "Save"
PDFPrinter.Option("Save.ShowSaveDialog") = "No"
PDFPrinter.Option("Save.WhenExists") = "Overwrite"
bVal = doCompress.Value
If (bVal = True) Then
With PDFPrinter
.Option("Compression.Graphics") = "Yes"
.Option("Compression.Text") = "Yes"
.Option("Compression.ASCII") = "No"
.Option("Compression.Color.Enabled") = "Yes"
.Option("Compression.Color.Method") = "Auto"
.Option("Compression.Indexed.Enabled") = "Yes"
.Option("Compression.Indexed.Method") = "Auto"
.Option("Compression.Mono.Enabled") = "Yes"
.Option("Compression.Mono.Method") = "Auto"
End With
Else
PDFPrinter.Option("Compression.Graphics") = "No"
PDFPrinter.Option("Compression.Text") = "No"
End If
bVal = doEmbedd.Value
PDFPrinter.Option("Fonts.EmbedAll") = IIf(bVal = True, 1, 0)
bVal = doRun.Value
PDFPrinter.Option("Save.RunApp") = bVal
If bVal = True Then
PDFPrinter.Option("Save.RunCustom") = "No"
End If
' To Hide progress window uncomment the next line
PDFPrinter.Option("Saver.ShowProgress") = "No"
PDFPrinter.Option("Watermarks.Enabled") = "Yes"
PDFPrinter.AddImageWatermark "I", "P:\DOCTRAK FORMS\temp\Lake\Older Stuff\LAKOrderVerification.bmp", -1, 210, 297, 17, 0, 0, 0, 50, 796, 0, ""
PDFPrinter.AddTextWatermark "T", "TEST", "Arial", 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 50, 28, 0, ""
PDFPrinter.Option("Watermarks.Watermarks") = "I;T"
PDFPrinter.ApplyOptions 0
If (TypeOption(2).Value) Then
IE_WebBrowser.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
ElseIf (TypeOption(1).Value) Then
ShellExecute 0, "printto", m_File.Text, """" + pname + """", vbNull, SW_MINIMIZE
ElseIf (TypeOption(0).Value) Then
For Each P In Printers
If P.DeviceName = pname Then
' Set printer as default for current session
Set Printer = P
' Stop looking for a printer
Exit For
End If
Next
'
'initialize printer
D = Printer.TwipsPerPixelX
Printer.Orientation = vbPRORPortrait
'initialized
D = Printer.hDC
'
Printer.FontName = "Arial"
Printer.FontSize = 12
Printer.CurrentX = 1000
Printer.CurrentY = 1000
Printer.Print "Sample printing from VB using PDF-XChange 4.0"
Printer.Circle (3000, 3000), 1000
Printer.NewPage
Printer.EndDoc
End If
End Sub
Private Sub doBrowseRes_Click()
dlgDest.FileName = fName.Text
dlgDest.ShowSave
fName.Text = dlgDest.FileName
End Sub
Private Sub IE_GO_Click()
Dim URL As String
URL = IE_URL.Text
IE_WebBrowser.Navigate URL
End Sub
Private Sub PDFPrinter_OnEndDoc(ByVal JobID As Long, ByVal bOK As Long)
'
End Sub
Private Sub PDFPrinter_OnEndPage(ByVal JobID As Long, ByVal nPageNumber As Long)
'
End Sub
Private Sub PDFPrinter_OnError(ByVal JobID As Long, ByVal dwErrorCode As Long)
'
End Sub
Private Sub PDFPrinter_OnFileSaved(ByVal JobID As Long, ByVal lpszFileName As String)
MsgBox "PDF file was saved as '" + lpszFileName + "'"
End Sub
Private Sub PDFPrinter_OnFileSent(ByVal JobID As Long, ByVal lpszFileName As String)
'
End Sub
Private Sub PDFPrinter_OnStartDoc(ByVal JobID As Long, ByVal lpszDocName As String, ByVal lpszAppName As String)
MsgBox "Document '" + lpszDocName + "' started."
End Sub
Private Sub PDFPrinter_OnStartPage(ByVal JobID As Long, ByVal nPageNumber As Long)
'
End Sub
Private Sub TypeOption_Click(Index As Integer)
If (Index = vFrame) Then
Exit Sub
End If
Make_ShowHide vFrame, False
vFrame = Index
If (Index = 2) Then
If IE_URL.Text = "" Then
IE_URL.Text = "http://www.microsoft.com/"
IE_GO_Click
End If
End If
Make_ShowHide vFrame, True
End Sub