allcolor / YaHP-Converter

YaHP is a Java library that allows you to convert an HTML document into a PDF document.
GNU Lesser General Public License v2.1
56 stars 23 forks source link

If there are images in header and/or footer, nothing from header/footer is displayed #10

Closed ppetak closed 11 years ago

ppetak commented 11 years ago

Hi,

I'm using your converter in the project of mine for some easy and simple html data sheets to PDF export. What I want to achieve is to have a nice small image on every page footer. Which is not working - every time I add one image, nothing from header/footer is displayed at all.

This is how I use it:

headerFooterList.add(new IHtmlToPdfTransformer.CHeaderFooter(
                "<span><img src=\"file:///" + (new File("img_footer.jpg")).getAbsolutePath()+"\"/></span>",
                IHtmlToPdfTransformer.CHeaderFooter.FOOTER));

The image is there, and path is translated correctly to: ""

If I add some other html - it will display, but still, if it is more than approx. one line, it overflows out of the page

In my opinion the correct behaviour should be - if the footer is there, shorten the printed page body to have it all in printable area.

Is there some solution for this? All my ideas and googled methods failed. (ie, change the print page dimension in css, etc.. )

allcolor commented 11 years ago

Hi, you have to correctly size the margin of your pages. The header and footer must absolutely fit in them. But an easy way to add header and footer is to use absolute positionning, no margins and clever use of page break.

Regards, Quentin Le 19 juil. 2013 12:34, "ppetak" notifications@github.com a écrit :

Hi,

I'm using your converter in the project of mine for some easy and simple html data sheets to PDF export. What I want to achieve is to have a nice small image on every page footer. Which is not working - every time I add one image, nothing from header/footer is displayed at all.

This is how I use it:

headerFooterList.add(new IHtmlToPdfTransformer.CHeaderFooter( "<img src=\"file:///" + (new File("img_footer.jpg")).getAbsolutePath()+"\"/>", IHtmlToPdfTransformer.CHeaderFooter.FOOTER));

The image is there, and path is translated correctly to: ""

If I add some other html - it will display, but still, if it is more than approx. one line, it overflows out of the page

In my opinion the correct behaviour should be - if the footer is there, shorten the printed page body to have it all in printable area.

Is there some solution for this? All my ideas and googled methods failed. (ie, change the print page dimension in css, etc.. )

— Reply to this email directly or view it on GitHub.

ppetak commented 11 years ago

OK, I have tried almost anything before I will go into table-generator and try to cut the table to pages manually. I do not want to do this, because this table-generator is not my work, but anything with footer failed so far. My biggest problem is that all settings about margin in @page css rule is ignored by YaHP. I ended up with simple page with long text, using only simple @page rule like this:

@page { margin-bottom: 5cm; border: 1px solid red; } }

Border is there only for my visual check, it is the same without it. It is ignoring completely margin line, no matter what I'm using i tried percent, mm, even px, with no success. Is there something I'm missing?

allcolor commented 11 years ago

Hi, Please use the correct PageFormat with correct size for your header and footer and it will work.

Regards, Quentin

2013/7/29 ppetak notifications@github.com

OK, I have tried almost anything before I will go into table-generator and try to cut the table to pages manually. I do not want to do this, because this table-generator is not my work, but anything with footer failed so far. My biggest problem is that all settings about margin in @pagehttps://github.com/pagecss rule is ignored by YaHP. I ended up with simple page with long text, using only simple @page https://github.com/page rule like this:

@page https://github.com/page { margin-bottom: 5cm; border: 1px solid red; } }

Border is there only for my visual check, it is the same without it. It is ignoring completely margin line, no matter what I'm using i tried percent, mm, even px, with no success. Is there something I'm missing?

— Reply to this email directly or view it on GitHubhttps://github.com/allcolor/YaHP-Converter/issues/10#issuecomment-21704190 .

All those moments will be lost in time, like tears in rain.

ppetak commented 11 years ago

Hi, thanks for your time, for trying to help me .. but I'm noob in HTML-PDF converting.

I don't get your last advice .. i'm not using PageFormat class anywhere. What I'm trying to do is get HTML from some pre-generated html file, add some rules to css to manage margins on print page, and add footers. For this I'm using YaHP as found on tutorials page:

converter.convertToPdf(new URL("file:///"+new File(tmpFileName).getAbsolutePath()), IHtmlToPdfTransformer.A4P, headerFooterList, outW, properties);

The HTML page is on disk at the moment of conversion, and if I try to display it in Firefox print preview, page margin IS there exactly as I set it in @page rule. but using YaHP no margin is rendered to PDF, thus no footer is visible (as I assume from your previous post).

How I'm supposed to implement PageFormat into my workflow? Or maybe I'm wrong from the beginning, and there is other right way how to make it, but now I'm lost in it.

allcolor commented 11 years ago

IHtmlToPdfTransformer.A4P is a page size format... with 1cm margin.

That's the thing you must change by providing a correct PageSize object with the desired margin for your image to fit.

But the easiest way to do this is not to use the header/footer function, and to use a pagesize with zero size margin and use absolute positionning.

Regards, Quentin

2013/7/29 ppetak notifications@github.com

Hi, thanks for your time, for trying to help me .. but I'm noob in HTML-PDF converting.

I don't get your last advice .. i'm not using PageFormat class anywhere. What I'm trying to do is get HTML from some pre-generated html file, add some rules to css to manage margins on print page, and add footers. For this I'm using YaHP as found on tutorials page:

converter.convertToPdf(new URL("file:///"+new File(tmpFileName).getAbsolutePath()), IHtmlToPdfTransformer.A4P, headerFooterList, outW, properties);

The HTML page is on disk at the moment of conversion, and if I try to display it in Firefox print preview, page margin IS there exactly as I set it in @page https://github.com/page rule. but using YaHP no margin is rendered to PDF, thus no footer is visible (as I assume from your previous post).

How I'm supposed to implement PageFormat into my workflow? Or maybe I'm wrong from the beginning, and there is other right way how to make it, but now I'm lost in it.

— Reply to this email directly or view it on GitHubhttps://github.com/allcolor/YaHP-Converter/issues/10#issuecomment-21706729 .

All those moments will be lost in time, like tears in rain.

ppetak commented 11 years ago

Great! Thank you very much, at last I have gotten your point, make my own page size with margins in java, not in css! How could I be so blind :) Now i have made proper margins and everything works fine, without absolute positioning.

Thanks again!

ppetak commented 11 years ago

Some better comment for anyone as blind as me:

you must define your page like this: new IHtmlToPdfTransformer.PageSize(21*cm, 29.5*cm,1*cm,1*cm,4*cm,1.5*cm)

not like this:

@page {
margin-bottom: 40mm;
}

all dimensions in cm, so constant cm=1 here (I have some other measures in inches so I'm using this.)