OpenOffice HTML & CSS : JODConverter

2019-08-24 13:43发布

问题:

I'm using JODConverter in my application to convert a HTML file with basic CSS 2 to a PDF file.

When I convert the file, the pdf is just a mess, And when I tried to view in openOffice directly it was a mess also.

This is the file generated :

and this is what I have in my chrome browser :

As you see there's a big difference.

This is my code :

<div style="padding : 5% 25% 0% 10%; diplay : inline-block; ">
  <div>
    <span style="color : green; float : left; "><b>MyCompany - MyConsultant</b></span>
    <hr style="width : 100%; border-top: dotted 1px; " />
  </div>
  <div>
    <div>
      <div style="float : left;">Number of days</div>
      <div style="float : right ">20,5</div>
      <hr style="width : 100%; border-top: dotted 1px; " />
    </div>
    <div>
      <div style="float : left ">Your number</div>
      <div style="float : right ">520,00€</div>
      <hr style="width : 100%; border-top: dotted 1px; " />
    </div>
    <div>
      <div style="float : left ">Total HT</div>
      <div style="float : right ">10 660,00€</div>
      <hr style="width : 100%; border-top: dotted 1px; " />
    </div>
    <div>
      <div style="float : left ">TVA [20%]</div>
      <div style="float : right ">2 132,00€</div>
    </div>
    <div>
      <hr style="width : 100%; border-top: dotted 3px;font-weight : bold;" />
      <div style="float : left;font-weight : bold;">TOTAL TTC</div>
      <div style="float : right;font-weight : bold;">12 792,00€</div>
    </div>
  </div>

And if anyone got another solution, then I wanted :), thx

回答1:

LibreOffice/Apache OpenOffice is a great application, but in this case it is not the right tool for the job. There are many applications that render HTML more effectively.

This worked for me, adapted from https://superuser.com/questions/592974/how-to-print-to-save-as-pdf-from-a-command-line-with-chrome-or-chromium.

./chrome.exe --headless --disable-gpu --print-to-pdf=file1.pdf http://www.example.com/

EDIT:

To make this call in Java, see How to execute system commands (linux/bsd) using Java.