Free Support Forum - aspose.com

Convert HTML to Word and PDF?

I have an existing Web application which creates a dynamic HTML report with embedded JPG’s. The user wants the report to instead be generated in a PDF and/or Word format - but still show up in a browser screen using either a PDF or a Word add-in. Additionally, I need a batch process which runs on a schedule and emails these same reports as PDF and Word attachments to the users. It looks like the Aspose product line might do this, but I am unsure which products and how. Ideally I need a server-based solution which my existing web application would feed/stream HTML. If in interactive mode, the user would immediately see a pop-up of a PDF or Word report instead of the existing HTML screen. If in batch mode, the generated PDF and Word documents would be available to the batch process to be used as attachments to emails.


Can Aspose products do this?

Thanks

Hi,


Thanks for your interest in our products.

I am a representative from Aspose.Pdf team. This component provides the feature to create as well as manipulate existing PDF documents. As per your requirement, you may try using this component to read the source HTML and convert it to PDF format. For further details, please visit How to convert HTML to PDF using InLineHTML approach

Now concerning to your requirement on sending these documents as attachment, please try using Aspose.Email. My fellow worker from respective team will share further details regarding this requirement.

Hi,


I am a representative of Aspose.Email.

My colleauge Nayyer has already guided you about how to convert HTML to PDF using Aspose.Pdf. Once you get your desired output file, you can use Aspose.Email for .NET for sending this file as an attachment in an email as follow:

//Create an instance of the MailMessage
class
<o:p></o:p>

MailMessage message = new MailMessage();

//From field

message.From = "username@gmail.com";

//To field

message.To.Add("receiver@aspose.com");

//Adding 1st attachment

//Create an instance of Attachment class

Attachment attachment;

//Load or add an attachment

attachment = new Attachment(@"phase 3 - billing timer records.pdf");

//Now add the attachment to the message

message.Attachments.Add(attachment);

//Create an instance of the SmtpClient Class

//UseSmtp(message);

SmtpClient client = new SmtpClient();

client.Host = "smtp.gmail.com";

//Specify your mail user name

client.Username = "username";

//Specify your mail password

client.Password = "password";

//Specify your Port #

client.Port = 587;

client.EnableSsl = true;

client.SecurityMode = SmtpSslSecurityMode.Explicit;

client.Send(message);



You can get more information about Aspose.Email by visiting our online documentation that contains a number of examples. If you have any additional query/inquiry related to Aspose.Email, please feel free to write to us by visiting the Aspose.Email forum. We'll be glad to assist you further.

I appreciate the prompt responses. Just a couple of additional question for now: (1) In addition to PDF, I also need to build a Word document at the same time using the same HTML. Is the Aspose Word component what I need for that? Or can I go from HTML to PDF and then from PDF to Word using just the PDF product? (2) My HTML contains some embedded Javascript. Will that code get converted correctly? Thanks again.

Hi,


In case you need to convert the source HTML to Word format, you need to try using Aspose.Words. However Aspose.Pdf for .NET also supports the capability to render PDF file to Word (DOC) format. So the workflow would be

  1. First read the HTML
  2. Convert it to PDF format using Aspose.Pdf.Generator namespace
  3. Store the resultant file in Stream object
  4. Instantiate a new Document object from Stream
  5. Render the output in DOC format.

For further information, please visit Convert PDF file into DOC format

Will HTML code with embedded Javascript get converted properly?

Hi,


Thanks for contacting support.

I am afraid the java code inside HTML file is not executed during HTML to PDF conversion. However once the PDF file is generated, you can add JavaScript inside PDF document. We are sorry for this inconvenience. Create JavaScript Link in Existing PDF File (Facades)

Hi there,


I am representative from Aspose.Words team.

Thanks for your inquiry. You can convert HTML document to Pdf and MS Word file formats by using Aspose.Words. Please use the following code snippet to convert html to Pdf/Doc/Docx file formats.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:green;mso-no-proof:yes”>// Open a
document.<o:p></o:p>

Document doc = new Document(MyDir + "Sample+2003.doc");

// Save html document to Pdf

doc.Save(MyDir + "Out.pdf", SaveFormat.Pdf);

// Save html document to Doc

doc.Save(MyDir + "Out.doc", SaveFormat.Doc);

// Save html document to Docx

doc.Save(MyDir + "Out.docx", SaveFormat.Docx);


Moreover, you can find formats of the document that can be loaded into Aspose.Words' DOM from here:
http://www.aspose.com/docs/display/wordsnet/LoadFormat+Enumeration

Once html document is loaded into Aspose.Words' DOM, you can save your html into other file format mentioned here:
http://www.aspose.com/docs/display/wordsnet/SaveFormat+Enumeration

Please read following documentation lik for your kind referece and let us know if you have any more queries.
http://www.aspose.com/docs/display/wordsnet/Loading%2C+Saving+and+Converting