use of com.itextpdf.html2pdf.css.media.MediaDeviceDescription in project commons by mosip.
the class PDFGeneratorImpl method generate.
/*
* (non-Javadoc)
*
* @see io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#generate(java.io.
* InputStream, java.lang.String)
*/
@Override
public OutputStream generate(InputStream is, String resourceLoc) throws IOException {
isValidInputStream(is);
OutputStream os = new ByteArrayOutputStream();
PdfWriter pdfWriter = new PdfWriter(os);
PdfDocument pdfDoc = new PdfDocument(pdfWriter);
ConverterProperties converterProperties = new ConverterProperties();
pdfDoc.setTagged();
PageSize pageSize = PageSize.A4.rotate();
pdfDoc.setDefaultPageSize(pageSize);
float screenWidth = CssUtils.parseAbsoluteLength("" + pageSize.getWidth());
MediaDeviceDescription mediaDescription = new MediaDeviceDescription(MediaType.SCREEN);
mediaDescription.setWidth(screenWidth);
DefaultFontProvider dfp = new DefaultFontProvider(true, true, false);
converterProperties.setMediaDeviceDescription(mediaDescription);
converterProperties.setFontProvider(dfp);
converterProperties.setBaseUri(resourceLoc);
converterProperties.setCreateAcroForm(true);
try {
HtmlConverter.convertToPdf(is, pdfDoc, converterProperties);
} catch (Exception e) {
throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), e.getMessage());
}
return os;
}
Aggregations