Hi,
I'm attempting to add a watermark to a pdf using "TransparencyGroup" but can't figure out how to add the group to an existing document. I've been referencing the example which creates a new document (http://www.dynamicpdf.com/Support/Java_Help_Documentation_11_01/api-examples/TransparencyGroup.html).
' Do watermarking
If File.Exists(sNativePDFPathAndFileName) = True Then
Dim sTempFile As String = sNativePDFPathAndFileName.Replace(".pdf", "_temp.pdf")
File.Move(sNativePDFPathAndFileName, sTempFile)
Dim MyDocument As MergeDocument = New MergeDocument(sTempFile)
Dim group As TransparencyGroup = New TransparencyGroup(0.5!)
Dim MyLabel As Label = New Label("Author Copy", 30, 500, 600, 300, ceTe.DynamicPDF.Font.Helvetica, 100, TextAlign.Center, RgbColor.LightGrey)
MyLabel.Angle = -45
group.Add(MyLabel)
' Add the transparency group to the document
MyDocument.() ' <--
MyDocument.Draw(sNativePDFPathAndFileName)
File.Delete(sTempFile)
End If
Any help or advice will be greatly appreciated.
Regards Allan
Add watermark text
Re: Add watermark text
Support · Jun 7, 2012Hello Allan,
You can add watermark to the already existing PDF document without any problem. You will need create Template object and add the TransparencyGroup to this template and stamp it to the MergeDocument object using Template property. Below is the sample code for it.
Dim MyDocument As MergeDocument = New MergeDocument("C:\MyDocument1.pdf")
Dim group As TransparencyGroup = New TransparencyGroup(0.5!)
Dim MyLabel As Label = New Label("Author Copy", 30, 500, 600, 300, ceTe.DynamicPDF.Font.Helvetica, 100, TextAlign.Center, RgbColor.LightGrey)
MyLabel.Angle = -45
group.Add(MyLabel)
Dim MyTemplate As Template = New Template()
'Add group to template.
MyTemplate.Elements.Add(group)
'Stamp the template to Mydocument object.
MyDocument.Template = MyTemplate
MyDocument.Draw("C:\Output.pdf")
Thanks,
ceTe Software Support Team.
Re: Add watermark text
Forum member · Jun 7, 2012Hi,
Thanks very much for your prompt response.
I've added in the template but have a problem where the pdf contains images the watermark is completely hidden behind the images, is there anyway around this?
I'm happy to send you a screen print or a copy of the file.
Regards Allan
Re: Add watermark text
Support · Jun 7, 2012Hello Allan,
The Template property of the MergeDocument class adds the new contents beneath the already existing contents. You can use StampTemplate property of the MergeDocument class to stamp the template to the document and this will work for you. Below is the line of code for it.
MyDocument.StampTemplate = MyTemplate
Thanks,
ceTe Software Support team.
Re: Add watermark text
Forum member · Jun 7, 2012Hi,
Excellent that seems to be working.
Many thanks!
Regards Allan