"Fit to page width" using Java ITextRenderer html2pdf conversion

Closed

Description

We generate a html page as Java String and convert it to pdf using ITextRenderer.

The generated pdf is in vector mode, we would like to scale it to fit a certain page widht (A4 paper). We want to keep the vector representation.

We need such code, it should use free libraries or necessary code should be included as deliverable.

Requirements:

- The solution cannot be a css tweak because it must be dynamic independent of given page content and styles

- The implementation must be in Java. You will need to hack into Itextrenderer etc.

- Width must squeeze to fit A4 width, length is not important (preserve scale/proportionality of width x height), it will print as many pages as necessary split by A4 height.

Current code is:

/**

* Convert HTML to PDF

* @param in HTML

* @param out PDF

*/

public static void html2pdf(InputStream in, OutputStream out) {

try {

StringWriter sw = new StringWriter();

Tidy tidier = new Tidy();

{

[url removed, login to view](ENCODING);

[url removed, login to view](true);

[url removed, login to view](true);

[url removed, login to view](true);

[url removed, login to view](false);

[url removed, login to view](false);

[url removed, login to view](in, sw);

[url removed, login to view]();

}

{

ITextRenderer renderer = new ITextRenderer();

[url removed, login to view]([url removed, login to view]().toString());

[url removed, login to view]();

[url removed, login to view](out);

}

} catch (Throwable e) {

throw new RuntimeException(e);

}

}

Skills: Java, Software Architecture

See more: itextrenderer, itextrenderer page, itextrenderer page width, java html2pdf, itextrenderer fit page, java html fit page, itextrenderer html, itextrenderer layout, setdocumentfromstring itextrenderer, java itextrenderer, itextrenderer pdf scale, html2pdf, html2pdf java, itextrenderer pdf page width, vector vector string, vector string, string vector, split page html, param software, page split, java to c convert, convert pdf to css, convert java to c, param java, java flush

Project ID: #4796222

Awarded to:

chinbochen

Hello, I'm a Java, JEE developer with over 10 years experience. I'm glad to work for you. thanks.

$300 USD in 5 days
(4 Reviews)
4.1

5 freelancers are bidding on average $153 for this job

eperfections

Java Expert! Let me fix it.

$147 USD in 3 days
(312 Reviews)
6.9
ranganathp

Can help.. I am an expert...

$100 USD in 7 days
(12 Reviews)
5.3
szymszteinsl

Ready, sir!

$154 USD in 3 days
(11 Reviews)
4.2
HBalkaran

I can complete this task. I have extensive experience writing applications that manipulated pdf using the iText pdf library. I can modify ITextRenderer to generate your desired result.

$66 USD in 3 days
(4 Reviews)
3.2