Search in sources :

Example 1 with MediaDeviceDescription

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;
}
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)

Aggregations

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