Print Page | Close Window

Background Watermak and Stamping with Transparency

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2934
Printed Date: 22 Nov 24 at 7:06PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Background Watermak and Stamping with Transparency
Posted By: AndrewC
Subject: Background Watermak and Stamping with Transparency
Date 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");




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk