Hi
We have a problem when adding a watermark text to an existing PDF document. Please see below is the code snippet for your reference. If we add section and watermark to existing pdf document, its throwing an error 'Object reference not set'. If I add only water mark then entire PDF document content gets corrupted/erased and nothing is getting saved
Could you please help us on this
Regards,
Balaji
public static string AddWaterMarkInPDF()
{
//Aspose.Pdf.Pdf p = new Aspose.Pdf.Pdf("t.pdf");
//System.IO.MemoryStream mem = new System.IO.MemoryStream();
//p.Save(mem, Aspose.Pdf.SaveType.OpenInAcrobat);
try
{
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(@"Aspose.Pdf.lic");
FileInfo f = new FileInfo(@"input.pdf");
FileStream fs = f.Open(FileMode.Open, FileAccess.ReadWrite);
Pdf pdf1 = new Pdf(fs);
//Aspose.Pdf.Section sec1 = pdf1.Sections.Add();
//Aspose.Pdf.Text text1 = new Text(sec1, "This is text in section1.");
////text1.Left = 30;
////text1.Top = 100;
//sec1.Paragraphs.Add(text1);
FloatingBox watermark1 = new FloatingBox(300, 300);
watermark1.BoxHorizontalPositioning = BoxHorizontalPositioningType.Page;
watermark1.BoxHorizontalAlignment = BoxHorizontalAlignmentType.Center;
watermark1.BoxVerticalPositioning = BoxVerticalPositioningType.Page;
watermark1.BoxVerticalAlignment = BoxVerticalAlignmentType.Center;
watermark1.Paragraphs.Add(image1);
pdf1.Watermarks.Add(watermark1);
pdf1.Close();
fs.Close();
//pdf1.Save(@"C:\Testpdf\abc.pdf");
// (fs);
return "success";
}
catch (Exception e)
{
return "failed";
}
}