Welcome Guest Search | Active Topics | Sign In | Register

EO-PDF Blank page at end Options
Phil
Posted: Wednesday, May 2, 2018 5:40:52 AM
Rank: Advanced Member
Groups: Member

Joined: 11/8/2017
Posts: 66
Hello, I have the code that follows below that uses Bootstrap 4 styles. I run the HTML as is (with the Bootstrap styles) thru EO-PDF (latest version 18.1.56.0), with Letter and Landscape settings (see C# code that runs it below the HTML code) and I get 4 pages of content. However If I change the first div line from:-
<div class="main-content my-normal-text">
to
<div class="main-content my-small-normal-text">
...I get 4 pages of content with a blank page at the end.

Any ideas how I get rid of the blank page ?

Note - as a solution
- I would prefer pure HTML/CSS (no 'remove-blank-page' logic in the API)
- I cannot simply reduce the sizes (height or width as I have a blue colored background). Changing the size would potentially leave a white vertical/horizontal strip
- I would prefer also not to use the ShrinkToFit/ScaleToFit settings for the same reason (potential horizontal/vertical white strip)

Code: HTML/ASPX
<style type="text/css">
  .letter-landscape {
    overflow: hidden;
    height: 8.5in !important;
    max-height: 8.5in !important;
    min-height: 8.5in !important;
    width: 11in !important;
    max-width: 11in !important;
    min-width: 11in !important;
  }
  .my-normal-text {
    font-size: 8pt !important;
    line-height: 14px !important;
  }
  .my-small-normal-text {
    font-size: 8pt !important;
    line-height: 12px !important;
  }
</style>
<div class="main-content my-normal-text">
  <div class="container-fluid">
    <div class="letter-landscape">
      <div class="row mb-1">
        <div class="col-12 col-sm-9 large-text font-weight-bold  mt-1 mb-1"><span class="dark-blue">1111</span>2222</div>
        <div class="col-12 col-sm-3 text-left text-sm-right">3333</div>
      </div>
      <div class="row">
        <div class="col-12">
          <div>4444</div>
        </div>
      </div>
      <div class="row">
        aaaa
      </div>
    </div>
    <div class="letter-landscape">
      <div class="row mb-1">
        xxxx
      </div>
      <div class="row">
        yyyy
      </div>
      <div>
        zzzz
      </div>
    </div>
    <div class="letter-landscape">
      <div class="row mb-1">
        <div class="col-12 col-sm-9 large-text font-weight-bold  mt-1 mb-1"><span class="dark-blue">1111</span>2222</div>
        <div class="col-12 col-sm-3 text-left text-sm-right">3333</div>
      </div>
      <div class="row">
        <div class="col-12">
          <div>4444</div>
        </div>
      </div>
      <div class="row">
        aaaa2
      </div>
    </div>
    <div class="letter-landscape">
      <div class="row mb-1">
        xxxx2
      </div>
      <div class="row">
        yyyy2
      </div>
      <div>
        zzzz2
      </div>
    </div>
  </div>
</div>


Code: C#
SizeF sizeF;

if (uploadData.PageSize.ToLower() == "letter")
{
    sizeF = (uploadData.PageOrientation.ToLower() == "portrait") 
        ? new SizeF(PdfPageSizes.Letter.Width, PdfPageSizes.Letter.Height)
        : new SizeF(PdfPageSizes.Letter.Height, PdfPageSizes.Letter.Width);
}
else
{
    sizeF = (uploadData.PageOrientation.ToLower() == "portrait")
        ? new SizeF(PdfPageSizes.Tabloid.Width, PdfPageSizes.Tabloid.Height)
        : new SizeF(PdfPageSizes.Tabloid.Height, PdfPageSizes.Tabloid.Width);
}

HtmlToPdf.Options.BaseUrl = uploadData.BaseUrl;
HtmlToPdf.Options.PageSize = sizeF;
HtmlToPdf.Options.OutputArea = new RectangleF(0, 0, sizeF.Width, sizeF.Height);
HtmlToPdf.Options.AutoFitX = HtmlToPdfAutoFitMode.None;
HtmlToPdf.Options.UsePrintMedia = true;
HtmlToPdf.DebugConsole = Console.Out;
HtmlToPdf.Options.NoLink = true;

EO.Pdf.Runtime.AddLicense("xxxxxxxx");

using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
    HtmlToPdf.ConvertHtml(uploadData.InputHtml, stream);

    bytes = stream.ToArray();
}
result = new HttpResponseMessage(HttpStatusCode.OK)
{
    Content = new ByteArrayContent(bytes)
};
eo_support
Posted: Wednesday, May 2, 2018 2:25:44 PM
Rank: Administration
Groups: Administration

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

We tested your code and we could not reproduce the problem. My guess is some kind of rounding issues that caused the extra blank page at the end.

The best way for you to do paging is not through hard coding the page size. The best way is to force a page break when needed. See here for more details:

https://www.essentialobjects.com/doc/pdf/htmltopdf/paging.aspx

So instead of having full page size divs, you would just have "normal" divs but force a page break after every div. For example:

Code: HTML/ASPX
<div style="page-break-after:always;">
page 1
</div>
<div>
page 2
</div>


This means the first DIV will only occupy a small portion at the top of the first page instead of occupying the whole page. If you need full page background, you should use HtmlToPdf.Options.BeforeRenderPage callback. The following code demonstrate how to fill the whole page with blue:

Code: C#
//Convert the main content
HtmlToPdf.Options.BeforeRenderPage = BeforeRenderPage;
HtmlToPdf.ConvertUrl(url, pdf_file);

//This function is called for each page before the main contents
//is generated. So you can use this function to generate page
//background
static void BeforeRenderPage(object sender, PdfPageEventArgs e)
{
    //Use ACM interface to fill the page with blue. The code
    //assume your page size is 8.5 * 11 (the default size)
    AcmRender render = new AcmRender(e.Page, 0, new AcmPageLayout(new AcmPadding()));
    AcmBlock block = new AcmBlock();
    block.Style.Left = 0;
    block.Style.Top = 0;
    block.Style.Width = 8.5f;
    block.Style.Height = 11f;
    block.Style.BackgroundColor = Color.Blue;
    render.Render(block);
}


Please let us know if this works for you.

Thanks!
Phil
Posted: Monday, May 7, 2018 9:55:43 AM
Rank: Advanced Member
Groups: Member

Joined: 11/8/2017
Posts: 66
Thank-you - adding the callback event fixed the issue - because the solution can be applied generally (with some configuration) adding the logic server-side was fine
eo_support
Posted: Monday, May 7, 2018 2:10:55 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Great. Glad to hear that it works for you. Please feel free to let us know if there is anything else.


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.