Here is a snippet I garnered from our code, not sure that everything is in here that should be for compilation, but I think it is a good framework of where we are seeing the problem
public class BuyerInvoicePDFCreate {
public static final int DEFAULT_TXT_CHARS = 20;
public void createInvoicePDF( Connection connection) throws IOException, SQLException{
Document doc = new Document();
doc.setFitWindow(true);
doc.setCenterWindow(true);
double zoom = 1;
com.aspose.pdf.GoToAction action = new com.aspose.pdf.GoToAction(1);
action.setDestination(new com.aspose.pdf.XYZExplicitDestination(doc, 0, 0, 0, zoom));
doc.setOpenAction(action);
Page page = doc.getPages().add();
PageInfo info = page.getPageInfo();
info.setMargin(getPageMargin());
page.setPageInfo(info);
page.getParagraphs().add(createInvoiceBox(vendorId));
// where output is a buffered output stream
doc.save(output);
}
private FloatingBox createInvoiceBox(String vendorId){
FloatingBox invoiceBox = new FloatingBox(580,10);
invoiceBox.setLeft(0);
invoiceBox.setTop(0);
invoiceBox.setVerticalAlignment(VerticalAlignment.Center);
invoiceBox.setHorizontalAlignment(HorizontalAlignment.Center);
Table table = new Table();
table.setColumnWidths(“120 338 120”);
Row row = table.getRows().add();
Cell invoiceNumber = row.getCells().add();
invoiceNumber.setMargin(getTxtMargin());
// if this is set to something greater than the default of 20 characters then the doc.save() will hang
TextFragment invoiceId = getTextFragment(invoice.getInvoiceNumber());
invoiceId.setHorizontalAlignment(HorizontalAlignment.Left);
invoiceNumber.getParagraphs().add(invoiceId);
Cell invoiceCell = row.getCells().add();
TextFragment InvoiceTag = getTextFragment(50,fieldMaster.getDisplayText(BuyerInvoice_ConfigureMainDocuments_Fields.INVOICE_NAME));
InvoiceTag.setHorizontalAlignment(HorizontalAlignment.Center);
invoiceCell.getParagraphs().add(InvoiceTag);
Cell pageNumber = row.getCells().add();
TextFragment page = getTextFragment(“Page 1”);
page.setHorizontalAlignment(HorizontalAlignment.Right);
pageNumber.getParagraphs().add(page);
invoiceBox.getParagraphs().add(table);
invoiceBox.setBorder( new BorderInfo(15));
return invoiceBox;
}
public static TextFragment getTextFragment(int size, String text){
text = “012345678901234567890123456789012345678901234567890”;
String s = text.substring(0, Math.min(text.length(),size));
return new TextFragment(s);
}
public static TextFragment getTextFragment( String text){
text = “012345678901234567890123456789012345678901234567890”;
String s = text.substring(0, Math.min(text.length(),DEFAULT_TXT_CHARS));
return new TextFragment(s);
}
private MarginInfo getPageMargin(){
MarginInfo pageMarginInfo = new MarginInfo();
pageMarginInfo.setLeft(5);
pageMarginInfo.setRight(5);
pageMarginInfo.setTop(5);
pageMarginInfo.setBottom(5);
return pageMarginInfo;
}
private MarginInfo getTxtMargin(){
MarginInfo txtMarginInfo = new MarginInfo();
txtMarginInfo.setTop(0);
txtMarginInfo.setLeft(5);
txtMarginInfo.setRight(0);
txtMarginInfo.setBottom(0);
return txtMarginInfo;
}
}