Free Support Forum - aspose.com

Image and Text alignment to display signatures

Hi,

I am trying to place the Image(signature) and my name, designation and company name as shown in the attached image(expected_align_img_text.png), using aspose pdf.

I need to write this data in a PDF generated at particular position.

Currently I am able to write this as a different way, but want to fit image and text aligned properly.
It should be auto aligned like a table data where we aligned text in center aligned for a cell.

For reference I have attached screenshot(generated_PDF.png) of the same, which I tried using the aspose pdf.

I have followed the below link to align the text in center, but not able to add the image in the same way.
http://www.aspose.com/docs/display/pdfjava/Define+alignment+for+TextStamp+object

Please let me know or pointers as how can I achieve this using aspose.pdf package for java.

Thanks,
Shivaji

Hi Shivaji,


Thanks for contacting support.

In order to accomplish your requirement, you may consider placing Image and Text objects inside table cell. However I have observed that Image is always appearing as Left Aligned inside table cell. This problem related to image alignment is already logged in our issue tracking system as PDFNEWJAVA-35034. We will further look into the details of this issue and will keep you posted with our findings.

We are sorry for this inconvenience.

For your reference, I have also attached the output PDF generated with following code snippet.

[Java]

com.aspose.pdf.Document doc = new com.aspose.pdf.Document();<o:p></o:p>

com.aspose.pdf.Page page = doc.getPages().add();<o:p></o:p>

com.aspose.pdf.Table table = new com.aspose.pdf.Table();<o:p></o:p>

table.setColumnWidths(“300”);<o:p></o:p>

page.getParagraphs().add(table);<o:p></o:p>

table.setBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, com.aspose.pdf.Color.getHotPink()));<o:p></o:p>

table.setDefaultCellBorder( newcom.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, com.aspose.pdf.Color.getIndigo()));<o:p></o:p>

com.aspose.pdf.Row r1 = table.getRows().add();<o:p></o:p>

com.aspose.pdf.Cell c1 = r1.getCells().add();<o:p></o:p>

c1.getDefaultCellTextState().setHorizontalAlignment(com.aspose.pdf.HorizontalAlignment.Center);<o:p></o:p>

com.aspose.pdf.Image image = new com.aspose.pdf.Image();<o:p></o:p>

image.setFile(“c:/pdftest/logoSpin.png”);<o:p></o:p>

image.setHorizontalAlignment(com.aspose.pdf.HorizontalAlignment.Center);<o:p></o:p>

c1.getParagraphs().add(image);

com.aspose.pdf.TextFragment name_fragment = new com.aspose.pdf.TextFragment(“My name is Here after signature”);<o:p></o:p>

//name_fragment.IsInLineParagraph = true;<o:p></o:p>

com.aspose.pdf.TextFragment desig_fragment = new com.aspose.pdf.TextFragment(“here is my designation comes into pricture”);<o:p></o:p>

com.aspose.pdf.TextFragment company_name = new com.aspose.pdf.TextFragment(“My company name is here”);<o:p></o:p>

c1.getParagraphs().add(name_fragment);<o:p></o:p>

c1.getParagraphs().add(desig_fragment);<o:p></o:p>

c1.getParagraphs().add(company_name);<o:p></o:p>

doc.save(“c:/pdftest/ImageAlignment_Test.pdf”);

Thank you for looking in this issue.

I am trying the piece of the code which provided, will revert you if we get any issues further.

Also please update me once the issue with image alignment is fixed.

Thanks,
Shivaji

Hi Shivaji,


As soon as we have some definite updates regarding the earlier reported issue, we will surely updated you within this forum thread. Your patience and comprehension is greatly appreciated in this regard.

Hi Nayyer,

I have tried the given code to align the image and text for signature format, it works as mentioned.

Is there any workaround for the image alignment to center by using the inner table in that cell with merge cells applied.

Or can we add some empty spaces left side of the image to look like a center aligned.

Please find the attached screens for the format I am trying to explain.

Thanks,
Shivaji

Hi,

I am trying to use the below mentioned code snippet, I found that there is one method(addNestedTable) not found on Cell object.
http://www.aspose.com/docs/display/pdfjava/Create+Nested+Table

//Add the nested table into the paragraphs collection of the 2nd cell
cell2.addNestedTable(tab2);
Please let me know if I miss anything importing.

Thanks,
Shivaji
Hi Shivaji,

shivaji_dole:
Hi Nayyer,

I have tried the given code to align the image and text for signature format, it works as mentioned.

Is there any workaround for the image alignment to center by using the inner table in that cell with merge cells applied.

Or can we add some empty spaces left side of the image to look like a center aligned.

Please find the attached screens for the format I am trying to explain.

Thanks,
Shivaji

Please use following code snippet to set cell alignment. You need to use setAlignment() method for the purpose. Hopefully it will help you to accomplish the task.

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

com.aspose.pdf.Page page = doc.getPages().add();

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

table.setColumnWidths("300");

page.getParagraphs().add(table);

table.setBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, com.aspose.pdf.Color.getHotPink()));

table.setDefaultCellBorder( new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, com.aspose.pdf.Color.getIndigo()));

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

com.aspose.pdf.Cell c1 = r1.getCells().add();

com.aspose.pdf.Image image = new com.aspose.pdf.Image();

image.setFile(myDir + "aspose-Pdf-for-net.png");

com.aspose.pdf.TextFragment name_fragment = new com.aspose.pdf.TextFragment("My name is Here after signature");

c1.setAlignment(com.aspose.pdf.HorizontalAlignment.Center);

c1.getParagraphs().add(image);

com.aspose.pdf.TextFragment desig_fragment = new com.aspose.pdf.TextFragment("here is my designation comes into pricture");

com.aspose.pdf.TextFragment company_name = new com.aspose.pdf.TextFragment("My company name is here");

c1.getParagraphs().add(name_fragment);

c1.getParagraphs().add(desig_fragment);

c1.getParagraphs().add(company_name);

doc.save(myDir + "ImageAlignment_Test141.pdf");


Please feel free to contact us for any further assistance.


Best Regards,

Hi Shivaji,

Thanks for your inquiry.

shivaji_dole:
Hi,

I am trying to use the below mentioned code snippet, I found that there is one method(addNestedTable) not found on Cell object.
http://www.aspose.com/docs/display/pdfjava/Create+Nested+Table

//Add the nested table into the paragraphs collection of the 2nd cell
cell2.addNestedTable(tab2);
Please let me know if I miss anything importing.

Thanks,
Shivaji

You need to add nested table in paragraph collection of targeted cell as following. Hopefully it will help you to accomplish you task.

//Instantiate Pdf document object

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

//Create a section in the Pdf

com.aspose.pdf.Page page = pdf.getPages().add();

//Create a table

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

//Add the table into the paragraphs collection of section

page.getParagraphs().add(tab1);

//Set the column widths of the table

tab1.setColumnWidths("100 200");

//Set the default cell border using BorderInfo instance

tab1.setDefaultCellBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All));

//Add a row into the table

com.aspose.pdf.Row row1 = tab1.getRows().add();

//Add 1st cell in the row

row1.getCells().add("left cell");

//Add 2nd cell in the row

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

//Create a table to be nested with the reference of 2nd cell in the row

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

//Set the default cell border using BorderInfo instance

tab2.setDefaultCellBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All));

//Add the nested table into the paragraphs collection of the 2nd cell

cell2.getParagraphs().add(tab2);

//Set the column widths of the nested table

tab2.setColumnWidths("100 100");

//Create 1st row in the nested table

com.aspose.pdf.Row row21 = tab2.getRows().add();

//Create 1st cell in the 1st row of the nested table

com.aspose.pdf.Cell cell21 = row21.getCells().add("top cell");

//Set the column span of the 1st cell (in the 1st row of the nested table) to 2

cell21.setColSpan(2);

//Create 2nd row in the nested table

com.aspose.pdf.Row row22 = tab2.getRows().add();

//Create 1st cell in the 2nd row of the nested table

row22.getCells().add("left bottom cell");

//Create 2nd cell in the 2nd row of the nested table

row22.getCells().add("right bottom cell");

//Save the Pdf

pdf.save(myDir+"nestedtable.pdf");


Please feel free to contact us for any further assistance.

Best Regards,

Hi,

I am able to manage with the above mentioned code snippet.

I will update if any issues I face.

Thank you!

-Shivaji

Hi Shivaji,


Thanks for your feedback. It is good to know that suggested code worked for you.

Please keep using our API and feel free to contact us for any further question or concern, we will more than happy to extend our support.

Best Regards,

Thank you!

I have one more question regarding the same.
How can we write a table at particular position? I want to write the same signatures at the end of the pdf after generated.

I will be having the Document object and want to write the table at the end of the last page. I know the x,y co-oridnates where to write the table content.

Please suggest me, if any workarounds available.

Thanks,
Shivaji


Hi Shivaji,


Thanks for your inquiry. You may set table Top and Left property to control the table position and add table to you desired page. Please note in case of Top value, bottom of the page is 0 and Top corner of page is Page height. Please check following code sample, hopefully it will help you to accomplish the task.

com.aspose.pdf.Document doc = new
com.aspose.pdf.Document(myDir+“Input.pdf”);<o:p></o:p>

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

table.setTop(600);

table.setLeft(100);

table.setColumnWidths("300");

doc.getPages().get_Item(2).getParagraphs().add(table);

table.setBorder(new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, com.aspose.pdf.Color.getHotPink()));

table.setDefaultCellBorder( new com.aspose.pdf.BorderInfo(com.aspose.pdf.BorderSide.All, com.aspose.pdf.Color.getIndigo()));

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

com.aspose.pdf.Cell c1 = r1.getCells().add();

com.aspose.pdf.Image image = new com.aspose.pdf.Image();

image.setFile(myDir + "aspose-Pdf-for-net.png");

com.aspose.pdf.TextFragment name_fragment = new com.aspose.pdf.TextFragment("My name is Here after signature");

c1.setAlignment(com.aspose.pdf.HorizontalAlignment.Center);

c1.getParagraphs().add(image);

com.aspose.pdf.TextFragment desig_fragment = new com.aspose.pdf.TextFragment("here is my designation comes into pricture");

com.aspose.pdf.TextFragment company_name = new com.aspose.pdf.TextFragment("My company name is here");

c1.getParagraphs().add(name_fragment);

c1.getParagraphs().add(desig_fragment);

c1.getParagraphs().add(company_name);

doc.save(myDir + "ImageAlignment_Test141.pdf");


Please feel free to contact us for any further assistance.


Best Regards,

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan