We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Watermark text on pdf file using aspose.pdf.kit

Can u pls go through the below code ...in below code they r using input and output files..but as per my requirement.....i dont want input file..iam getting bytes and i have to write to meemory stream and then pass to some pdf file as input to PdfFileInfo.

string inFile = @"C:\input.PDF";

string outFile = @"C:\kit.PDF";

// create PdfFileInfo object to get PDF file information

PdfFileInfo fileInfo = new PdfFileInfo(infile);

// create Stamp object

Stamp aStamp = new Stamp();

// create a sample formatting text with Maroon as font color and text size as 50

FormattedText formatted = new FormattedText("Draft Document", System.Drawing.Color.Maroon, Aspose.Pdf.Kit.FontStyle.HelveticaBold, EncodingType.Winansi, true, 50);

aStamp.BindLogo(formatted);

aStamp.IsBackground = false;

// specify the page number over which watermark should be displayed

// aStamp.Pages = new int[] { };

// Watermark rotation angle

aStamp.Rotation = 45;

// specify the opacity value for watermark

aStamp.Opacity = 0.5F;

//specifies the position of stamp

aStamp.SetOrigin(fileInfo.GetPageWidth(1) / 3, fileInfo.GetPageHeight(1) / 2);

PdfFileStamp stamper = new PdfFileStamp(inFile, outFile);

stamper.AddStamp(aStamp);

stamper.Close();

Hi Deepi,

I have tested this issue at my end using Aspose.Pdf.Kit for .NET, but couldn’t notice any such problem. I have used the following code snippet:


byte[] data = File.ReadAllBytes(“input.pdf”);

PdfFileInfo info = new PdfFileInfo(new MemoryStream(data));

PdfFileStamp stamp = new PdfFileStamp(new MemoryStream(data), new MemoryStream());

Please also note that when you use the PdfFileStamp constructor, make sure that the input and output both are the streams. You can't pass input as stream and output as file path.

I hope this helps. If you find any further questions, please do let us know.
Regards,

yes ur code shows me right way to use constructor i agree for tht…but atlast result must save to some output file path on disk na…so tht i can check whether my code works fine or not i mean water mark and conetnt is adding to output pdf or not…

yeah i tried the code in this way is it the right way to do ?can u pls check it out....

byte[] pdfBytes = File.ReadAllBytes(@"C:\input.PDF");

Stream output = new FileStream(@"C:\kit.PDF", FileMode.Create, FileAccess.Write);

// create PdfFileInfo object to get PDF file information

PdfFileInfo fileInfo = new PdfFileInfo(new MemoryStream(pdfBytes));

// create Stamp object

Stamp aStamp = new Stamp();

FormattedText formatted = new FormattedText("Print Preview", System.Drawing.Color.Blue, Aspose.Pdf.Kit.FontStyle.TimesBold, Aspose.Pdf.Kit.EncodingType.Winansi, false, 60);

aStamp.BindLogo(formatted);

aStamp.IsBackground = false;

aStamp.Rotation = 45;

aStamp.Opacity = 0.5F;

//specifies the position of stamp

aStamp.SetOrigin(fileInfo.GetPageWidth(1) / 3, fileInfo.GetPageHeight(1) / 2);

PdfFileStamp stamper = new PdfFileStamp(new MemoryStream(pdfBytes), output);

stamper.AddStamp(aStamp);

stamper.Close();

Hi Deepi,

Your code is correct. In fact, when we talk about stream, it means both MemoryStream and FileStream. So, if you want to save the file to disk while taking input from MemoryStream then you can use the FileStream as output parameter.

I hope this helps. If you find any further questions, please do let us know.
Regards,