Search in sources :

Example 1 with DefaultFontProvider

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;
}
Also used : ConverterProperties(com.itextpdf.html2pdf.ConverterProperties) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PageSize(com.itextpdf.kernel.geom.PageSize) DefaultFontProvider(com.itextpdf.html2pdf.resolver.font.DefaultFontProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MediaDeviceDescription(com.itextpdf.html2pdf.css.media.MediaDeviceDescription) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) GeneralSecurityException(java.security.GeneralSecurityException) PDFGeneratorException(io.mosip.kernel.core.pdfgenerator.exception.PDFGeneratorException) IOException(java.io.IOException) DocumentException(com.itextpdf.text.DocumentException) PDFGeneratorException(io.mosip.kernel.core.pdfgenerator.exception.PDFGeneratorException)

Example 2 with DefaultFontProvider

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;
}
Also used : ConverterProperties(com.itextpdf.html2pdf.ConverterProperties) DefaultFontProvider(com.itextpdf.html2pdf.resolver.font.DefaultFontProvider) IOException(java.io.IOException) DefaultFontProvider(com.itextpdf.html2pdf.resolver.font.DefaultFontProvider) FontProvider(com.itextpdf.layout.font.FontProvider) FontProgram(com.itextpdf.io.font.FontProgram)

Aggregations

ConverterProperties (com.itextpdf.html2pdf.ConverterProperties)2 DefaultFontProvider (com.itextpdf.html2pdf.resolver.font.DefaultFontProvider)2 IOException (java.io.IOException)2 MediaDeviceDescription (com.itextpdf.html2pdf.css.media.MediaDeviceDescription)1 FontProgram (com.itextpdf.io.font.FontProgram)1 PageSize (com.itextpdf.kernel.geom.PageSize)1 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)1 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)1 FontProvider (com.itextpdf.layout.font.FontProvider)1 DocumentException (com.itextpdf.text.DocumentException)1 PDFGeneratorException (io.mosip.kernel.core.pdfgenerator.exception.PDFGeneratorException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 GeneralSecurityException (java.security.GeneralSecurityException)1