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.