Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
Stamping with a rotated shadowed text + www link |
Post Reply |
Author | |
AndrewC
Moderator Group Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
Post Options
Thanks(0)
Posted: 27 Dec 11 at 5:56AM |
Here is some C# to add a rotated text object with a shadow and then on top of this we add a web link annotation. Enjoy, Andrew. QP.LoadFromFile("unstamped.pdf", ""); int fid1 = QP.AddStandardFont(4); // Helvetica double angle = 30; for (int p = 1; p <= QP.PageCount(); p++) /* Loop through all pages in doc */ { QP.SelectPage(p); QP.SetOrigin(1); // Top left QP.SetMeasurementUnits(0); // Points QP.SelectFont(fid1); QP.SetTextAlign(1); // Align text center QP.SetTextSize(72); QP.SetTextColor(0, 0, 0); QP.DrawRotatedText(QP.PageWidth() / 2 + 3, QP.PageHeight() / 2 + 3, angle, "www.debenu.com"); // Draw Watermark at center QP.SetTextColor(0, 0, 1); QP.DrawRotatedText(QP.PageWidth() / 2, QP.PageHeight() / 2, angle, "www.debenu.com"); // Draw Watermark at center double tx = QP.GetTextWidth("www.debenu.com") / 2 * Math.Cos(angle * Math.PI / 180); double ty = QP.GetTextWidth("www.debenu.com") / 2 * Math.Sin(angle * Math.PI / 180); double x, y, w, h; double hx = QP.GetTextAscent() * Math.Sin(angle * Math.PI / 180); double hy = QP.GetTextAscent() * Math.Cos(angle * Math.PI / 180); x = QP.PageWidth() / 2 - tx - hx; y = QP.PageHeight() / 2 - ty - hy; w = tx * 2 + hx; h = ty * 2 + hy; QP.AddLinkToWeb(x, y, w, h, "http://www.debenu.com", 0); QP.SetTextSize(132); QP.SetTextColor(1, 0, 0); QP.DrawRotatedText(QP.PageWidth() / 2, QP.PageHeight() / 2 - 80, angle, "DEMO"); // Draw Watermark at center } QP.SaveToFile("out.pdf"); |
|
edvoigt
Senior Member Joined: 26 Mar 11 Location: Berlin, Germany Status: Offline Points: 111 |
Post Options
Thanks(0)
|
Hi,
this is a nice demo. Here is a transcription to Delphi. I want to have the watermark more realistic in the background. But how to do this? Remember it is possible to capture a page. On a new page with the same size we draw with the code of andrew a watermark and later we draw over it the captured original. So it looks then: uses Math; ... var fid, pid, p, n: integer; angle, tx, ty, hx, hy, x, y, w, h, pw, ph: double; sin, cos: extended; wm: string; begin QP := TQuickPDF.Create; QP.UnlockKey(...); QP.LoadFromFile('unstamped.pdf', ''); fid := QP.AddStandardFont(4); // Helvetica angle := 30; wm := 'www.debenu.com'; for p := 1 to QP.PageCount // Loop through all pages in doc do begin QP.SelectPage(p); // note the pagesize pw := QP.PageWidth; ph := QP.PageHeight; n := QP.NewPage; // is the empty new last page pid := QP.CapturePage(p); QP.SelectPage(n-1); // -1 because capture deletes the page QP.MovePage(p); // new page on the old place QP.SetPageDimensions(pw, ph); // size of the original page // // the watermark part QP.SetOrigin(1); // Top left QP.SetMeasurementUnits(0); // Points QP.SelectFont(fid); QP.SetTextAlign(1); // Align text center QP.SetTextSize(72); QP.SetTextColor(0, 0, 0); // simple shadow QP.DrawRotatedText(pw/2 + 3, ph/2 + 3, angle, wm); // Draw Watermark at center QP.SetTextColor(0, 0, 1); QP.DrawRotatedText(pw/2, ph/2, angle, wm); // Draw Watermark at center sincos(angle*pi/180, sin, cos); // calc the anglefunctions only once tx := QP.GetTextWidth(wm)/2*cos; ty := QP.GetTextWidth(wm)/2*sin; hx := QP.GetTextAscent*sin; hy := QP.GetTextAscent*cos; x := pw/2-tx-hx; y := ph/2-ty-hy; w := tx * 2 + hx; h := ty * 2 + hy; QP.AddLinkToWeb(x, y, w, h, 'http://www.debenu.com', 0); QP.SetTextSize(132); QP.SetTextColor(1, 0, 0); QP.DrawRotatedText(pw/2, ph/2-80, angle, 'DEMO'); // Draw Watermark at center // stamp the captured original content over the watermark QP.DrawCapturedPage(pid, 0, 0, pw, ph); end; QP.SaveToFile('out.pdf'); Happy new year, Werner |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store