Free Support Forum - groupdocs.com

Converting to one html file


#1

Hi,

I’m using GroupDocs.Viewer 19.10.0 for .NET.
I have files with multiple pages inside (word, pdf). Is it possible to convert all pages to one html output file?

Thanks,
Dariusz


#2

@kamelwielki,

We are currently investigating your scenario (logged as VIEWERNET-2219) to combine the HTML files into a single file. As a workaround, you can merge the files manually as shown in the following code sample:

// filePath="sample.xml"
static void renderDocument(string filePath)
{
	string outputDirectory = "D:/output";
	outputDirectory = Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(filePath));
	if (!Directory.Exists(outputDirectory))
	{
		Directory.CreateDirectory(outputDirectory);
	}
	// The {0} will be replaced with current processing page number.
	string pageFilePathFormat = Path.Combine(outputDirectory, "page_{0}.html");

	using (Viewer viewer = new Viewer(filePath))
	{
		HtmlViewOptions htmlOptions = HtmlViewOptions
			.ForEmbeddedResources(pageFilePathFormat);
		htmlOptions.RenderResponsive = true;
		viewer.View(htmlOptions);
	}
	// Combine files into a single HTML file
	combineFiles(outputDirectory);
}
public static void combineFiles(string folderPath)
{
	string[] inputFilePaths = Directory.GetFiles(folderPath, "*.html");
	using (var outputStream = File.Create(Path.Combine(folderPath, "combined_output.html")))
	{
		foreach (var inputFilePath in inputFilePaths)
		{
			using (var inputStream = File.OpenRead(inputFilePath))
			{
				inputStream.CopyTo(outputStream);
			}
		}
	}
}

#3

Your solution based on simple joining of files is not an option - I don’t want an html file with many head, body, styles tags etc.
Even if I combine head and body tags to have one body and head element in the resulting file, I’m still not sure if css styles will not interfere with each other.


#4

@kamelwielki,

In fact, GroupDocs.Viewer is designed to work for the document viewer applications where the document is loaded/displayed in the form of pages. It makes it simple to navigate to a particular page, apply watermark, rotate/reorder a page etc. and this is how the document viewers work. Imagine we have a large PDF/Word document rendered into single HTML file. The resultant HTML file could be large enough in size as well as in length of the content.

The feature of rendering into single HTML may be useful for small documents where it’s better to have single HTML document on the output, for example XML files. However, we are investigating it further to check the feasibility of this feature. We shall let you know in case of any updates.