Page number stamp not working

Hi ,


Please find the code to stamp page numbers.The code is throwing exception. Please help.

<span style=“font-size:7.0pt;mso-bidi-font-size:10.0pt;font-family:“Gisha”,“sans-serif”;
mso-bidi-font-family:Consolas;color:#7F0055”>import
java.io.FileInputStream;<span style=“font-size:7.0pt;mso-bidi-font-size:10.0pt;font-family:“Gisha”,“sans-serif”;
mso-bidi-font-family:Consolas”><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 TestPageNumberStamp {

/**

* @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);

final PageNumberStamp pageNumberStamp = new PageNumberStamp();

// whether the stamp is background

pageNumberStamp.setBackground(false);

pageNumberStamp.setFormat("Page # of " + 1);

pageNumberStamp.setBottomMargin(10);

pageNumberStamp

.setHorizontalAlignment(com.aspose.pdf.HorizontalAlignment.Center);

pageNumberStamp.setStartingNumber(1);

// set text properties

pageNumberStamp.getTextState().setFont(

com.aspose.pdf.FontRepository.findFont("Arial"));

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

pageNumberStamp.getTextState().setFontStyle(

com.aspose.pdf.FontStyles.Bold);

pageNumberStamp.getTextState().setFontStyle(

com.aspose.pdf.FontStyles.Italic);

pageNumberStamp.getTextState().setForegroundColor(java.awt.Color.BLUE);

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(pageNumberStamp);

}

doc.save("pageStamp.pdf");

}

}

Hi Basil,

We are sorry for the inconvenience caused. While testing the scenario with the latest version of Aspose.Pdf for Java 4.5.1, We have managed to reproduce the reported issue and logged it in our bug tracking system as PDFNEWJAVA-34043 for further investigation and resolution. We will notify you via this thread as soon as it is resolved.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Basil,

In addition to above reply, as a workaround you can use com.aspose.pdf.facades package to add page number stamp in existing PDF documents. Please check following documentation link for the purpose. However, we will keep you updated about the original issue resolution progress.

We are sorry for the inconvenience caused.

Best Regards,

Hi ,


I have used the same code already.But I cannot use this .

1) Font style com.aspose.pdf.facades.FontStyle has only limited fonts.
2) I want to loop through each pages and set page numbers.The page number format for last page will be different.I have to set page number manually .
If you have any other work around please let me know immediately.

Thanks
Basil
  1. Font style com.aspose.pdf.facades.FontStyle has only limited fonts.

Hi Basil,

In case you need to use TrueType font while adding logo, you may try specifying the complete path of TrueType font file as an argument to FormattedText object. Please take a look over following code line.

FormattedText text = new
FormattedText(“Sample
Text in Rage”, new FontColor(180, 0, 0),<o:p></o:p>

"c:/pdftest/RAGE.TTF",//path of the font,using the absolute path here

EncodingType.MacRoman,

false,

40f);
  1. I want to loop through each pages and set page numbers.The page number format for last page will be different.I have to set page number manually .

I am afraid currently PdfFileStamp object does not support the feature to add page number stamp on specific pages. However as a workaround, you may consider extracting the last page of PDF file, add page number stamp and then concatenate this page to original file. For further details, please visit

Hi,


Thanks for the response.I want to load the TTF file from my class path for formatted text.Can you please help me regrading this ?.I do not want to use absolute path.

Thanks
Basil C Paulose:
I want to load the TTF file from my class path for formatted text.Can you please help me regrading this ?.I do not want to use absolute path.
Hi Basil,

I am afraid I am unable to understand above stated requirement. Can you please share some details.

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


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