The examples here were kindly provided by one of our forum members.
Instant ASP
JScript ASP page implementing Word to PDF using the COM interface:
[Jscript]
<%@ LANGUAGE = "jscript" %>
<html>
<body>
<%
var baseFile = "C:\\Inetpub\\wwwroot\\WordSamples\\test3";
/* ============ Open Word & Save to Aspose.Pdf XML ============ */
var lic = Server.CreateObject("Aspose.Words.License");
lic.SetLicense("C:\\Inetpub\\wwwroot\\WordSamples\\Aspose.Custom.lic");
var helper = Server.CreateObject("Aspose.Words.ComHelper");
var doc = helper.Open(baseFile + ".doc");
doc.Save_2(baseFile + ".xml", 3);
doc = null;
helper = null;
lic = null;
/* ===================== Convert to PDF ===================== */
var lic = Server.CreateObject("Aspose.Pdf.License");
lic.SetLicense("C:\\Inetpub\\wwwroot\\WordSamples\\Aspose.Custom.lic");
var pdf = Server.CreateObject("Aspose.Pdf.Pdf");
pdf.BindXML_2(baseFile + ".xml",null);
pdf.isImagesInXmlDeleteNeeded = true;
// OPTIONAL: Set PDF custom properties
// ===================================
pdf.author = "Demo User";
pdf.creator = "Demo System";
pdf.keywords = "Hot Document";
pdf.subject = "Report on Things";
pdf.title = "Customer #123";
// OPTIONAL: Set PDF document security
// ===================================
var sec = Server.CreateObject("Aspose.Pdf.Security");
sec.isContentsModifyingAllowed = false;
pdf.security = sec;
sec = null;
pdf.Save(baseFile + ".pdf");
pdf = null;
lic = null;
/* ===================== Remove Interim XML File ===================== */
var fs = Server.CreateObject("Scripting.FileSystemObject");
fs.DeleteFile(baseFile + ".xml");
fs = null;
%>
</body>
</html>
Instant ASP.NET
Works easiest in ASP.NET v2.0 -- Copy Aspose.Words.dll & Aspose.Pdf.dll into a directory named "Bin" in your website directory. Then create your .aspx page and copy the following into it (update the variables at the top as needed - understand our example assumes a base filename and we play with the extensions from there - .doc .xml .pdf).
[ASP.NET]
<%@ Page Language="C#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Aspose.Words" %>
<%@ Import Namespace="Aspose.Pdf" %>
<%
string file = "c:\\inetpub\\wwwroot\\wordsamples\\mtest3";
string lic = "c:\\inetpub\\wwwroot\\wordsamples\\Aspose.Custom.lic";
// ===================================
// Set Controls Licensing
// ===================================
Aspose.Words.License license_w = new Aspose.Words.License();
license_w.SetLicense(lic);
Aspose.Pdf.License license_p = new Aspose.Pdf.License();
license_p.SetLicense(lic);
// ===================================
// Load Word Doc
// ===================================
Document doc = new Document(file + ".doc");
// ===================================
// MailMerge Data Fields
// ===================================
// *** MANUAL METHOD
//string[] fieldNames = {"Company", "EndNumber", "PolicyNumber", "EffectiveDate", "DateIssued", "CounterSignedDate"};
//object[] fieldValues = {"ABC Corporation of America", "3", "NAC12345", "10/31/2006", "10/28/2006", "10/30/2006"};
//doc.MailMerge.Execute(fieldNames, fieldValues);
// *** XML FILE METHOD
DataSet ds = new DataSet();
System.IO.FileStream fsReadXml = new System.IO.FileStream(file + "_data.xml", System.IO.FileMode.Open);
System.Xml.XmlTextReader myXmlReader = new System.Xml.XmlTextReader(fsReadXml);
ds.ReadXml(myXmlReader);
myXmlReader.Close();
doc.MailMerge.Execute(ds.Tables["header"]);
// ===================================
// Convert Word to PDF
// ===================================
doc.Save(file + ".xml", SaveFormat.AsposePdf);
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.IsImagesInXmlDeleteNeeded = true;
// ===================================
// OPTIONAL: Set PDF custom properties
// ===================================
pdf.Author = "Demo User";
pdf.Creator = "Demo System";
pdf.Keywords = "Hot Document";
pdf.Subject = "Report of Things";
pdf.Title = "Customer #123";
// ===================================
// OPTIONAL: Set PDF document security
// ===================================
Aspose.Pdf.Security sec = new Aspose.Pdf.Security();
sec.IsContentsModifyingAllowed = false;
pdf.Security = sec;
pdf.BindXML(file + ".xml", null);
pdf.Save(file + ".pdf");
// ===================================
// Cleanup
// ===================================
File.Delete(file + ".xml");
%>