The initial situation

The PDF file to be created should have a defined file name which is to be compiled from the values customer number and invoice number (customer ID_invoice number.pdf). In merchandise management, there is unfortunately no way to add print data or similar to a print job (via control characters as is normal). According to the general assessment, waiting for a corresponding extension from the ERP manufacturer is very unrealistic. However, the ERP can provide the desired file name in the Windows clipboard. We take advantage of that.

The solution

Our PDF printer will read the desired file name from the Windows clipboard and take it into account. We use the PDF printer's VBScript framework for this, which can be used immediately after installation. To access the desired PDF file name, we access the Windows clipboard here when the PDF is printed from the ERP and then save it as desired in a PDF file based on the pattern Customer ID_InvoiceNo.pdf.

For this we use the following VBScript macro code:

Function ClipBoard(input)
    If IsNull(input) Then
        ClipBoard = CreateObject("HTMLFile").parentWindow.clipboardData.getData("Text")
    If IsNull(ClipBoard) Then ClipBoard = ""
        CreateObject("WScript.Shell").Run _
        "mshta.exe javascript:eval(""document.parentWindow.clipboardData.setData('text','" _
        & Replace(Replace(Replace(input, "'", "\\u0027"), """","\\u0022"),Chr(13),"\\r\\n") & "');window.close()"")", _
    End If
End Function

Create individual VBS function macro tag

We use the following macro code in the 7-PDF printer configuration.


The screenshot below shows the necessary steps in detail (just click to enlarge). This MacroTag calls the created VBS function "clipboard" (from clipboard.vbs) and the returned value of this function replaces the individual MacroTag entry with the real return value. Since the return value is the file name previously copied to the clipboard, the print dialog then also displays this file name and the PDF to be created can be saved as desired. The example could of course be expanded to include further data from the clipboard (for example including the complete directory path or other data). But this solution is sufficient for the initial situation described above.

The figure below shows the concrete steps:

Steps Clipboad

Sample file download

This macro code is now placed as a VBS file clipboard.vbs in the "Macros" folder of our PDF printer (installation directory of our 7-PDF printer).


Attachment Size
Example file 439 Bytes