Results 1 to 5 of 5

Thread: Converting files to PDF

  1. #1

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819

    Converting files to PDF

    I seem to recall asking this before but can't find it....

    We have an old application that runs as a scheduled task on an very old server. A major part of its job is converting files into PDFs, and it does this by using the MS Office object model. Essentially, it uses the relevant application to open the file (".DOC", ".TXT", ".HTM", ".HTML", ".RTF", ".MHT", ".MHTML" files are opened in Word, ".XLS", ".CSV" in Excel), and then uses that to print them into a PDF file. Very basic, but it works well (please ignore the naming conventions!).

    Code:
                    Select Case UCase(mFileExt)
                        Case ".DOC", ".TXT", ".HTM", ".HTML", ".RTF", ".MHT", ".MHTML"
                            Dim oWordApp As Word.Application
                            Dim oDocument As Word.Document
    
                            oWordApp = CreateObject("Word.Application")
                            oWordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
                            oWordApp.Visible = False
                            oWordApp.Application.WindowState = Word.WdWindowState.wdWindowStateMinimize
                            oDocument = CreateObject("Word.Document")
                            oDocument = oWordApp.Documents.Open(mTempFilePath, PasswordDocument:=mPassword, ReadOnly:=True)
    
                            Dim holdprtrdefault As String = oWordApp.ActivePrinter
                            oWordApp.ActivePrinter = "Adobe PDF"
                            oWordApp.Application.PrintOut(FileName:=mTempFilePath, _
                                Copies:=1, _
                                Range:=Word.WdPrintOutRange.wdPrintAllDocument, _
                                Item:=Word.WdPrintOutItem.wdPrintDocumentContent, _
                                Pages:="", _
                                PageType:=Word.WdPrintOutPages.wdPrintAllPages, _
                                Collate:=True, _
                                Background:=False, _
                                PrintToFile:=True, _
                                OutputFileName:=mPSFilePath)
    
                            oWordApp.ActivePrinter = holdprtrdefault
                            oWordApp.Application.Quit(Word.WdSaveOptions.wdDoNotSaveChanges)
                            oWordApp = Nothing
                            oDocument = Nothing
                        Case ".XLS", ".CSV"
                            Dim oXLApp As Excel.Application
                            Dim oWkBook As Excel.Workbook
                            oXLApp = CreateObject("Excel.Application")
    
                            oXLApp.DisplayAlerts = False
                            oXLApp.Visible = False
                            oXLApp.Application.WindowState = Excel.XlWindowState.xlMinimized
                            oWkBook = oXLApp.Workbooks.Open(mTempFilePath, Password:=Trim(mPassword), ReadOnly:=True, UpdateLinks:=False, Converter:=True, IgnoreReadOnlyRecommended:=True)
    
                            Dim holdprtrdefault As String = oXLApp.ActivePrinter
                            Dim nSheets As Integer = oWkBook.Worksheets.Count
    
                            oWkBook.PrintOut(1, nSheets, 1, ActivePrinter:="Adobe PDF", PrintToFile:=True, Collate:=True, PrToFileName:=mPSFilePath)
                            oXLApp.ActivePrinter = holdprtrdefault
                            oXLApp.Application.Quit()
                            oXLApp = Nothing
                            oWkBook = Nothing
    
                        Case ".MDI"
                            Dim oDIApp As MODI.Document = New MODI.Document
    
                            oDIApp.Create(mTempFilePath)
                            oDIApp.PrintOut(PrinterName:="Adobe PDF", PrintToFileName:=mPSFilePath, FitMode:=MODI.MiPRINT_FITMODES.miPRINT_ACTUALSIZE)
                            oDIApp.Close()
                            oDIApp = Nothing
    
                        Case Else
                            mIsPDF = False
                            mConvToPDF = False
                            mLogMsg = "Invalid File Format"
                            mLogType = MergeLogType.Failure
                            WriteLog(" - Invalid File Format", False)
                            Exit Sub
    
                    End Select
    However, we now want to move this application to a new server and would like to avoid having to install Office on that new server. This means we need an alternative way of converting all of these files into PDFs. Unfortunately buying new software is out of the question, because getting approval for anything not in our current development stack is a looooooooooooooooong process in this place. Even freeware could be a problem, although I'd be willing to look into it.

    Anyone have any suggestions? I've googled quite a bit and haven't found anything suitable.
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,747

    Re: Converting files to PDF

    So it's not only about creating PDF, but also for parsing all kind of document formats.

    Just a silly question, if the current solution works and you don't have any budget then why are you looking for an alternative?

  3. #3

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819

    Re: Converting files to PDF

    It's not the budget so much as the length of time it takes to get anything approved.

    The problem is that the new servers are Windows Server 2012, and Microsoft strongly recommend not installing Office on them:

    https://support.microsoft.com/en-us/...tion-of-office

    Because of this, our infrastructure team (who handle installations) are digging their heels in a bit about installing it.


    The reason for all of those formats being in there is that you can use Word to convert any of them into PDFs.
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  4. #4
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,130

    Re: Converting files to PDF

    Hi,

    take a look at PDfCreator
    http://https://sourceforge.net/projects/pdfcreator/

    regards
    Chris

  5. #5

    Thread Starter
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819

    Re: Converting files to PDF

    Thanks, Chris - that looks very interesting. I'll see what I can do with it.
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width