Page 1 of 1

AddImageWatermark and AddTextWatermark for API

Posted: Fri Apr 13, 2012 3:46 pm
by kmoens
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

Re: AddImageWatermark and AddTextWatermark for API

Posted: Thu Apr 19, 2012 5:22 pm
by kmoens
Has anyone been able to reproduce this issue?

This is for a customer that we are upgrading from PDF X-Change 3.0 to 4.0. I am just looking to get this going.

--Kevin

Re: AddImageWatermark and AddTextWatermark for API

Posted: Thu Apr 19, 2012 5:37 pm
by John - Tracker Supp
Hi Kevin,

not wishing to be pedantic - but looking through code is never easy and you quickly become 'code blind' - a small working example is a far better way to proceed and will elicit a quicker answer - please provide a simple example that displays the issue - both project source and compiled and zip and send - if you wish to leave you license info in the example - PLEASE DO NOT POST HERE - please send to support@pdf-xchange.com with a link back to this forum post.

Once we have we wil take a look as soon as possible

Re: AddImageWatermark and AddTextWatermark for API

Posted: Thu Apr 19, 2012 6:25 pm
by kmoens
I attached VbExCOM.zip.
This contains the source and compiled VB6 example into a zip file.

Below are the lines added that are not in the basic demo:

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

--kevin

Re: AddImageWatermark and AddTextWatermark for API

Posted: Thu Apr 19, 2012 6:27 pm
by Walter-Tracker Supp
Thank you; I will take a look and get back to you asap.

-Walter

Re: AddImageWatermark and AddTextWatermark for API

Posted: Thu Apr 19, 2012 6:47 pm
by Walter-Tracker Supp
It looks like you have set the flags argument to "796" in the image watermark case, binary 1100011100... I'm not sure what the high bits are intended to do here but they will probably be ignored... however, since the second last bit is not set it will not be visible in the viewer. I just noticed there's an error in the documentation (flags offset by one) and it will be fixed shortly. Set flags to decimal 14 (binary 1110) to set all bits except background. The flags are binary 1 for placement in background, 10 for viewer, 100 for export visibility, and 1000 for printing visibility...

Same problem with the flags for the text watermark: should be 14 (binary 1110), not 28 (binary 11100). I will get this documentation typo fixed ASAP.

Also, in the text case, you are using a font weight of zero. It should be 400 for normal and 700 for bold.

Font size is also set to zero; this may be intentional (font will be adjusted to fit entire page), but it may be an oversight you will want to fix as well. dwAlign is set to 17, but because font size is zero this will be ignored and interpreted as horizontal & vertical centering (value 9).

Re: AddImageWatermark and AddTextWatermark for API

Posted: Wed Apr 25, 2012 10:18 am
by David_Carle
Can you advise if the documentation has been updated now, and if so what the date and/or version number are?

The version of PDFX4DRV_API.pdf that I'm using is dated 15/04/2008 (in the PDF properties) and it seems to contain numerous mistakes.

If there's an updated version can you please give me a link to it?

Thanks

Re: AddImageWatermark and AddTextWatermark for API

Posted: Wed Apr 25, 2012 12:50 pm
by Tracker Supp-Stefan
Hi David,

Checking now with the guys maintaining the manuals, and as soon as I get an update we will post back here.

Best,
Stefan

Re: AddImageWatermark and AddTextWatermark for API

Posted: Mon Apr 30, 2012 12:48 pm
by David_Carle
Hi Stefan

While you're waiting on a response from "the guys maintaining the manuals", can you please advise what is the latest version of documentation that you have access to?

I really hope that it has been updated since 2008.

Thanks

Re: AddImageWatermark and AddTextWatermark for API

Posted: Mon Apr 30, 2012 4:06 pm
by Tracker Supp-Stefan
Hi David,

The attached copy is from 14 Feb this year, though I can't tell what the changes in it are.

Best,
Stefan

Re: AddImageWatermark and AddTextWatermark for API

Posted: Tue May 01, 2012 11:36 am
by David_Carle
Thanks Stefan

Please also see my comments about this manual at
https://forum.pdf-xchange.com/ ... 44&t=13428

Re: AddImageWatermark and AddTextWatermark for API

Posted: Tue May 01, 2012 12:03 pm
by Tracker Supp-Stefan
Hi David,

Checking it already!

Cheers,
Stefan

Re: AddImageWatermark and AddTextWatermark for API

Posted: Wed May 09, 2012 6:59 pm
by kmoens
I updated making the changes you suggested and then I also included the bitmap I am testing with. I still do not see these watermarks.

I uploaded the zip file with the changes.

--Kevin

Re: AddImageWatermark and AddTextWatermark for API

Posted: Wed May 09, 2012 7:30 pm
by Walter-Tracker Supp

Code: Select all

 PDFPrinter.AddImageWatermark "I", "P:\DOCTRAK FORMS\temp\Lake\Older Stuff\LAKOrderVerification.bmp", -1, 210, 297, 17, 0, 0, 0, 50, 796, 0, ""

The syntax for this function is:

Code: Select all

Sub AddImageWatermark(
sName As String,
sImageFileName As String,
dwTranscolor As Long,
dwWidth As Long,
dwHeight As Long,
dwAlign As Long,
xOffset As Long,
yOffset As Long,
nAngle As Long,
dwOpacity As Long,
dwFlags As Long,
dwPlaceType As Long,
sRange As String)
In your example you have:

dwTranscolor = -1
dwWidth = 210
dwHeight = 297
dwAlign = 17
xOffset = 0
yOffset = 0
nAngle = 0
dwOpacity = 50
dwFlags = 796
dwPlaceType = 0
sRange = ""

Can you do as I originally suggested and change dwFlags to 14?

You have also not made the changes I suggested to AddTextWatermark, for flags and font weight.

(Also, this is an unrelated issue that will make your life easier, if you set variables with sensible names and pass those to the function it will make your coding life much easier, so you can see what each argument is set to instead of just seeing a long list of values. ie, PDFPrinter.AddTextWatermark(name, content, font, ...))..

Re: AddImageWatermark and AddTextWatermark for API

Posted: Wed May 09, 2012 9:32 pm
by kmoens
Sorry about that... the VB6 app died and lost the changes. So I zipped up the wrong code. Re-made the changes and retested still with no luck.
--Kevin

Re: AddImageWatermark and AddTextWatermark for API

Posted: Wed May 09, 2012 10:39 pm
by Walter-Tracker Supp
Please try placing each watermark (text, and then image) in isolation to help narrow down which one might be causing the problem.

It could be something as simple as failing to load the image from disk (e.g. incorrect path).

-Walter

Re: AddImageWatermark and AddTextWatermark for API

Posted: Thu May 10, 2012 12:55 pm
by kmoens
In the last zip file I uploaded I moved the bitmap next to the executable path.

Everything should be in the zip file for you to test.

I am looking to make an ImageWatermark act like an overlay with an RGB value of (244, 244, 244) as the Transparent Color.

With PDF X-Change 3.0 we put these setting in the Printing Preferences - Watermarks area.

I am not concerned with the TextWatermark as much.

--Kevin

Re: AddImageWatermark and AddTextWatermark for API

Posted: Mon May 14, 2012 9:16 pm
by Walter-Tracker Supp
Hi, I have been unable to build your VB6 project - however I will still do my best to help you.

Could you try adding only a single watermark, using the same image. If this fails, try to do the same with a different image and see if this works?

-Walter

Re: AddImageWatermark and AddTextWatermark for API

Posted: Mon Jul 02, 2012 2:42 pm
by kmoens
I did my tests. 14 as your suggestion still kept the Background Flag checked
0001 = ?
0010 = Background
0100 = View
1000 = Export
1 0000 = Print 


I also found out when I used single Character names such as "I" for Image and "T" for Text it wouldn't select the watermark.

Attached is a word doc holding screen shots of the tests I tried.

Re: AddImageWatermark and AddTextWatermark for API

Posted: Mon Jul 02, 2012 2:46 pm
by kmoens
Is there a way to set the flag "Fit To Page"?

Re: AddImageWatermark and AddTextWatermark for API

Posted: Mon Jul 02, 2012 3:39 pm
by Tracker Supp-Stefan
Hello kmoens,

Seems like the Screenshots you wanted to attach two posts above went missing - you will need to zip them before uploading.

As for the FitPage - you need to set General.MagnificationType to 2 (FitPage).

Best,
Stefan