With the example code I've used, this approach creates an output which contains many HTML and HEAD tags - the document still renders in a browser, but is there a way to stop the multiple tags?
I'm just getting pages out of local filestream via htmlHandler.GetPages(fs), and this also creates several @font-face declarations in each page - do those need to be accounted for? I'd rather not extract them to supporting files like the ASP.Net MVC Front End showcase project does.
Yes, you can achieve this functionality by providing range of the document pages to convert in HtmlOptions or ImageOptions. You can do this using following code
GroupDocs.Viewer for .NET does not provide any builtin method to escape from multiple tags in case of merging HTML pages into single page. However, you can use your own logic to extract the child elements of all head tags, trim/remove head tags from HTML content of all pages and then add a single head tag in final html page (containing body of all HTML pages) that will contain the child elements extracted at first step. You can play with HTML content of each page using following code:
foreach (PageHtml page in pages)
{
string outputHtmlContent = page.HtmlContent;
// you can use outputHtmlContent to perform your required operations on HTML content
}
Secondly, when you use embedded resources then all the resources (including font faces) get embedded in HTML pages. However, when you do not use embedded resources then the API creates a separate directory named “resources” containing all the resources in it and adds reference of these resources in HTML page. Following code snippet shows how to set embedded resources.
//Instantiate the HtmlOptions object
HtmlOptions options = new HtmlOptions();
//to get html representations of pages with embedded resources
options.IsResourcesEmbedded = false;
List pages = htmlHandler.GetPages(guid, options);
If anything is not yet clear, please feel free to tell us.
If I use the options with Range(1,10) this is works only for file which contains more than 10 pages. If the file has less than 10 pages, i get an exception.
I resolve this problem in wich I use the function:
Thank you for the swift reply. I figured I’d have to play about with the HTML as your example shows, and thank you for the clarification on the resources.
I do have another question, but I need to write some sample code first.
Its good to know that you have resolved your issue.
You can also get complete information about a document, containing number of pages, before rendering that document. This will help you to escape from any exception. For more details, please see Working with Document Information.