:before :after pseudo elements CSS not getting rendered in my PDF

125 views Asked by At

Below are my dependencies that I am using to convert thymeleaf template to PDF.

<dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>kernel</artifactId>
            <version>7.1.15</version>
        </dependency>
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>html2pdf</artifactId>
        <version>3.0.4</version>
        </dependency>

here is my html to pdf conversion code :

public ByteArrayInputStream htmlToPdf(String processedHtml, LoggerDto loggerDto, DBLogger logger){
        
            loggerDto.setMessage("Inside htmlToPdf of DocumentGeneratorUtil" );
            logger.printLog(DbEnum.INFO,loggerDto);
        
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            
            try {
        
                PdfDocument pdfDoc = new PdfDocument(new PdfWriter(byteArrayOutputStream));
                pdfDoc.setDefaultPageSize(PageSize.A4);
                
                DefaultFontProvider defaultFont = new DefaultFontProvider(false, true, false);
                
                ConverterProperties converterProperties = new ConverterProperties();
                converterProperties.setFontProvider(defaultFont);
                converterProperties.setBaseUri(ServiceUtility.getCurrentBaseUrl());
                
                HtmlConverter.convertToPdf(processedHtml, pdfDoc, converterProperties);
                
                FileOutputStream fout = new FileOutputStream("/home/vaibhav/Desktop/CreatePDF/sample.pdf");
                byteArrayOutputStream.writeTo(fout);
                
                ByteArrayInputStream pdfStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
                byteArrayOutputStream.close();
                byteArrayOutputStream.flush();
                loggerDto.setMessage("PDF stream created" );
                logger.printLog(DbEnum.INFO,loggerDto);
                
                return pdfStream;

}

I want to render lines for tree structure in my pdf for which i am using below CSS :

.tree-sec {
    position: relative;
}

.tree-sec:before {
    content: '';
    position: absolute;
    top: 12px;
    left: 32px;
    width: 1px;
    height: 99%;
    background-color: #dfe2eb;
}

.tree-sec:after {
    content: '';
    width: 2px;
    height: 8px;
    background: #ffffff;
    position: absolute;
    top: -2px;
    left: 0;
}

But it not able to understand :before :after pseudo elements.

I tried to use the latest versions of Kernel and html2pdf but I am getting errors in my html to PDF conversion utility methods like it is unable to identify DefaultFontProvider, ConverterProperties.

Please suggest solution for this

0

There are 0 answers