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,
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,
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
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
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,
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
//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");
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,
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,
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