BUG: ConvertTo() duplicates pages

I use the following code for years and worked well. Since 6.0.0 there's some problems. Please see the example code, because it's easier to understand what I want to report.

  1. ConvertTo(path) will duplicate pages (or append the file itself).
  2. Calling ConvertTo() with a non-existing path the new file won't be created.
Public Function EncryptPdf(ByVal pdfFullPath As String, ByVal pwd As String, Optional ByVal titleStr As String, Optional ByVal subjectStr As String) As String
Dim pdfCreatorQueue As Object
Set pdfCreatorQueue = CreateObject("PDFCreator.JobQueue")
Dim creator As Object
Set creator = CreateObject("PDFCreator.PDFCreatorObj")
Dim printJob As Object

If Not creator.IsInstanceRunning() Then
    pdfCreatorQueue.Initialize
End If

creator.AddFileToQueue pdfFullPath
Set printJob = pdfCreatorQueue.NextJob
With printJob
    .SetProfileSetting "TitleTemplate", titleStr
    .SetProfileSetting "SubjectTemplate", subjectStr
    
    .SetProfileSetting "PdfSettings.Security.Enabled", "true"
    .SetProfileSetting "PdfSettings.Security.EncryptionLevel", "Aes256Bit"
    .SetProfileSetting "PdfSettings.Security.RequireUserPassword", "true"
    .SetProfileSetting "PdfSettings.Security.UserPassword", pwd
    
    .SetProfileSetting "PdfSettings.Security.OwnerPassword", "verysecurepassword123456"
    .SetProfileSetting "PdfSettings.Security.AllowToEditTheDocument", "False"
    
    'This will duplicate the pages. For example, a 3-page PDF will have 6 pages.
    .ConvertTo pdfFullPath
    'Giving a new path will be ignored, the file won't be created. Instead the pdfFullPath will be modified.
    '.ConvertTo "c:\newpdf.pdf"
    
    EncryptPdf = .GetOutputFiles.GetFileName(0)
End With

Cleanup:
    pdfCreatorQueue.ReleaseCom
    Set printJob = Nothing
    Set pdfCreatorQueue = Nothing
    Set creator = Nothing
End Function

Hi,

thank you for bringing this to our attention and sorry for any trouble this might have caused.
I can confirm there is a bug when using the com interface which causes PDFCreator to always append instead of overwriting existing PDFs. We will look into this and try to fix it in an upcoming update.
I was however not able to reporduce the other part of the issue, converting to a non existing path works without issues here using the basic js example scripts from the PDFCreator application folder. Do you still get this issue in PDFCreator 6.2.1 and if yes, do you get any error message when the file isn't created?

Best regards

Robin

Thank you for your reply. I tried both 6.1.0 and 6.2.1, and the new encrypted file was never created (the parameter of .ConvertTo). Instead of creating a new file, the original file was modified and password‑protected without appending. There were no error messages, and I do have write access to the folder where I want to save the file.

Thanks for the additional feedback. I only did a quick test without encryption, will have another look with encryption enabled to check if we can reproduce this on our end.

Edit: I ran the following script without running into the described issue:

if (WScript.Version < 5.6) {
    WScript.Echo("You need the \"Windows Scripting Host version 5.6\" or greater!");
    WScript.Quit();
}

try {
    var PDFCreatorQueue = new ActiveXObject("PDFCreator.JobQueue");
    var PDFCreator = new ActiveXObject("PDFCreator.PDFCreatorObj");

   
    PDFCreatorQueue.Initialize();   
    PDFCreator.AddFileToQueue("C:\\temp\\test.pdf");
    
    if (!PDFCreatorQueue.WaitForJob(10)) {
        WScript.Echo("The print job did not reach the queue within " + 10 + " seconds");
    }
    else {       
        var job = PDFCreatorQueue.NextJob;
       
        job.SetProfileSetting("PdfSettings.Security.EncryptionLevel", "Aes256Bit");       
        job.SetProfileSetting("PdfSettings.Security.OwnerPassword", "myOwnerPassword");
        job.SetProfileSetting("PdfSettings.Security.RequireUserPassword", "true");  
        job.SetProfileSetting("PdfSettings.Security.UserPassword", "myPassword");
 	job.SetProfileSetting("PdfSettings.Security.AllowToEditTheDocument", "false");
        job.ConvertTo("C:\\temp\\new.pdf");

        if (!job.IsFinished || !job.IsSuccessful) {
            WScript.Echo("Could not convert the file: " + fullPath);
        }
        else {
            WScript.Echo("Job finished successfully");
        }
    }
    WScript.Echo("Releasing the object");
    PDFCreatorQueue.ReleaseCom();
}
catch (e) {
    WScript.Echo(e.message);
    PDFCreatorQueue.ReleaseCom();
}

Does this sample .js code work as expected on your end?

Best regards

Robin

I tried your js code with v6.1.0 and v6.2.1 as well. The same goes for both: the new file is created, but not encrypted. I tried the same file name, but still not encrypted (but the content is duplicated).

Thank you for the feedback and my apologies; while simplifying the COM example, I forgot to copy over 1 critical line of code: job.SetProfileSetting("PdfSettings.Security.Enabled", "true"); . After adding this, files are encrypted and created / appended as expected. If no file exists in the specified path, a new encrypted PDF gets created. Otherwise the content is appended and encryption added to the entire PDF. You can also change the setting to overwrite instead of append, if this is what you would like to do.

Thank you. It looks like works in js, and after porting your code to vba, it worked as well. I haven't used this approach in the past, because WaitForJob(seconds) always did wait seconds no matter what, it wasn't practical. Now it looks like works as expected. But my example code still works as I mentioned in my first post.
I searched the docs, but I couldn't find how to overwrite instead of append. Can you help me with this as well?
I'm going to try the new ported code extensively.

Currently the settings for chosing between overwriting and appending aren't respected when using the COM interface, we will fix this on our end with the next update. For now, you would need to check per code if a file exists in the output path and delete it if you need the overwirte behaviour.