Welcome Guest Search | Active Topics | Sign In | Register

Facing issue while converting html to pdf Options
harish
Posted: Friday, April 12, 2013 2:24:21 AM
Rank: Newbie
Groups: Member

Joined: 4/12/2013
Posts: 1
Hi,

my controls is spliting into to two pages when converting html to pdf.

I have used page-break-inside:avoid; in line style on my controls but still controls are spliting between two pages.

my code is below

public byte[] Export(string bodyHtml, string headerString = null, string footerString = null)
{
try
{
EO.Pdf.PdfDocument doc = new PdfDocument();
HtmlToPdfOptions options = new HtmlToPdfOptions();
options.BaseUrl = ConstantHelper.WebRootUrl;

options.PageSize = EO.Pdf.PdfPageSizes.A4;
options.SaveImageAsJpeg = true;

this.headerHtml = headerString;
options.AutoAdjustForDPI = true;
if (!string.IsNullOrWhiteSpace(headerString))
{
options.BeforeRenderPage = this.On_BeforeRenderPage;
options.OutputArea = new RectangleF(0f, 1.3f, 8.3f, 11.7f);
}
else {
options.OutputArea = new RectangleF(0f, 0f, 8.3f, 11.7f);
}

string stylesheetTag = "style sheet path";

EO.Pdf.HtmlToPdf.ConvertHtml(string.Concat(stylesheetTag, bodyHtml), doc, options);
MemoryStream ms = new MemoryStream();
doc.Save(ms);
var pdfByteArray = ms.ToArray();
doc = null;
return pdfByteArray;
}
catch (Exception ex)
{
ExceptionHandlingUtility.ExceptionHandling(ex, "PDFHelper", "Export", 0, MethodType.Get, "Business Policy");
return null;
}


}

private void On_BeforeRenderPage(object sender, EO.Pdf.PdfPageEventArgs e)
{
string stylesheetTag = "style sheet path";

EO.Pdf.HtmlToPdf.Options.OutputArea = new RectangleF(0f, 0f, 8.3f, 1.7f);

EO.Pdf.HtmlToPdf.Options.BaseUrl = ConstantHelper.WebRootUrl;


EO.Pdf.HtmlToPdf.ConvertHtml(string.Concat(stylesheetTag, this.headerHtml), e.Page);
}

Please help.....
eo_support
Posted: Friday, April 12, 2013 9:22:31 AM
Rank: Administration
Groups: Administration

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

Your code looks fine. If the block that you don't want to split is larger than a single page, it will ALWAYS be split into two pages ---- this is because no matter where you page it, it will never fit into a single page. The only way to make it to fit is to adjust the scale factor. You can find more information about scaling here:

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

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.