swftools-common
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Swftools-common] Word Document to PDF conversion


From: Matthew Richer
Subject: RE: [Swftools-common] Word Document to PDF conversion
Date: Fri, 22 Jan 2010 08:15:11 -0500

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.msoAutomationSecurityForceDisable;

 

            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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]