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!
Background Watermak and Stamping with Transparency |
Post Reply |
Author | |
AndrewC
Moderator Group Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
Post Options
Thanks(0)
Posted: 13 Jul 14 at 6:31AM |
This demo code will draw transparent background image (wotermark) and text on alternate pages. It shows how to create a new content stream, draw onto it, and then move the contentstream to the background layer.
To render the resulting PDF you will need to use the new Debenu Renderer in Debenu PDF Library 10.xx versions. Refer to the README.TXT in the "Rendering and Printing Add-On" folder in the DQPL installation directory.
int ret = QP.LoadFromFile("Debenu Quick PDF Library 10.15 Reference Guide.pdf", ""); int imgId = QP.AddImageFromFile("DebenuLogo.bmp", 0); int fontId = QP.AddStandardFont(4); double angle = 30; for (int i = 1; i <= QP.PageCount(); i++) // Start at page 1. { QP.SelectPage(i); QP.NormalizePage(0); // Fix any page problems and remove rotation QP.SetOrigin(1); int csId = QP.NewContentStream(); // Create a new layer at the top that is drawn last. QP.SelectContentStream(csId); // Select the content stream QP.SaveState(); // Save the graphics state. QP.SetTransparency(90); // Now draw something into the content stream. if (i % 2 == 0) { QP.SelectImage(imgId); QP.DrawImage(0, 0, QP.PageWidth(), QP.PageHeight()); } else // Draw text { QP.SelectFont(fontId); 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.LoadState(); // Restore the graphics state QP.MoveContentStream(csId, 1); // Move the new layer/contentstream to bottom so it is drawn first. } QP.SaveToFile("out.pdf"); |
|
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