Welcome Guest Search | Active Topics | Sign In | Register

Footer leaving gap below Options
JVK
Posted: Tuesday, June 10, 2014 9:55:38 AM
Rank: Newbie
Groups: Member

Joined: 6/10/2014
Posts: 5
Here is the code I'm using to generate my PDF with the HtmlToPdf library
Code: C#
var oa = new RectangleF(0, 0, PdfPageSizes.Letter.Width, PdfPageSizes.Letter.Height);

			if (opts.adjust_body_by_footer_margin)
			{
				oa.Height -= opts.footer_margin;
			}

			if (opts.adjust_body_by_header_margin)
			{
				oa.Height -= opts.header_margin;
				oa.Y += opts.header_margin;
			}

			if (opts.adjust_body_by_left_margin)
			{
				oa.Width -= opts.left_margin;
				oa.X += opts.left_margin;
			}

			if (opts.adjust_body_by_right_margin)
			{
				oa.Width -= opts.right_margin;
			}

			var options = new HtmlToPdfOptions
				              {
					              JpegQualityLevel = 100,
					              PageSize = PdfPageSizes.Letter,
					              OutputArea = oa
				              };

			var res = EO.Pdf.HtmlToPdf.ConvertHtml(opts.body, opts.directory + @"/" + opts.filename, options);
			for (var p = 0; p < res.PdfDocument.Pages.Count; p++)
			{
				if ((opts.header_first_page_only && p == 0) || (opts.header_last_page_only && p == res.PdfDocument.Pages.Count - 1) || (!opts.header_first_page_only && !opts.header_last_page_only))
				{
					var pg = res.PdfDocument.Pages[p];

					var os = new HtmlToPdfOptions
						         {
							         PageSize = PdfPageSizes.Letter,
							         OutputArea = new RectangleF(0, 0, PdfPageSizes.Letter.Width, PdfPageSizes.Letter.Height)
						         };

					EO.Pdf.HtmlToPdf.ConvertHtml(opts.header, pg, os);
				}

				if ((opts.footer_first_page_only && p == 0) || (opts.footer_last_page_only && p == res.PdfDocument.Pages.Count - 1) || (!opts.footer_first_page_only && !opts.footer_last_page_only))
				{
					var pg = res.PdfDocument.Pages[p];

					var os = new HtmlToPdfOptions
						         {
							         PageSize = PdfPageSizes.Letter,
							         OutputArea = new RectangleF(0, PdfPageSizes.Letter.Height - opts.footer_height, PdfPageSizes.Letter.Width, opts.footer_height)
						         };

					EO.Pdf.HtmlToPdf.ConvertHtml(opts.footer, pg, os);
				}
			}

			res.PdfDocument.Save(opts.directory + @"/" + opts.filename);


For some reason though I'm getting a small gap below the footer, about a pixel or 2. If I make a div that has a solid background color and set it's height really tall it'll wrap around vertically but still leave this little gap. Any ideas why?
eo_support
Posted: Tuesday, June 10, 2014 3:26:55 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

I am not exactly sure if I understand what you meant by "gap below the footer". Generally, you should not have footer that produces solid fill color/lines and intend for it to align to the bottom of the paper. The reason is PDF is not pixel accurate. While the coordination are specified in float, when the are rounded to integer they can be aligned to different pixel positions. For example, a float value 0.5 and 0.9 can be aligned to the same integer value 1 at 100% zoom level, but can be aligned to value 1 and value 2 respectively at 180% zoom level (because 0.5 * 1.8 = 0.9 and 0.9 * 1.8 = 1.62).

Thanks!
JVK
Posted: Wednesday, June 11, 2014 8:43:42 AM
Rank: Newbie
Groups: Member

Joined: 6/10/2014
Posts: 5
If I change to using these options:

Code: C#
var options = new HtmlToPdfOptions
				              {
					              JpegQualityLevel = 100,
								  PageSize = PdfPageSizes.Letter,
					              OutputArea = oa,
								  FooterHtmlFormat = opts.footer,
								  FooterHtmlPosition = ps.Height - opts.footer_height,
								  HeaderHtmlFormat = opts.header,
								  HeaderHtmlPosition = 0
				              };


It will align perfectly, however I no longer have the ability to control which pages the footer / header show on. Is there a way to control which pages the header and footer show on, other than doing it manually after the pdf is generated?
eo_support
Posted: Wednesday, June 11, 2014 9:42:17 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

No. The only way to have advanced logic is to do it in a loop after the main conversion. In fact even FooterHtmlFormat and HeaderHtmlFormat are done after the main conversion in a loop in a similar fashion. It's just those are done by our code. But theoretically there shouldn't be any difference between your code and our code ---- there is one thing that you must pay attention is the zoom level. When you use a loop to add the header/footer in your code. It is possible that your main contents and the footer are on different zoom level. To verify if this is the problem for you, check this property for both conversions:

http://www.essentialobjects.com/doc/4/eo.pdf.htmltopdfresult.zoomlevel.aspx

If they are not the same, then you will need to set this property when you convert your header/footer:

http://www.essentialobjects.com/doc/4/eo.pdf.htmltopdfoptions.zoomlevel.aspx

Thanks!
JVK
Posted: Wednesday, June 11, 2014 11:20:39 AM
Rank: Newbie
Groups: Member

Joined: 6/10/2014
Posts: 5
I'm leaving the zoomlevel as the default for all conversions.
eo_support
Posted: Wednesday, June 11, 2014 11:28:58 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
That's exactly what we were trying to tell you ----- you need to set it instead of leaving it to default. See here for more details about how the converter automatically resize the output:

http://www.essentialobjects.com/doc/4/htmltopdf/auto_fit.aspx

Thanks
JVK
Posted: Wednesday, June 11, 2014 11:38:58 AM
Rank: Newbie
Groups: Member

Joined: 6/10/2014
Posts: 5
I tried setting ZoomLevel to 1 for all conversions and it still has the same issue.
eo_support
Posted: Thursday, June 12, 2014 4:52:57 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

Please try to read the above link again. It appears that you do not pay enough attention to either our explanation here or explanation in our documentation. There are several properties related to zooming. Sometimes you may need to set one, sometimes you may need to set multiple of them. The only way for you to get them working for you is that you understand what each properties is for and when to use them. We can not tell you exactly what to do unless we debug through your code, which obviously is not something we can afford to do for free here. We can only tell you where to look.

If you have read the documentation but still have specific questions about anything please feel free to ask, we will be happy to explain it further to you. Also, if you have tried all properties but still can not get it to work, or if you believe there is a problem on our end, please try to produce a test project and send the test project to us. Once we receive that we will look into it as soon as possible. Please see test project instructions here:

http://www.essentialobjects.com/forum/test_project.aspx

Thanks!
JVK
Posted: Friday, June 13, 2014 8:41:32 AM
Rank: Newbie
Groups: Member

Joined: 6/10/2014
Posts: 5
I did read it several times and fully understand how the properties work. I ended up setting the outputarea of the footer content to the full page and used css to position it to the bottom and it's working properly now.

Thanks for trying to help anyway.
eo_support
Posted: Friday, June 13, 2014 9:13:25 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Great. That will work too. Please feel free to let us know if there is anything else.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.