Print Page | Close Window

Watermark text in PDF using Quick PDF libary

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3767
Printed Date: 25 Apr 24 at 5:46AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Watermark text in PDF using Quick PDF libary
Posted By: ssivasankaran
Subject: Watermark text in PDF using Quick PDF libary
Date Posted: 09 Dec 19 at 6:52AM
Hi,

I want to create watermark text in pdf using quick pdf library. Could you give me a sample program to insert watermark text in pdf? If the code is in C# then it will be helpful for me.

Regards
Santhanaraman.S



Replies:
Posted By: Ingo
Date Posted: 09 Dec 19 at 8:36AM
Hi,

i think you've didn't read/search in the online reference 'till now? ;-)
Here's a C#-sample from the kb:
https://www.debenu.com/kb/programmatically-add-watermark-stamp-pdf/

Cheers and welcome here,
Ingo



-------------
Cheers,
Ingo



Posted By: ssivasankaran
Date Posted: 09 Dec 19 at 8:58AM
Hi,

Thanks for your response. I have converted the code into c# mentioned in the following link.

http://www.quickpdf.org/forum/watermark_topic230.html" rel="nofollow - http://www.quickpdf.org/forum/watermark_topic230.html

*******************************************************************************
            string printFile = fileName;
            int transp = 10; //The transparency as a percent value
            int drewin = 35; //Angle of rotation... try with values over and below zero... not more than -45 to 45
            string ausr;
            if (_objPdfLibrary.Unlocked() == 1)
            {
                try
                {
                    string waterMarkText = "Uncontrolled Copy";

                    if (waterMarkText.Trim().Length > 40) //The text should have max. 40 characters
                        waterMarkText = waterMarkText.Substring(1, 40);

                    _objPdfLibrary.LoadFromFile(fileName, "");
                    _objPdfLibrary.SetOrigin(1);
                    _objPdfLibrary.SetMeasurementUnits(0); //means pixel
                    for(int i = 1 ; i<= _objPdfLibrary.PageCount();i++)
                    {
                        int ts, tl, th;
                        ts = tl = 0;
                        _objPdfLibrary.SelectPage(i);
                        int sc1 = i / 2;
                        int sc2 = i * 2;
                        if (_objPdfLibrary.PageWidth() < 250)
                            ts  = 8;
                        if ((_objPdfLibrary.PageWidth() > 249) && (_objPdfLibrary.PageWidth() < 400))
                            ts = 12;
                        if ((_objPdfLibrary.PageWidth() > 399) && (_objPdfLibrary.PageWidth() < 650) )
                            ts = 18;
                        if ((_objPdfLibrary.PageWidth() > 649) && (_objPdfLibrary.PageWidth() < 1500))
                            ts = 22;
                        if ((_objPdfLibrary.PageWidth() > 1499) && (_objPdfLibrary.PageWidth() < 2500)) 
                            ts = 30;
                        if(_objPdfLibrary.PageWidth() > 2499) 
                            ts = 38;

                        _objPdfLibrary.SetTextSize(ts);

                        int tw = tl * ts; //Textwidth is the sum from length * size...
                        tw = tw / 2;
                        tw = tw + drewin;
                        th = (tw * drewin) / 45;

                        _objPdfLibrary.SetTransparency(transp);
                        if (ausr == 'lo')
                        _objPdfLibrary.DrawRotatedText(ts, th, drewin, waterMarkText); // left - top - width - height
                        if (ausr == 'lu')
                        _objPdfLibrary.DrawRotatedText(ts, _objPdfLibrary.PageHeight() - th, drewin, waterMarkText); // left - top - width - height
                        if (ausr == 'ro')
                        _objPdfLibrary.DrawRotatedText(_objPdfLibrary.PageWidth() - tw, ts, drewin, waterMarkText); // left - top - width - height
                        if (ausr == 'ru')
                        _objPdfLibrary.DrawRotatedText(_objPdfLibrary.PageWidth() - tw, _objPdfLibrary.PageHeight() - tl, drewin, waterMarkText); // left - top - width - height

                        _objPdfLibrary.CompressContent();
                    }

                    _objPdfLibrary.SaveToFile(fileName);
                }
                catch (Exception ex)
                {
                    
                }
            }
**************************************************************************

But unable to convert the following code. I can't understand.

   if cbausr.Text = 'Links oben'    then ausr := 'lo'; //top left
   if cbausr.Text = 'Links unten'   then ausr := 'lu'; //bottom left
   if cbausr.Text = 'Rechts oben'   then ausr := 'ro'; //top right
   if cbausr.Text = 'Rechts unten' then ausr := 'ru'; //bottom right

Could you explain the above?

Thanks and Regards
Santhanaraman.S


Posted By: Ingo
Date Posted: 09 Dec 19 at 6:51PM
cbausr.Text means the selected content of a combobox.
If you choose "Links unten" variable ausr will set to "lu".
"lu" means left, bottom and has to do with a simple alignment of the watermark.




-------------
Cheers,
Ingo



Posted By: ssivasankaran
Date Posted: 10 Dec 19 at 4:35AM
Thank you so much. It's working for me.

Thanks and Regards
Santhanaraman.S


Posted By: Ingo
Date Posted: 10 Dec 19 at 10:52PM
a NormalizePage before the stamp is always a good option...



-------------
Cheers,
Ingo




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