Hi Tahir,
Thanks for looking into this.
I have tried both the above mentioned approaches.But with no success.
I am still not able to get the CSS applied.Below are the details of my implementation.
Please look into this and suggest me any changes.
Approach 1:
-----------
1.Save the html file, CSS and logos at local hard drive and use the same code to achieve correct output. Please see the attachment.
With this approach I am able to get the Client logo but not the CSS.
shows labels and form options in one column left-justified, instead of two columns.
Expected: The output PDF should look like the input html, including column display, font type, font style, etc.
Please see the attached pdf file “NoCSSApplied.pdf”.
Approach 2:Use the method OpenDocumentFromUrl to load document from URL.
I have used the following code:
private Document OpenDocumentFromUrl(string url)
{
//Prepare the web page we will be asking for
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.ContentType = "text/html";
request.UserAgent = "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0";
//Execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//We will read data via the response stream
Stream resStream = response.GetResponseStream();
//Write content into the MemoryStream
BinaryReader resReader = new BinaryReader(resStream);
MemoryStream docStream = new MemoryStream(resReader.ReadBytes((int)response.ContentLength));
// Open document from stream.
string filename = @"D:\Aspose\test.htm";
//save the file to the local disk inoreder to replace the relative paths to absolute paths
SaveMemoryStream(docStream, @"D:\test.htm");
Document doc = new Document(docStream);
return doc;
}
private void SaveMemoryStream(MemoryStream ms, string FileName)
{
FileStream outStream = File.OpenWrite(FileName);
ms.WriteTo(outStream);
outStream.Flush();
outStream.Close();
}
Aspose.Words.LoadOptions lo = new Aspose.Words.LoadOptions();
lo.LoadFormat = Aspose.Words.LoadFormat.Html;
string readText = File.ReadAllText(@" D:\test.htm");
string dataToRemove = "href=\"/jetstream";
string dataToRemove2 = "src=\"/jetstream";
string dataToRemove3 = "../../../../../../..";
//replace the relative paths with absolute paths.
readText = Regex.Replace(readText, dataToRemove, "href=\"https://" + "VIZSPOTHUGADT01" + "/jetstream", RegexOptions.IgnoreCase);
readText = Regex.Replace(readText, dataToRemove2, "src=\"https://" + "VIZSPOTHUGADT01" + "/jetstream", RegexOptions.IgnoreCase);
readText = Regex.Replace(readText, dataToRemove2, "src=\"https://" + "VIZSPOTHUGADT01" + "/jetstream", RegexOptions.IgnoreCase);
readText = Regex.Replace(readText, dataToRemove3, "https://VIZSPOTHUGADT01");
File.WriteAllText(@" D:\test2.htm", readText);
Aspose.Words.Document doc2 = new Aspose.Words.Document(@" D:\test2.htm", lo);
//conver the html to image files.
for (int pageCounter = 0, stop = doc2.PageCount; pageCounter < stop; pageCounter++)
{
Aspose.Words.Saving.ImageSaveOptions options2 = new Aspose.Words.Saving.ImageSaveOptions(SaveFormat.Png);
options2.PageIndex = pageCounter;
options2.PrettyFormat = true;
// images are of the format \<0-padded-page-index>.png, e.g. (somepath\myfile02.png)
doc2.Save(string.Format("{0}{1}{2}{3:d2}.png", "D:\\Aspose\\RDP\\NEWFiles\\Images\\", "", "MyImagetest", pageCounter + 1), options2);
}
With this approach also I am not able to get the CSS applied.
Can you please look into this and help me to convert the html file to image file with all the CSS applied.
Thanks,
Siddi.