Does Aspose support opening an HTML file with script?
I tried using the Aspose.Word to open an HTML file, with the final intention of converting it to RTF/MS-Word file and It seems like Aspose ignore the client-side javascript when loading the html.
Attached is the zip file containing the html and its content.
Any help would be greatly appreciated.
You are correct - Aspose.Words does not support javascript while loading html. As we all know JScript is implemented as part of web browser to enhance user interface and dynamic website. I know that part of applications use it, for example PDF-document. But as far as I know Words does not use javascript. The same for Aspose.Words product - it ignores javascript and does not interpret it code.
Hope I answered to you question. Please let us know if you have any concerns.
Yes MSWords does not use Javascript.
But one thing that programmers normally uses the old Ms-Word API for is perform a ‘Copy’ from a web-browser displaying a html file and perform a ‘Paste’ into the word document using the API, then subsequently save it to whatever document conversion format that is supported by MS-Word (e.g. RTF, DOC etc.)
This copy and paste mechanism allow us to preserve the WYSIWYG format of the html file from the web browser, even in the case where the html file contains javascript.
Reason why I ask is because we are trying to replace our current usage of MS-Word api w/ Aspose API, and the aforementioned logic is one of the thing that we need to support.
I am just wondering if this would be something that would be supported by Aspose.Words in the near future?
Thank you for additional information. Execution JavaScrips on HTMl page is out of scope of Aspose.Words. However, what you are asking for can be done through clipboard. You can open url in browser, copy content to clipboard and then load document from clipboard. I created a simple code example for you to demonstrate the technique:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Aspose.Words;
namespace TestClipboard
{
class Program
{
[STAThread]
static void Main(string[] args)
{
Process p = new Process();
p.StartInfo.FileName = "IExplore.exe";
p.StartInfo.Arguments = "http://localhost/test/TestHTMLWScript.htm";
p.Start();
Thread.Sleep(5000); // Wait for few seccons while page is loading.
SetFocus(new HandleRef(null, p.Handle));
SendKeys.SendWait("^a"); // Send ctrl+a to select all content of page.
Clipboard.Clear(); // clear clipboard.
SetFocus(new HandleRef(null, p.Handle));
SendKeys.SendWait("^c"); // Send ctrl+c to copy content to clipboard.
SetFocus(new HandleRef(null, p.Handle));
SendKeys.SendWait("%({F4})"); // close browser window (send alt+f4)
Thread.Sleep(10000); // It needs some time to load content into clipboard.
Console.WriteLine(Clipboard.ContainsText());
// Get content from clipboard.
string rtf = Clipboard.GetText(TextDataFormat.Rtf);
// Now we can load RTF into Aspose.Words.Document.
MemoryStream rtfStream = new MemoryStream(Encoding.UTF8.GetBytes(rtf));
Document doc = new Document(rtfStream);
doc.Save(@"C:\Temp\out.doc");
Console.WriteLine("Done.");
Console.ReadLine();
}
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr SetFocus(HandleRef hWnd);
}
}
Hope this could be useful for you.
Best regards,
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.