Error with merging pdf files on terminal server


#1

Hi

I use the following code:


Dim outPath$
Dim folder As String
Dim PDFfilename As String

folder = "N:\Styringssystem\Database UDVIKLING\"    'CHANGE AS REQUIRED
If Right(folder, 1) <> "" Then folder = folder & ""
   
PDFfilename = Dir(folder & "*.pdf", vbNormal)
outPath = "n:\styringssystem\database udvikling\outputFile.pdf"

Dim oPDF As PDFCreator_COM.PdfCreatorObj
Set oPDF = New PDFCreator_COM.PdfCreatorObj

While Len(PDFfilename) <> 0
    filnavn = folder & PDFfilename
    oPDF.AddFileToQueue filnavn
    PDFfilename = Dir()  ' Get next matching file'
Wend

When I use it on a stand alone machine with the free version it works fine - when I use it on the terminal server I get a error on this line: oPDF.AddFileToQueue filnavn

The error is a run time error -2147024809 (80070057) with the message "Der må ikke bruges tomme stinavne". Translated from Danish: "You are not allowed to use empty path names"

When I check the log file, I can see this error:

2018-11-03 22:30:07.1262 [Error] pdfforge.PDFCreator.Core.DirectConversion.DirectConversionInfFileHelper.TransformToInfFileWithMerge: Error while coping ps-file in spool folder:
Typeinitialiseringsfunktionen for 'PdfTools.Pdf.Internal.NativeBase' udløste en undtagelse.

Any suggestions?

Kasper


#2

Hi,

sorry for the trouble.
We will need to look into this.
The paid PDFCreator editions use some third party libraries from pdftools, which aren't included in the free version; this is probably the reason why the freeware doesn't have this issue.
A possible workaround might be to use the /merge command line parameter instead of the COM interface, as this uses a different workflow internally:
http://docs.pdfforge.org/pdfcreator/3.3/en/pdfcreator/using-pdfcreator/command-line-parameters/

Best regards

Robin


#3

Hi Robin

Thanks for answer.

Do I understand you correct if you mean this should work?

Dim stAppName As String
stAppName = "C:\Program Files\PDFCreator\pdfcreator.exe"
Call Shell("stAppName /OutputFile=n:\test.pdf" /Merge=n:\file_a.pdf /Merge=n:\file_b.pdf", 1)

I can't make it work.. :frowning:

Kasper


#4

Hi Kasper,

it should work if you change the third line to
Call Shell("stAppName /OutputFile=n:\test.pdf" /Merge=n:\file_a.pdf n:\file_b.pdf", 1)
I just realized the example in the docs is incomplete and we will update it accordingly.

Best regards

Robin


#5

Sorry Robin

I can't make it work...

I need a functionality where I from VBA code can merge several pdf-files to one pdf. I has to work in the background without starting pdfcreator with prompts for user input.

Can pdfcreator give mig a code which works with COM on a terminal server or a command line which can do the trick - or can you recommed something else?

Thank you in advance :smile:

Kasper


#6

Hi,

what went wrong? Did you get a prompt for the output location even though you specified the OutputFile parameter, or which prompt(s) did you get? We have in the past seen a few cases i which VBA doesn't play along nicely with COM, does the JS merge example in "PDFCreator\COM Scripts\JS Scripts\How To" work?
We will look into the COM issue and see if we can find the cause of it.

Best regards

Robin


#7

Hi Robin

Any solution to the COM issue?

Regards

Kasper


#8

Hi Kasper,

I tried to reproduce the issue with the merge sample from PDFCreator\COM Scripts\Word - VBA\Testpage2PDF.docm but it didn't have any issues.
Probably the issue is restricted to direct PDF input, if you print the PDFs to the queue and merge them afterwards it should work, does the seem like a suitable work around? Sumatra PDF can print PDFs to a dedicated printer in the background via command line, if your currently installed reader doesn't support this.

Best regards

Robin


#9

I now also tried merging PDFs directly, it worked without an error.
Does this modified sample work for you?

Sub MergedMultipleFiles()
Dim PDFCreatorQueue As Variant
Dim printJob As Variant
Dim oPDF As Variant

Set oPDF = CreateObject("PDFCreator.PDFCreatorObj")
Set PDFCreatorQueue = CreateObject("PDFCreator.JobQueue")

If Not oPDF.IsInstanceRunning Then
    MsgBox "Initializing PDFCreator queue..."
    PDFCreatorQueue.Initialize
End If

'change path to some existing test files
oPDF.AddFileToQueue "D:\temp\test.pdf"
oPDF.AddFileToQueue "D:\temp\test2.pdf"
'Set printer if necessary
Application.ActivePrinter = "PDFCreator"

MsgBox "Waiting for the 2 jobs to arrive at the queue for 15 seconds..."
If Not PDFCreatorQueue.WaitForJobs(2, 15) Then
    MsgBox "The print job did not reach the queue within " & " 15 seconds"
Else
    MsgBox "Currently there are " & PDFCreatorQueue.Count & " job(s) in the queue"
    
    MsgBox "Merging all available jobs now"
    PDFCreatorQueue.MergeAllJobs
    
    MsgBox "Now there are " & PDFCreatorQueue.Count & " job(s) in the queue"
    MsgBox "Getting job instance"
    Set printJob = PDFCreatorQueue.NextJob
    
    printJob.SetProfileByGuid ("DefaultGuid")
    
    'change output path as required
    printJob.ConvertTo ("D:\temp\output.pdf")
    
    If (Not printJob.IsFinished Or Not printJob.IsSuccessful) Then
        MsgBox "Could not convert the file: " & fullPath
    Else
        MsgBox "Job finished successfully"
    End If
End If

MsgBox "Releasing the object"
PDFCreatorQueue.ReleaseCom
End Sub