How can I create an image watermark in an existing PDF file?
I'm programing in VB.NET
Thanks
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)
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);
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?
How can I set text watermark to bottom of my every pdf page?
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));
}
}