Hi Matt,
We use Office 2007 to do the automation server side. Technically Microsoft
frowns upon it, but it works. Office 2007 has a "Save As PDF" plugin (or it
included in Service Pack 2). Here go (if the list smashes my code indenting
you can email me directly and I'll send it over (FYI Office's API is not all
that great but it gets the job done):
protected Boolean Word2PDF(String wordFile, String pdfFile)
{
Object fileName = (Object)wordFile;
Object f = false;
Object t = true;
Object missing = System.Type.Missing;
Object frmt = Word.WdOpenFormat.wdOpenFormatAuto;
Boolean result = false;
Exception e = null;
Word.Application wApp = null;
Word.Document wDoc = null;
try
{
wApp = new Word.Application();
wApp.AutomationSecurity =
Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisabl
e;
wDoc = wApp.Documents.Open(ref fileName, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing);
fileName = (Object)pdfFile;
frmt = Word.WdSaveFormat.wdFormatPDF;
wDoc.SaveAs(ref fileName, ref frmt, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing);
wDoc.Close(ref f, ref missing, ref missing);
wApp.Quit(ref f, ref missing, ref missing);
result = true;
}
catch (Exception ex)
{
if (wDoc != null)
wDoc.Close(ref f, ref missing, ref missing);
if (wApp != null)
wApp.Quit(ref f, ref missing, ref missing);
e = ex;
}
finally
{
wDoc = null;
wApp = null;
}
if (e != null)
throw e;
return result;
}
Matt
>>>>
Hello,
Does anyone know of a good way to convert Word documents (either .DOC or
.DOCX) to PDF documents? It should be able to function via the command line
or programatically/API. It doesn't have to be free, but it does need to make
high quality PDFs.
More info: we'd be doing this ASP.NET. As such, I've briefly looked into
using the Microsoft Word API to do the conversion programatically (i.e. open
the DOC and save as a PDF), but haven't gotten very far yet.
Thanks,
Matt
--
Matt Long
Lead Developer
650-963-942
webnotes.net