Align the text to left

HI,

We are using addpageNumber and would like to display the text to the bottom left. Can you please let me know if this is possible. We tried various coordinates and the text is always alligned center.

The mehod we are using is

public void addPageNumber(java.lang.StringformatString,
                          intposition,
                          floatleftMargin,
                          floatrightMargin,
                          floattopMargin,
                          floatbottomMargin)

Thanks In Advance

B

Hi Mayur,


Thanks for contacting support.

I have tested the scenario and have observed that Position parameter of addPageNumber(…) method does not support the value to set page number stamp on Bottom-Left position. For the sake of implementation, I have
logged this requirement in our issue tracking system under New Features list as
PDFNEWJAVA-33617. We will further investigate this requirement in details
and will keep you updated on the status of a correction.

However as a workaround, you may specify 0 as position parameter and set left margin value to negative so that page stamp is displayed on Bottom-Left. Please take a look over following code snippet. For your reference, I have also attached the resultant PDF generated over my end.

We are sorry for this inconvenience.

[Java]

String inFile = “c:/pdftest/DemoWord.pdf”;<o:p></o:p>

String outFile = "c:/pdftest/DemoWord_PageNumber.pdf";

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

//add page number

fileStamp.addPageNumber(new com.aspose.pdf.facades.FormattedText("Page # .",

new Color(0, 0, 100), com.aspose.pdf.facades.FontStyle.CourierBold, com.aspose.pdf.facades.EncodingType.Winansi, false, 10), 0, -550, 0, 0, 0);

fileStamp.close();

Hi,

With the coordinates provided it is alligning text to the complete left and if the text is too long, the starting characters are trimmed off. We need to position the text in allignment with the left margin of the pdf and should be able to control the position of the text in the botton left area of the page.

The left margin of the text should be fixed and with the coordinates provided, I think the right margin is fixed and when new data is added it is moving left

The text is displayed at bottom left even with the followig coordinates but the same trimming issue

fileStamp.addPageNumber(new FormattedText(stripText, new Color(0,10,100),
FontStyle.CourierBold, EncodingType.Winansi, false, 10), 0, 0, 0, 0, 0)

~B

Hi Mayur,


In order to display stamp on Bottom-Left position, I would suggest you to please try using PageNumberStamp class of Aspose.Pdf namespace. Please try using the following code snippet. For further information, please visit Add Page Number Stamp in a PDF File

[C#]

//open document<o:p></o:p>

Document pdfDocument = new Document("c:/pdftest/DemoWord.pdf");

//create page number stamp

PageNumberStamp pageNumberStamp = new PageNumberStamp();

//whether the stamp is background

pageNumberStamp.Background = false;

pageNumberStamp.Format = "Page # of " + pdfDocument.Pages.Count;

pageNumberStamp.BottomMargin = 10;

// set horizontal alignment for stamp object

pageNumberStamp.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Left;

// set vertical alignment for stamp object

pageNumberStamp.VerticalAlignment= Aspose.Pdf.VerticalAlignment.Bottom;

pageNumberStamp.StartingNumber = 1;

//set text properties

pageNumberStamp.TextState.Font = FontRepository.FindFont("Arial");

pageNumberStamp.TextState.FontSize = 14.0F;

//add stamp to particular page

pdfDocument.Pages[1].AddStamp(pageNumberStamp);

//save output document

pdfDocument.Save(“c:/pdftest/Bottom_Left_AlignedStamp.pdf”);

Hi Nayyer,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

We need to implement the mentioned feature in Java and I do not see PageNumberStamp in the java api reference. Please let me know if there is a way we can achieve this is Java using PdfFileStamp or any other class.

For your reference I'm mentioning the requirement once again. We should be able to add a dynamic text at the bottom of the page and it should be in alignment with the left margin of the page and the left margin position should be fixed.

~B

Hi Mayur,


First of all please accept my apologies as I shared the information related to Aspose.Pdf for .NET. Please try using the following code snippet for Aspose.Pdf for Java. Ensure that you are using latest release of Aspose.Pdf for Java 4.1.2.

[Java]

//open document<o:p></o:p>

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("input.pdf");

//create page number stamp

com.aspose.pdf.PageNumberStamp pageNumberStamp = new com.aspose.pdf.PageNumberStamp();

//whether the stamp is background

pageNumberStamp.setBackground(false);

pageNumberStamp.setFormat("Page # of " + pdfDocument.getPages().size());

pageNumberStamp.setBottomMargin(10);

// set horizontal alignment for stamp object

pageNumberStamp.setHorizontalAlignment(com.aspose.pdf.HorizontalAlignment.Left);

// set vertical alignment for stamp object

pageNumberStamp.setVerticalAlignment(com.aspose.pdf.VerticalAlignment.Bottom);

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

//add stamp to particular page

pdfDocument.getPages().get_Item(1).addStamp(pageNumberStamp);

//save output document

pdfDocument.save(“PageNumberStamp_output.pdf”);

Hi Mayur,


Thanks for your patience. In reference to above reported issue (PDFNEWJAVA-33617), please note we have already implemented additional positions in Aspose.Pdf for java as following. Moreover, you can also use the predefined constants:


5 - bottom left,
6 - sides left,
7 - upper left.


PdfFileStamp.POS_BOTTOM_MIDDLE
PdfFileStamp.POS_BOTTOM_RIGHT
PdfFileStamp.POS_UPPER_RIGHT
PdfFileStamp.POS_SIDES_RIGHT
PdfFileStamp.POS_UPPER_MIDDLE
PdfFileStamp.POS_BOTTOM_LEFT
PdfFileStamp.POS_SIDES_LEFT
PdfFileStamp.POS_UPPER_LEFT


Please download and try latest version of Aspose.Pdf for Java, it will help you to accomplish the task.

Please feel free to contact us for any further assistance.

Best Regards,