|
-
Jul 17th, 2017, 06:15 AM
#1
Thread Starter
Fanatic Member
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.
-
Jul 17th, 2017, 06:29 AM
#2
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?
-
Jul 17th, 2017, 08:32 AM
#3
Thread Starter
Fanatic Member
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.
-
Jul 17th, 2017, 09:40 AM
#4
Re: Converting files to PDF
-
Jul 18th, 2017, 03:25 AM
#5
Thread Starter
Fanatic Member
Re: Converting files to PDF
Thanks, Chris - that looks very interesting. I'll see what I can do with it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|