0

I have prepared a pdf which comprises of some data, followed by some whitespace. I don't know how large the data is,but i have to remove the whitespace in document,see the following code Note:documents contains only text

Document document = new Document(PageSize.A4, 40, 72, getMargins(1),20); document.setMarginMirroringTopBottom(true); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(webapps/wordimages/dischhip86.pdf)); List list1 = dao.executeQuery("select wordole from ip.dischargetemplate where patid='"+patid+"'");

String html = ((Map)list1.get(0)).get("WORDOLE").toString(); InputStream _ishtml = new ByteArrayInputStream(html.getBytes());

HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event);

writer.setBoxSize("art", new Rectangle(36, 54, 559, 788)); document.open();

Font font = FontFactory.getFont("Times-Roman"); XMLWorkerHelper.getInstance().parseXHtml(writer, document, _ishtml);

venky pup
  • 1
  • 3

1 Answers1

0

PDF can be seen a representation of a paper document, so you cannot just cut whitespaces.

From a physical world perspective, you can cut a blank space of a paper document using scissors, which in PDF means a change/reducing of a target page format.

Alternatively you can scale up the PDF content to exactly fit a desired page format width.

What do you see as an acceptable solution?

Both options have drawbacks: the first one leads to an output of PDFs with non-standard page formats. The second one results a content scale (i.e. font size) changes itself from document to document.

As I see in your code sample, you convert HTML to PDF. Third option would be to re-arrange HTML document layout to leave no blank spaces (i.e. represent as a two columns of content).

If the first two options are still acceptable for you, you could try HTML-to-PDF converter PD4ML. Its API call pd4ml.adjustHtmlWidth() implements the content scaling logic (option #2).

Also using PD4ML it is possible to measure HTML content width and to choose a target page format, matches the content width the best (option #1).

zfr
  • 339
  • 4
  • 11