PDF Generating Tool Support Forum

HOME   Login   Register    Search




  Subject: Urgent -Bad pdf layout - it span only 1/4 of normal width
   PostPosted: 21 Dec 2011, 17:53 
Hi,

In our product, PD4ML is being used to generate pdf report from html.
One of our customers generated the report which is very badly formated (although html file looks fine) - On each page, it spans 1/4 portion of page on the left, while other 3/4 page on the right is blank.

I am not sure how to attach screenshot here but if you give me a email address, I can send you screenshot.

Below is the snippet of code that I used PD4ML to generate pdf:

public InputStream render(List<InputStream> pages, Map<ReportMetadata, Serializable> reportMetadata)
throws RenderingException {

boolean landscapeView = false;
if (reportMetadata.containsKey(ReportMetadata.ORIENTATION)
&& "landscape".equalsIgnoreCase(reportMetadata.get(ReportMetadata.ORIENTATION).toString()))
landscapeView = true;

PD4ML converter = new PD4ML();
converter.setPageSize( landscapeView ? converter.changePageOrientation( PD4Constants.LETTER ): PD4Constants.LETTER );
converter.setPageInsets(new Insets(20, 50, 10, 10));
converter.enableImgSplit(false);
converter.enableTableBreaks(true);

if(landscapeView)
converter.setHtmlWidth(1000);
else
converter.setHtmlWidth(PD4Constants.LETTER.width);

converter.adjustHtmlWidth();


try {
File report = File.createTempFile("pdfreport", ".pdf");

List<File> pdfs = new ArrayList<File>();
File pdf;

// for each page
for (InputStream page : pages) {

// create PDF
pdf = File.createTempFile("pdfreportpage", ".pdf");
pdfs.add(pdf);
converter.render(new InputStreamReader(page),
new FileOutputStream(pdf));
}

PDFUtils.merge(pdfs, report);
for(File tmpFile :pdfs)
tmpFile.delete();
return new FileInputStream(report);

} catch (IOException e) {
throw new RenderingException(e);
} catch (DocumentException e) {
throw new RenderingException(e);
}
}


  Subject: Re: Urgent -Bad pdf layout - it span only 1/4 of normal width
   PostPosted: 21 Dec 2011, 19:47 
Attach generated pdf


  Subject: Re: Urgent -Bad pdf layout - it span only 1/4 of normal width
   PostPosted: 21 Dec 2011, 20:16 
try again to attach screenshot


Attachments:
screenshot_nidc.jpeg
screenshot_nidc.jpeg [ 139.77 KiB | Viewed 1099 times ]
  Subject: Re: Urgent -Bad pdf layout - it span only 1/4 of normal width
   PostPosted: 21 Dec 2011, 20:45 
It looks like htmlWidth conversion parameter value (frame width of virtual web browser) is set too big.

Also there is some garbage characters: it is caused by an invalid or missing charset directive in the source document.

The document HTML source and resulting PDF would help to analyze the issue. Please publish or send to support pd4ml com


  Subject: Re: Urgent -Bad pdf layout - it span only 1/4 of normal width
   PostPosted: 21 Dec 2011, 21:48 
I replaced "converter.adjustHtmlWidth()" with "convert.fitPageVertically()", then everything starts to work fine.
Is it safe to do so? what's differene between these 2 method calls?


  Subject: Re: Urgent -Bad pdf layout - it span only 1/4 of normal width
   PostPosted: 22 Dec 2011, 15:11 
Now I see what was the problem reason: I paid no heed to converter.adjustHtmlWidth() call.

It is better to remove both: converter.adjustHtmlWidth() and convert.fitPageVertically() until you have no special need in the features.

convert.fitPageVertically() tries to place all content to a single page. It does not reflow it, but just scales down content until it fit. If needed scale factors make text extremely tiny, it gives up. Obviously it happens with the document with your current configuration.

converter.adjustHtmlWidth() first renders page with given converter.setHtmlWidth() (virtual web browser frame width), after that calculates right content edge, sets htmlWidth parameter to the new value and re-renders the page. But if the page has an element with width=100% the approach does not work as the right content edge will be always equal to the initial converter.setHtmlWidth() value.

BTW: the code

if(landscapeView)
    converter.setHtmlWidth(1000);
else
    converter.setHtmlWidth(PD4Constants.LETTER.width);


is not correct. As converter.setHtmlWidth() expects a parameter given in screen pixels, but PD4Constants.LETTER.width is a paper format in typographical points. Well, they are both integer values - hopefully you know what you do.


  Subject: Re: Urgent -Bad pdf layout - it span only 1/4 of normal width
   PostPosted: 22 Dec 2011, 22:49 
Thanks for the explanation.

The reason that I add "converter.adjustHtmlWidth()" is to try to fix another issue reported by customer -- sometimes, the content (or table column) was chopped off on the page right side.

Adding "converter.adjustHtmlWidth()" solves that issue. Unfortunately it causes current issue in certain pdf report -3/4 of page shows blank.


  Subject: Re: Urgent -Bad pdf layout - it span only 1/4 of normal width
   PostPosted: 04 Jan 2012, 15:29 
> it causes current issue in certain pdf report -3/4 of page shows blank

It should happen only in situations, when the source HTML has elements with width="100%", which leave no "blank space" to be cut with adjustHtmlWidth()



[Reply]     [ 8 posts ] 

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