Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Oct 31, 2013 9:15 am

How can I create an image watermark in an existing PDF file?

I'm programing in VB.NET

Thanks

inyazar
 
Posts: 24
Joined: Wed Jul 03, 2013 8:38 am

Fri Nov 01, 2013 2:38 am

Hello,

Thanks for your inquiry.

Please refer to the following code to create an image watermark in an existing PDF file. And the full demo is in the attachment,
which doesn't include Spire.pdf dll, please add it and check.
Code: Select all
Dim pdfdoc As PdfDocument = New PdfDocument
pdfdoc.LoadFromFile("..\..\sample.pdf")
Dim img As Image = Image.FromFile("..\..\Background.png")
pdfdoc.Pages(0).BackgroundImage = img
pdfdoc.SaveToFile("..\..\AddWatermark.pdf", FileFormat.PDF)

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Mon Nov 04, 2013 8:59 am

Thank you Gary.

I'll try it.

Best regards

inyazar
 
Posts: 24
Joined: Wed Jul 03, 2013 8:38 am

Thu Nov 28, 2013 11:56 am

Hi Gary,

I'll try your code and doesn't work for me.

I send you the files

Thanks a lot

Best regards,
galder

inyazar
 
Posts: 24
Joined: Wed Jul 03, 2013 8:38 am

Fri Nov 29, 2013 6:07 am

Hello galder,

Thanks for your feedback.
Actually, it is added to the PDF, the reason you didn't see the content of the image is that the color of the image you provided is too light, after setting its transparency, its content is almost invisible, and our method to add image watermark to the PDF is that firstly set the transparency of the image, then add the image on the pdf page, so we suggest that you redesign the image. So sorry for inconvenience.
If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Wed Dec 04, 2013 8:34 am

Hello galder,

Has the issue been resolved? Could you please give us some feedback if convenience?

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Dec 10, 2013 12:23 pm

Hello Gary,

The issue was resolved with your solution.

Thanks.

Best Regards,
Galder

inyazar
 
Posts: 24
Joined: Wed Jul 03, 2013 8:38 am

Wed Dec 11, 2013 1:19 am

Hello Galder,

Thanks for your feedback. Happry to hear that.
If there are any questions, welcome to get it back to us.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Sat Mar 29, 2014 8:59 am

Hello Sir,
How to give image watermark to pdf file which is password protected and we know that password already?
i tried code for unlock pdf and its working fine.but it is not working for lock pdf.
Please provide me solution for this
Regards,
Pravin Bangar
(bangarpravin22@gmail.com)

bangarpravin22
 
Posts: 7
Joined: Thu Mar 27, 2014 9:12 am

Mon Mar 31, 2014 2:37 am

Hello Pravin,

Sorry for late reply as weekend.
Thanks for your inquiry.
Please try the below code, if the issue still exists, please provide us your document if convenience.
Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(your filename, the password);
Image img = Image.FromFile("watermark.png");
doc.Pages[0].BackgroundImage = img;
doc.SaveToFile("result.pdf",FileFormat.PDF);


Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Apr 01, 2014 6:08 am

Hello Gary

Thanks for your reply.The issue is resolved with your solution.
watermark get applied to lock as well as unlock pdf.
However I have one more query to ask you.After applying watermark to lock pdf file
how can i open it by sending password through programm?
I tried following code to open lock pdf file (password:123456)
Process.Start(fileName)
Thread.Sleep(1200)
SendKeys.Send("123456~")

but above solution is not 100% perfect.Could you please provide me solution on this?

Regards,
Pravin Bangar

bangarpravin22
 
Posts: 7
Joined: Thu Mar 27, 2014 9:12 am

Tue Apr 01, 2014 7:27 am

Hello,

Thanks for your response. Sorry that we don't have better idea for this. If you do this only for viewing the pdf, you could try our Spire.PdfViewer product.

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Fri Apr 04, 2014 9:30 am

Hi,

Have you tried our Spire.PdfViewer product ?How did it work?
If you have any question please feedback to us.
Best regards,
Lisa
E-iceblue support team
User avatar

lisa.chen
 
Posts: 21
Joined: Thu Mar 20, 2014 2:31 am

Fri Apr 04, 2014 11:10 am

Hello Gary
Thanks for all your response.I used your both product but I have some more query to ask you.
In PdfViewer
I tried trial version of Spire PdfViewer.
In that I able to view one pdf at a time.On one button click i want to open one pdf file and on another button click
I want to open another pdf file.Using PdfViewer module How can I open pdf file by keeping priviously open pdf file as it is?
.

In Spire.Pdf
How can I set text watermark to bottom of my every pdf page?
At present I adjust x and y point so that watermark will display at bottom.
But sometimes it doesn't display .is there any way to detect pdf page bottom?
I hope you understand my problem.Please reply me....

Regards,
Pravin Bangar

bangarpravin22
 
Posts: 7
Joined: Thu Mar 27, 2014 9:12 am

Mon Apr 07, 2014 6:29 am

Hello,

Thanks for your query.
In that I able to view one pdf at a time.On one button click i want to open one pdf file and on another button click
I want to open another pdf file.Using PdfViewer module How can I open pdf file by keeping priviously open pdf file as it is?

Sorry that the product only views one pdf at a time. For your need, you have to create two pdfViewer, then control them using the different buttons.
How can I set text watermark to bottom of my every pdf page?

Please refer the below code
Code: Select all
  class Program
    {
        static void Main(string[] args)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            doc.PageSettings.Margins.All = 0;

            SetDocumentTemplate(doc, PdfPageSize.A4, 40);

            PdfDocument original = new PdfDocument();

            original.LoadFromFile("test.pdf");

            PdfPageBase page = null;

            foreach (PdfPageBase origianlPage in original.Pages)
            {
                page = doc.Pages.Add(new SizeF(origianlPage.Size.Width, origianlPage.Size.Height + 40));//add the TopSpace height
                origianlPage.CreateTemplate().Draw(page, 0, 0);

            }
            doc.PageSettings.Margins.Top = 40;
            doc.PageSettings.Margins.Left = 90;
            doc.SaveToFile("output.pdf");
            System.Diagnostics.Process.Start("output.pdf");
        }
        private static void SetDocumentTemplate(PdfDocument doc, SizeF pageSize, float height)//height, is the topSpace height depends on the added content
        {
            PdfPageTemplateElement BottomSpace = new PdfPageTemplateElement(pageSize.Width, height);
            BottomSpace.Foreground = true;
            doc.Template.Bottom = BottomSpace;

            PdfTilingBrush brush = new PdfTilingBrush(new SizeF(BottomSpace.Width, BottomSpace.Height));
            brush.Graphics.SetTransparency(0.3f);
            brush.Graphics.Save();
            brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
            brush.Graphics.DrawString("Spire.Pdf Demo", new PdfFont(PdfFontFamily.Helvetica, 24), PdfBrushes.Black, -10,-10, new PdfStringFormat(PdfTextAlignment.Right,PdfVerticalAlignment.Top));
            brush.Graphics.Restore();
            brush.Graphics.SetTransparency(1);
            BottomSpace.Graphics.DrawRectangle(brush, new RectangleF(0,0,pageSize.Width,height));

        }


    }


If there are any questions, welcome to get it abck to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.PDF