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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > Sample Code
  New Posts New Posts RSS Feed - Background Watermak and Stamping with Transparency
  FAQ FAQ  Forum Search   Register Register  Login Login

Background Watermak and Stamping with Transparency

 Post Reply Post Reply
Author
Message
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 836
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Topic: Background Watermak and Stamping with Transparency
    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");

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store