Hi ,
public ByteArrayInputStream convertToPdf(InputStream docInputStream) throws PDFConversionException {
// Save the document in PDF format.
ByteArrayOutputStream dstStream = null;
try {
final Document doc = new Document(docInputStream);
dstStream = new ByteArrayOutputStream();
doc.save(dstStream, SaveFormat.PDF);
}
catch (Exception e) {
s_Logger.error(" Error : "+e.getMessage()+" occured while processing file for pdf conversion");
throw new PDFConversionException("Invalid document model for processing");
}
final ByteArrayInputStream srcStream = new ByteArrayInputStream(dstStream.toByteArray());
return srcStream;
}
// open document
final com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(docInputStream);
// create formatted text stamp
final FormattedText headerText = new FormattedText(getPageHeader(pdfDocInfo));
final TextStamp headerStamp = getHeaderStyle(headerText);
final FormattedText footerText = new FormattedText(getPageFooter(pdfDocInfo));
final TextStamp footerStamp = getFooterStyle(footerText);
// iterate through all pages of PDF file
for (int Page_counter =1; Page_counter<=pdfDocument.getPages().size(); Page_counter++) {
//add stamp to all pages of PDF file
pdfDocument.getPages().get_Item(Page_counter).addStamp(headerStamp); This is the line throwing an Exception.
pdfDocument.getPages().get_Item(Page_counter).addStamp(footerStamp);
pdfDocument.getPages().get_Item(Page_counter).addStamp(
getPageNo(Page_counter, pdfDocument.getPages().size()));
}
// Getting the input stream of modified PDF document
final ByteArrayOutputStream dstStream = new ByteArrayOutputStream();
pdfDocument.save(dstStream, com.aspose.pdf.SaveFormat.Pdf);
final ByteArrayInputStream srcStream = new ByteArrayInputStream(dstStream.toByteArray());
return srcStream;
private String getPageHeader(final DocumentModel pdfDocInfo) {
final String sPatientFristName = pdfDocInfo.getPatientFirstName();
final String sPatientLastName = pdfDocInfo.getPatientLastName();
final String sPatientMiddleName = pdfDocInfo.getPatientMiddleName();
final StringBuilder sb = new StringBuilder();
sb.append(sPatientLastName +", "+ sPatientFristName +" " +sPatientMiddleName.substring(0, 1).toUpperCase());
sb.append(" DOB:" +pdfDocInfo.getDateOfBirth());
sb.append(" GENDER: "+pdfDocInfo.getGender());
sb.append(" EMPI: "+pdfDocInfo.getEMPI());
return sb.toString();
}
And
private TextStamp getHeaderStyle(final FormattedText headerText) {
final TextStamp headerStamp = new TextStamp(headerText);
//set properties of the stamp
headerStamp.setTopMargin(10);
headerStamp.setLeftMargin(10.0);
headerStamp.setHorizontalAlignment(com.aspose.pdf.HorizontalAlignment.Left);
headerStamp.setVerticalAlignment(com.aspose.pdf.VerticalAlignment.Top);
//set text properties
headerStamp.getTextState().setFontSize(11.0F);
headerStamp.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);
return headerStamp;
}
multipartEntity.addPart("Gender", new StringBody(request.getGender(), charSet));
multipartEntity.addPart("empi", new StringBody(request.getEMPI(), charSet));