|
InsertCompositeWatermark Method |
Top Previous Next |
|
The InsertCompositeWatermark method inserts composite watermark (combination of both text and image watermark) to the PDF document.
Syntax
Parameters
CompositeWatermark [in] Dispatch pointer of the Instance of CgtCompositeWatermarkTamplate. The Composite watermark instance is a list of text and image watermarks. Dispatch pointer of the Instance of CgtTextWatermarkTamplate with all the necessary properties of the text watermark set.
Exceptions Raised
If the PDFtoolkit does not support the font provided for text watermark, then EUnsupportedFontError exception is raised.
Example Code
[VC++] CY fontSize; CgtTextWatermarkTemplate watermark, refWatermark; CgtCompositeWatermarkTemplate comp; CgtImageWatermarkTemplate img;
LPCSTR fname; CBitmap Bmp; unsigned long bmpHandle;
fname = "BitmapImage.bmp"; HANDLE hBmp = LoadImage(NULL, fname,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
Bmp.Attach(hBmp); bmpHandle = (long)HBITMAP(Bmp);
img = m_PDF.GetImageWatermark();
img.SetName("Image Watermark"); img.SetImageByHandle( bmpHandle , itBitmap);
img.SetHorizPos(hpCenter); img.SetVertPos(vpMiddle);
watermark = m_PDF.GetTextWatermark(); watermark.SetName("Text watermark"); watermark.SetText("Text watermark"); fontSize.int64 = 24 * 10000; watermark.GetFont().SetSize(fontSize); watermark.SetTextColor(RGB(255, 0, 0)); watermark.SetHorizPos(hpCenter);
watermark.SetOverlay(true);
comp = m_PDF.GetCompositeWatermark(); comp.AddTextWatermark(watermark.m_lpDispatch); comp.AddImageWatermark(img.m_lpDispatch);
if (comp.GetWatermarkTypeAt(0) == wtTextWatermark) { refWatermark = comp.GetTextWatermarkAt(0); refWatermark.SetText("Changed watermark Text"); }
m_PDF.LoadFromFile("Input.pdf"); m_PDF.InsertCompositeWatermark(comp.m_lpDispatch); m_PDF.SaveToFile("Output.pdf");
[VB] Dim txtWatermark As gtTextWatermarkTemplateX Dim img As gtImageWatermarkTemplateX Dim refWatermark As gtTextWatermarkTemplateX Dim comp As gtCompositeWatermarkTemplateX
Set txtWatermark = gtPDFDocumentX1.GetTextWatermark Set img = gtPDFDocumentX1.GetImageWatermark Set comp = gtPDFDocumentX1.GetCompositeWatermark
img.Name = "Image Watermark" img.SetImageByHandle Image1.Picture.Handle, itBitmap img.Overlay = True img.VertPos = vpTop img.HorizPos = hpCenter
txtWatermark.Text = "Text watermark" txtWatermark.HorizPos = hpCenter txtWatermark.Overlay = True
txtWatermark.TextColor = RGB(255, 0, 0) txtWatermark.Font.Size = 70 txtWatermark.Font.Bold = False txtWatermark.Font.Italic = True txtWatermark.Font.Underline = True
Call comp.AddTextWatermark(txtWatermark) Call comp.AddImageWatermark(img)
Set refWatermark = comp.GetTextWatermarkAt(0) refWatermark.Text = "Changed watermark text"
gtPDFDocumentX1.LoadFromFile ("Input.pdf") Call gtPDFDocumentX1.InsertCompositeWatermark(comp) gtPDFDocumentX1.SaveToFile ("Output.pdf")
|