PDF Generating Tool Support Forum

HOME   Login   Register    Search

  Subject: HTML words not rendering issue
   PostPosted: 17 Aug 2021, 17:05 
Hi folks,
Below is my code
public byte[] convertHtmlToPDF (String htmlDocument){

      byte[] pdfBytes = null;
      ByteArrayOutputStream baos = null;
         PD4ML pd4ml = getPd4ML();
         pd4ml.useTTF("java:fonts", true);
         pd4ml.setDefaultTTFs("Times New Roman", "Arial", "Courier New");
         pd4ml.useTTF( "java:fonts", true );
         baos = new ByteArrayOutputStream();
         pd4ml.render(new StringReader(htmlDocument), baos);
         pdfBytes = baos.toByteArray();
         if (null != baos)
      return pdfBytes;

public PD4ML getPd4ML(){
         PD4ML oPd4ml = null;
         try {
            oPd4ml = new PD4ML();
            oPd4ml.useTTF("java:fonts", true);
            oPd4ml.setDefaultTTFs("Times New Roman", "Arial", "Courier New");


            oPd4ml.setPageInsetsMM(new Insets(getTopValue(), getLeftValue(),getBottomValue(), getRightValue()));

         } catch (Exception e) {
         return oPd4ml;

The issue is, when I generate PDF from above code, it resolves issue of right side text cropping from some PDF.

But at the same time, it starts cropping right side text in other PDFs.

When I comment line: oPd4ml.adjustHtmlWidth(); , it reverses the issue. Below is the example
Before code comment

Now,I comment line: oPd4ml.adjustHtmlWidth(); and generate both PDF again. And see the result, issue is replaced in PDF


How is it possible?

File comment: After the line is commented, first PDF is now okay, but other one is causing issue
6.png [ 216.69 KiB | Viewed 343 times ]
File comment: In this, first PDF has crop issue, while other is good.
5.png [ 197.79 KiB | Viewed 344 times ]

[Reply]     [ 1 post ] 

Copyright ©2004-10 zefer|org. All rights reserved. Bookmark and Share