use of com.itextpdf.html2pdf.resolver.font.DefaultFontProvider 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;
}
use of com.itextpdf.html2pdf.resolver.font.DefaultFontProvider in project Rolls-Royce by EntryDSM.
the class ConverterPropertiesCreator method createConverterProperties.
public ConverterProperties createConverterProperties() {
ConverterProperties properties = new ConverterProperties();
FontProvider fontProvider = new DefaultFontProvider(false, false, false);
fonts.forEach(font -> {
try {
FontProgram fontProgram = FontProgramFactory.createFont(fontPath + font);
fontProvider.addFont(fontProgram);
} catch (IOException e) {
e.printStackTrace();
}
});
properties.setFontProvider(fontProvider);
return properties;
}
Aggregations