Text Stamp

Hi,


I want to add text stamp to a pdf page. But, I could not add a textstamp.
The function is below:

public void addWaterMark(Page page, String text) {
TextStamp ts = new TextStamp( text );
ts.setBackground(true);
ts.setLeftMargin(10);
ts.setXIndent( 100 );
ts.setYIndent( 150 );
ts.setRotateAngle(45);
ts.getTextState().setFontStyle(FontStyle.Bold);
ts.getTextState().setFontStyle(FontStyle.Italic);
ts.getTextState().setFontSize(18);
ts.getTextState().setForegroundColor(Color.GREEN);

page.addStamp(ts);
}

In this function, I will get following error:

Process: com.mycompany.pdftest, PID: 9024
java.lang.NullPointerException
at com.aspose.pdf.TextStamp.getRect(Unknown Source)
at com.aspose.pdf.TextStamp.put(Unknown Source)
at com.aspose.pdf.Page.addStamp(Unknown Source)
at com.mycompany.pdftest.PDFTester.addWaterMark(PDFTester.java:112)
at com.mycompany.pdftest.MainActivity.createEmptyPdf(MainActivity.java:123)
at com.mycompany.pdftest.MainActivity$1.onClick(MainActivity.java:46)
at android.view.View.performClick(View.java:4640)
at android.view.View$PerformClick.run(View.java:19421)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5476)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)

What is wrong in my code? In android , is there any problem with stamps?
Thanks for help.



Hi Ozan,


Thanks for your inquiry. I have tested the scenario with a sample PDF document and noticed the NullPointer Exception, so logged a ticket PDFANDROID-436 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.

We are sorry for the inconvenience caused.

Best Regards,

Hi,


Thank you for reply.

I want to use textstamp for watermark purpose, but it failed.


How can I add a waterwark to a pdf document? Does library have another support for this operation?

Hi Ozan,


Thanks for your inquiry. You may use com.aspose.pdf.facades package to add text watermark to PDF document as following. Hopefully it will help you to accomplish the task. However we will keep you updated about the original issue resolution progress.

//open document

com.aspose.pdf.facades.PdfFileStamp fileStamp = new com.aspose.pdf.facades.PdfFileStamp();

fileStamp.bindPdf(inputPath);



//create stamp

com.aspose.pdf.facades.Stamp stamp = new com.aspose.pdf.facades.Stamp();

stamp.bindLogo(new FormattedText(“Hello World!”));

stamp.setOrigin(200, 200);

stamp.setRotation(90.0F);

stamp.isBackground(true);



//add stamp to PDF file

fileStamp.addStamp(stamp);



//save updated PDF file<o:p></o:p>
fileStamp.save(outputPath);

fileStamp.close();<o:p></o:p>

Please feel free to contact us for any further assistance.


Best Regards,