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

Free Support Forum - aspose.com

Text Stamp not working

Hi ,

Please find the code to add a text stamp to a document.Code is throwing exception.Please help.

import java.io.FileInputStream;<o:p></o:p>

import java.io.FileNotFoundException;

import com.aspose.pdf.Document;

import com.aspose.pdf.License;

import com.aspose.pdf.MarginInfo;

import com.aspose.pdf.Page;

import com.aspose.pdf.PageCollection;

import com.aspose.pdf.PageInfo;

import com.aspose.pdf.PageNumberStamp;

public class TestTextStamp {

/**

* @param args

* @throws FileNotFoundException

*/

public static void main(String[] args) throws FileNotFoundException {

java.util.Locale locale1 = new java.util.Locale("en");

java.util.Locale.setDefault(locale1);

License lic = new License();

lic.setLicense(new FileInputStream(

"D:\\Workspaces\\Examples\\Aspose\\src\\conf\\Aspose.Total.Java.lic"));

// Added document

Document doc = new com.aspose.pdf.Document();

PageInfo pageInfo = doc.getPageInfo();

MarginInfo marginInfo = pageInfo.getMargin();

marginInfo.setLeft(37);

marginInfo.setRight(37);

marginInfo.setTop(37);

marginInfo.setBottom(37);

pageInfo.isLandscape(true);

com.aspose.pdf.Table table = new com.aspose.pdf.Table();

table.setColumnWidths("50 100");

// added page.

Page curPage = doc.getPages().add();

for (int i = 1; i <= 3; i++) {

com.aspose.pdf.Row row = table.getRows().add();

com.aspose.pdf.Cell cell1 = row.getCells().add();

cell1.getParagraphs().add(

new com.aspose.pdf.TextFragment("Content 1"));

com.aspose.pdf.Cell cell2 = row.getCells().add();

cell2.getParagraphs().add(

new com.aspose.pdf.TextFragment("Content 2"));

}

curPage.getParagraphs().add(table);

com.aspose.pdf.TextStamp textStamp = new com.aspose.pdf.TextStamp("sample stamp");

// set whether stamp is background

textStamp.setBackground(true);

// set origin

textStamp.setXIndent(100);

textStamp.setYIndent(100);

// rotate stamp

textStamp.setRotate(com.aspose.pdf.Rotation.on90);

// set text properties

textStamp.getTextState().setFont(new com.aspose.pdf.FontRepository().findFont("Arial"));

textStamp.getTextState().setFontSize(14.0F);

textStamp.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);

textStamp.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Italic);

textStamp.getTextState().setForegroundColor(java.awt.Color.GREEN);

final PageCollection pages = doc.getPages();

final int pageSize = pages.size();

for (int i = 1; i <= pageSize; i++) {

final Page page = pages.get_Item(i);

page.addStamp(textStamp);

}

doc.save("pageStamp.pdf");

}

}

Hi Basil,


Thanks for contacting support.

I have tested the scenario and I am able to
notice the same problem. For the sake of correction, I have logged this problem
as PDFNEWJAVA-34049 in our issue tracking system. We will further
look into the details of this problem and will keep you updated on the status
of correction. Please be patient and spare us little time. We are sorry for
this inconvenience.

The issues you have found earlier (filed as PDFNEWJAVA-34049) have been fixed in Aspose.Pdf for Java 9.7.1.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.