Completed

"Fit to page width" using Java ITextRenderer html2pdf conversion

This project was successfully completed by chinbochen for $300 USD in 5 days.

Get free quotes for a project like this
Employer working
Completed by:
Skills Required
Project Budget
$30 - $250 USD
Completed In
5 days
Total Bids
5
Project 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);
}
}

Looking to make some money?

  • Set your budget and the timeframe
  • Outline your proposal
  • Get paid for your work

Hire Freelancers who also bid on this project

    • Forbes
    • The New York Times
    • Time
    • Wall Street Journal
    • Times Online