Welcome Guest Search | Active Topics | Sign In | Register

Hiding Html elements during pdf conversion Options
nbhor
Posted: Monday, July 8, 2013 2:17:37 PM
Rank: Member
Groups: Member

Joined: 4/30/2013
Posts: 11
As you have guessed from subject that we are trying to hide certain html elements (links, paragraphs, images) during pdf conversion. We have used already forum suggested approach during our conversion but we are facing some issues with it.
We have supplied all html elements IDs comma separated to InvisibleElementIds property. While it seems to be working in most scenarios, we are having diffculty when there are multiple html element with same ID (our html page is dynamically generated and sometimes html element IDs are same). For some reason only last element in html page gets hidden during pdf conversion.
Here is the snippet of our code used for pdf conversion.

System.IO.MemoryStream stream = new System.IO.MemoryStream();
try
{
EO.Pdf.Runtime.AddLicense(pdfParams.Key);
PdfDocument doc = new PdfDocument();
HtmlToPdf.Options.HeaderHtmlFormat = "PDF converted from {url}<hr />";
HtmlToPdf.Options.FooterHtmlFormat = @"<hr /><div style=""text-align:right""><span style=""font-family:Arial,Verdana;font-size:9px;"">" + DateTime.Now.ToShortDateString() + @" | Page {page_number} of {total_pages}</span></div>";
HtmlToPdf.Options.InvisibleElementIds = "lnkLargerImage4;pageGenericMessage;spanTotalItems";
HtmlToPdf.Options.NoLink = true;
HtmlToPdf.ConvertUrl("url of the webpage here", doc);
doc.Save(stream);
stream.Position = 0;
return stream.ToArray();
}
catch (Exception excp)
{
throw new Exception("HtmlToPdf.ConvertUrl failed", excp);
}
finally
{
stream.Dispose();
}

Do you suggest using any other better approach for hiding certain portion\part of html page? Can we have css class based approach for hiding html elements?

Thanks -nilesh
eo_support
Posted: Monday, July 8, 2013 3:18:11 PM
Rank: Administration
Groups: Administration

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

That's normal. Id has to be unique, otherwise we only recognize the last element with the ID. What you can do is to add a small piece of JavaScript in your page that find all the matching elements and set their style.display = "none". The converter will run all JavaScript code the same way as your browser does. So it will hide the elements for you.

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.