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
Code:
public byte[] convertHtmlToPDF (String htmlDocument){

      byte[] pdfBytes = null;
      ByteArrayOutputStream baos = null;
      try{
         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();
   
      }finally{
         if (null != baos)
            IOUtils.closeQuietly(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");

            if(logger.isDebugEnabled())
               oPd4ml.enableDebugInfo();
            oPd4ml.adjustHtmlWidth();
            oPd4ml.protectPhysicalUnitDimensions();

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

         } catch (Exception e) {
            logger.error(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
[img]
Attachment:
5.png
[/img]

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

[img]
Attachment:
6.png
[/img]


How is it possible?


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

[Reply]     [ 1 post ] 

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