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.

Tue Nov 13, 2018 4:37 pm

Hi,

I open en existing pdf file to add text.
In the original file there is an hyperlink on page 2 that redirects to page 3.

I cannot manage to keep this link working once the file is watermarked and the stream saved.

Here is the code i use :

Code: Select all
PdfBrush color= PdfBrushes.Red;

System.Drawing.Font FontWatermark = new System.Drawing.Font("Arial", 12);

Spire.Pdf.PdfDocument originalDoc = new Spire.Pdf.PdfDocument(originalFileStream);
PdfDocument watermarkedDoc = new PdfDocument();

foreach (PdfPageBase page in originalDoc.Pages)
{
   PdfPageBase newPage = watermarkedDoc.Pages.Add(page.Size, new PdfMargins(0));
   
   PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width, page.Canvas.ClientSize.Height)); 
   brush.Graphics.Save();

   brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height - 40);
   brush.Graphics.DrawString("watermark to apply", new PdfTrueTypeFont(FontWatermark), color, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));
   break;

   brush.Graphics.Restore();
   brush.Graphics.SetTransparency(1);
   page.CreateTemplate().Draw(newPage, new PointF(0, 0));
   newPage.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), newPage.Canvas.ClientSize));
}
watermarkedDoc.SaveToStream(watermarkedStream);


In attachment you ll find a test file.

Thanks for your help.

LisiAero
 
Posts: 11
Joined: Tue Nov 13, 2018 12:04 pm

Wed Nov 14, 2018 7:21 am

Hi,

Thanks for your inquiry.
Please refer to the below code to keep the hyperlink.
Code: Select all
            Spire.Pdf.PdfDocument originalDoc = new Spire.Pdf.PdfDocument();
            originalDoc.LoadFromStream(originalFileStream);
            PdfDocument watermarkedDoc = (PdfDocument)originalDoc.Clone();           
            foreach (PdfPageBase page in watermarkedDoc.Pages)
            {   
                PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width, page.Canvas.ClientSize.Height));
                PdfBrush color = PdfBrushes.Red;
                System.Drawing.Font FontWatermark = new System.Drawing.Font("Arial", 12);
                brush.Graphics.Save();
                brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height - 40);
                brush.Graphics.DrawString("watermark to apply", new PdfTrueTypeFont(FontWatermark), color, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));
                page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));
            }           
            watermarkedDoc.SaveToStream(watermarkedStream);
        }
Sincerely,
Mike
E-iceblue support team
User avatar

Mike.Zhang
 
Posts: 93
Joined: Thu Sep 27, 2018 7:11 am

Wed Nov 14, 2018 9:12 am

Hi

Thanks for your answer.

I tried your code bu tun fortunately an exception is raised on
Code: Select all
PdfDocument newDoc = (Spire.Pdf.PdfDocument)doc.Clone();


Here is the exception message :
Unable to cast object of type 'spr7086' to type 'Spire.Pdf.PdfDocument'



spr7086 appears to be the PdfStandard

LisiAero
 
Posts: 11
Joined: Tue Nov 13, 2018 12:04 pm

Wed Nov 14, 2018 10:06 am

Hi,

I have confirmed that the latest Spire.Office (DLL Only) Version:3.11.3 works well. Please use this version instead. Attached is the result on my side.
Sincerely,
Mike
E-iceblue support team
User avatar

Mike.Zhang
 
Posts: 93
Joined: Thu Sep 27, 2018 7:11 am

Wed Nov 14, 2018 11:00 am

Thanks for your answer.

I use Spire.Pdf version 3.8.206.4035.
What version of Spire.Pdf is included in " Spire.Office (DLL Only) Version:3.11.3 " ?

Edit : I found that Spire.pdf v4.11.6 is in Spire.Office

If i only upgrade Spire.Pdf dll, is it going to work ?

Edit : i tried with version Spire.Pdf 4.11.5.2035 and needed to upgrade to Spire.Licence 1.3.7.35. Your code works fine and the hyperlinks are working.

LisiAero
 
Posts: 11
Joined: Tue Nov 13, 2018 12:04 pm

Thu Nov 15, 2018 3:34 am

Hi,

Thanks for your feedback.
Kindly note that if you only need the features of the Spire.PDF, you can use the Spire.PDF Pack(Hot Fix) Version:4.11.5. If you need two or more products working in one project, please use the Spire.Office (DLL Only) Version:3.11.3.
Sincerely,
Mike
E-iceblue support team
User avatar

Mike.Zhang
 
Posts: 93
Joined: Thu Sep 27, 2018 7:11 am

Tue Nov 27, 2018 8:46 am

Hi Mike.

I have one question regarding Spire products.
Spire.XLS and Spire.PDF are used in one of our project.

To resolve conversions issues and watermaks problems i downloaded separately the dlls Spire.PDF 4.11.8.2035 and Spire.xls 8.11.6.6035 (pro version). I need Spire.XLS pro version in order to convert XLS to PDF.

My manager and i are new on this project and have few hitorical knowledge regarding Spire products.
When my manager wanted to renew the licence he's been told that we purchased in the past Spire.Office.
Below is the answer that one of your vendor sent to our reseller :

Thanks for your message. I checked our records and found that the customer purchased the Spire.Office from us before rather than Spire.PDF, while your message shows they want to purchase Spire.PDF. Could you please double check with your client?

My question is : are the dlls Spire.PDF 4.11.8.2035 and Spire.xls 8.11.6.6035 (pro version) in the Spire.Office package ?
Is there also a Spire.Pdf pro version like Spire.XLS?

Thanks for your answer.

LisiAero
 
Posts: 11
Joined: Tue Nov 13, 2018 12:04 pm

Tue Nov 27, 2018 10:33 am

Hi,

Thanks for your inquiry.
Yes. the dlls Spire.PDF 4.11.8.2035 and Spire.xls 8.11.6.6035 (pro version) are in the Spire.Office Platinum (DLL Only) Version:3.11.5.
Yes, Spire.Pdf has pro version like Spire.XLS.
By the way, if you only want to use Spire.PDF Pro version and Spire.XLS Pro version, you can only buy the license of Spire.PDF Pro version and the license of Spire.XLS pro edition then apply two licenses. Note if you need two or more products working in one project, please downloadSpire.Office and reference corresponding dlls from it.
Sincerely,
Mike
E-iceblue support team
User avatar

Mike.Zhang
 
Posts: 93
Joined: Thu Sep 27, 2018 7:11 am

Tue Nov 27, 2018 10:53 am

Mike,

Thanks for the information. We will need Spire.Office.

I understand i need the office platinum version to have Spire.XLS pro version, is that right ?

Is it Spire.PDF standard edition or pro in the platinum package ?

When i go to this page i can't see the two versions of the Office package:
https://www.e-iceblue.com/Buy/Spire.Office.html

LisiAero
 
Posts: 11
Joined: Tue Nov 13, 2018 12:04 pm

Wed Nov 28, 2018 3:52 am

Hi,

Before answering your questions, let me explain a few points.
1. There is no standard edition of Spire.PDF.
Spire.PDF pro edition only includes Spire.PDF for .NET.
Spire.PDF Pack is a compilation of Spire.PDF for .NET, Spire.PDF for Silverlight and Spire.PDF for WPF.
2. Spire.Office Platinum (Pack) is a compilation of every .NET, Silverlight and WPF component offered by e-iceblue.
And Spire.Office for .NET only includes all pro versions of our products for .NET.
3. The products on our download page are the pack version in general, that means it includes all platforms of dlls. After downloading the package you need to reference corresponding dlls from the folder(e.g. NET folder, WPF folder).

Below is my answer to your questions.
1. Yes, if you only need .NET product, please buy Spire.Office for .NET, rather than Spire.Office platinum.
2. There is no standard edition of Spire.PDF. The Spire.pdf.dll in the .NET folder of Spire.Office package is pro version.
Besides, here is detailed information of our products.
https://www.e-iceblue.com/Download/product-list.html
Sincerely,
Mike
E-iceblue support team
User avatar

Mike.Zhang
 
Posts: 93
Joined: Thu Sep 27, 2018 7:11 am

Return to Spire.PDF