lua script example header and footer in dicom print

  • I am afraid not. The printer server is coded in Delphi, and has few options.

    Every image can go through printerdisplay.lua though DICOM in, bitmap out.

    Headers and footers are bitmaps:

    var headerbmpname: string = 'print_header.bmp';

    footerbmpname: string = 'print_footer.bmp';

    backgroundbmpname: string = 'print_background.bmp';

    The printer client in 1.5.0 is in lua, embedded in the GUI.


  • Hi Marcel,

    Is there any way to use printing on linux without the graphical interface?

    thanks for help.

  • Hi,

    there are lua plugins for printing but never used.

    Something like:


    printserver = dofile('lua/conquestprint.lua')

    The file recieves the DICOM Data and a variable "command_line" that can be, amongst others:







    The above are all ignored on the Windows printer.

    "createbasicfilmbox" - here you should read the film design from the Data["2010,0010"] and create a page

    "printbasicfilmbox" - here you should print the page

    or the filename of a DICOM file where the image was just stored - here you should add the image to the page

    This should give enough information to write a printer but you need lua libraries to support printing. I think I looked at CD and such. These should be able to create e.g. a PDF, but not sure they can print on Linux.

    But not a trivial task. Would be fun to just log what happens in conquestprint.lua (which you have to write!). Check the source code of the delphi GUI for how to do it.


    Some basic printer code:

  • This is what you get (tested under Windows):



    printserver = dofile('lua/print.lua')



    [CONQUESTSRV2] creatingbasicfilmsession

    [CONQUESTSRV2] createbasicfilmbox

    [CONQUESTSRV2] c:\dicom150beta\data\printer_files\1.2.826.0.1.3680043.2.135.737700.78920011.6.1629390.

    [CONQUESTSRV2] printbasicfilmbox

    On each of these you get the full dicom information sent. The "4.6.0" in the UID is image 0 of 6x4.

    If you print a bunch:

    CONQUESTSRV2] creatingbasicfilmsession

    [CONQUESTSRV2] createbasicfilmbox

    [CONQUESTSRV2] c:\dicom150beta\data\printer_files\1.2.826.0.1.3680043.2.135.737700.78920011.6.1629390.

    [CONQUESTSRV2] c:\dicom150beta\data\printer_files\1.2.826.0.1.3680043.2.135.737700.78920011.6.1629390.

    [CONQUESTSRV2] c:\dicom150beta\data\printer_files\1.2.826.0.1.3680043.2.135.737700.78920011.6.1629390.

    [CONQUESTSRV2] c:\dicom150beta\data\printer_files\1.2.826.0.1.3680043.2.135.737700.78920011.6.1629390.

    [CONQUESTSRV2] c:\dicom150beta\data\printer_files\1.2.826.0.1.3680043.2.135.737700.78920011.6.1629390.

    [CONQUESTSRV2] c:\dicom150beta\data\printer_files\1.2.826.0.1.3680043.2.135.737700.78920011.6.1629390.

    [CONQUESTSRV2] c:\dicom150beta\data\printer_files\1.2.826.0.1.3680043.2.135.737700.78920011.6.1629390.

    [CONQUESTSRV2] printbasicfilmbox

    Thus the lua interface is functional. Next find lua stuff to print!

    Edit: the files are not written, but the conquest API has enough methods to grab the image from the DICOM Data, convert it to e.g. jpeg and write it to disk. The lua example printer reads a jpeg image from disk. In other words, it is feasible to create a printer this way.


  • Couldn't help myself: a very basic printer. Requires libraries cd, cdlua51, cdluaim51, freetype6, im, imlua51, zlib1. I find these extremely hard to find for Linux, though. Look for canvasdraw and IM on sourceforge, precompiled libraries are something like (unverified):

    wget -O iuplibs.tar.gz…9.1_Linux44_64_lib.tar.gz

    wget -O iuplualibs.tar.gz…a51_Linux44_64_lib.tar.gz

    I tested this code on windows (with all these dlls) and it prints pages.

    dicom.ini (defines globals here per association to print more images per page)

    association = local canvas, canvas_w, canvas_h
    printserver = dofile('lua/print.lua')

    print.lua (the actual print server in the server/lua folder)

  • Hi, Marcel.

    As I could understand, with this we can "print to pdf" a given layout when conquest receives images, is that it?

    I have a exportconverters to create pdfs with images when Conquest receives a study, using third party software with some scripting..

    This would be interesting if simplifies the whole process.

  • Hi,

    actually the CD (canvasdraw) package can both print and create PDFs. I have worked some more in the printer code, and it is now prints similar to the GUI. As before it depends on the CD and IM libraries that are public domain.

    This is specific code for the DICOM printer, but similar calls can be made for incoming images.

    These I think are the right libraries for Linux:…44_64_lib.tar.gz/download…44_64_lib.tar.gz/download…44_64_lib.tar.gz/download…44_64_lib.tar.gz/download

    Marcel van Herk is developer of the Conquest DICOM server together with Lambert Zijp.

    Edited once, last by marcelvanherk: Added library paths ().

  • Hi Marcel,

    Thanks for the help, you've already given a way :)

    I can't find some lua files in the repository, could you tell me where to get them?

    these 3 files I didn't find...




    log error

    Server Command := 0150

    Message ID := 0021


    *** lua run error lua/print.lua:2: module 'cdlua' not found:

    no field package.preload['cdlua']

    no file './cdlua.lua'

    no file '/usr/local/share/lua/5.1/cdlua.lua'

    no file '/usr/local/share/lua/5.1/cdlua/init.lua'

    no file '/usr/local/lib/lua/5.1/cdlua.lua'

    no file '/usr/local/lib/lua/5.1/cdlua/init.lua'

    no file '/usr/share/lua/5.1/cdlua.lua'

    no file '/usr/share/lua/5.1/cdlua/init.lua'

    no file './lua/cdlua.lua'

    no file './'

    no file '/usr/local/lib/lua/5.1/'

    no file '/usr/lib/x86_64-linux-gnu/lua/5.1/'

    no file '/usr/lib/lua/5.1/'

    no file '/usr/local/lib/lua/5.1/' in 'dofile('lua/print.lua')'

    UPACS THREAD 0: ENDED AT: Mon Aug 23 17:54:26 2021


  • Unfortunately on Centos 7.x I had several problems with the lua libs, I tried new installation on Ubuntu 16.04 server, just to test, I also had several problems, as a proof of concept I took a windows7 that I use for delphi and put in it, the lua libs operate perfect on windows, i'll keep trying to solve this and as soon as i get it i put here a step by step with the right libs for download :)

    Now I try to put a header and a footer so that the presentation looks nice, I also believe that generating PDF is important, because for testing I don't have a printer at home :)

  • Hi marcelvanherk,

    There are several libs problems with updated versions of Centos and Ubuntu, so far I haven't been able to make it work, while I haven't solved it, I put your last script in lua on windows 7 by downloading the libs for win32 and putting it in the clibs folder, Okay, printing to the default windows printer works perfectly, without using the GUI.

    I have 2 questions:

    1 - how can I save in pdf with the Patient id number "I used exportconverter for this before"

    2 - I liked the idea of header and footer, I tried to insert it and it didn't work, any tips?

    I only save 2 files, print_header.bmp and print_footer.bmp in conquest directory :)

    thanks for help,

    about linux I will inform you as soon as I can solve this libs/compatibility problem.

  • Hi,

    You can create a pdf as canvas, instead of a printer. Similar you can load images with IM and draw them into you canvas as header and footer with a bit of Lua coding. You can best search for canvasdraw and IM documentation.

    Hope you can sort out the linux issue.


  • Hi Marcel,

    Which of these versions are you using?

    I tried several on windows64 bits and I couldn't understand if the error is in the lua version or not.

    in this moment I install these file ->

    I look in your file readme.txt, but im file name not found :)


    Place lua external libraries here such as IUP and CD for use within the DICOM server.

    Only work correctly with a dgate.exe that uses an external lua5.1.dll (64 bits for now)

    iuplua51.dll and iup.dll are required to run console.wlua and notepad.wlua

    For 64 bits windows use:

    iup, iuplua51, socket/core as provided

    For 32 bits windows use:

    socket/core.dll not required (built-in)


    I talked to one of the maintainers of the package, Antonio Sucuri , he gave me some tips, but the errors in the libs are not very clear where I am going wrong.





    require"cdpdf" <-- even being in the correct directory causes an error :(

    [CONQUESTPRINT01] UPACS THREAD 3: STARTED AT: Fri Sep 17 11:34:36 2021


    [CONQUESTPRINT01] Calling Application Title : "TestPrint"

    [CONQUESTPRINT01] Called Application Title : "CONQUESTPRINT01"

    [CONQUESTPRINT01] Application Context : "1.2.840.10008.", PDU length: 16384

    [CONQUESTPRINT01] Number of Proposed Presentation Contexts: 1

    [CONQUESTPRINT01] Presentation Context 0 "1.2.840.10008." 1

    [CONQUESTPRINT01] Server Command := 0110

    [CONQUESTPRINT01] Message ID := 0003

    [CONQUESTPRINT01] gettingprinter

    [CONQUESTPRINT01] *** lua run error error loading module 'cdpdf' from file 'D:\PACS\Prototipo_Lua\clibs\cdpdf.dll': Não foi possível encontrar o procedimento especificado. in 'dofile('lua/print.lua')'

    [CONQUESTPRINT01] Server Command := 0140

    [CONQUESTPRINT01] Message ID := 0005

    [CONQUESTPRINT01] creatingbasicfilmsession

    [CONQUESTPRINT01] *** lua run error error loading module 'cdpdf' from file 'D:\PACS\Prototipo_Lua\clibs\cdpdf.dll': Não foi possível encontrar o procedimento especificado. in 'dofile('lua/print.lua')'

    [CONQUESTPRINT01] Server Command := 0140

    [CONQUESTPRINT01] Message ID := 0007

    [CONQUESTPRINT01] createbasicfilmbox

    [CONQUESTPRINT01] *** lua run error error loading module 'cdpdf' from file 'D:\PACS\Prototipo_Lua\clibs\cdpdf.dll': Não foi possível encontrar o procedimento especificado. in 'dofile('lua/print.lua')'

    [CONQUESTPRINT01] Server Command := 0120

    [CONQUESTPRINT01] Message ID := 0009

    [CONQUESTPRINT01] D:\PACS\Prototipo_Lua\Data\printer_files\1.2.826.0.1.3680043.2.135.738028.60948977.6.1631889.

    [CONQUESTPRINT01] *** lua run error error loading module 'cdpdf' from file 'D:\PACS\Prototipo_Lua\clibs\cdpdf.dll': Não foi possível encontrar o procedimento especificado. in 'dofile('lua/print.lua')'

    [CONQUESTPRINT01] Server Command := 0130

    [CONQUESTPRINT01] Message ID := 000b

    [CONQUESTPRINT01] printbasicfilmbox

    [CONQUESTPRINT01] *** lua run error error loading module 'cdpdf' from file 'D:\PACS\Prototipo_Lua\clibs\cdpdf.dll': Não foi possível encontrar o procedimento especificado. in 'dofile('lua/print.lua')'

    [CONQUESTPRINT01] Server Command := 0150

    [CONQUESTPRINT01] Message ID := 000d

    [CONQUESTPRINT01] deletebasicfilmbox

    [CONQUESTPRINT01] *** lua run error error loading module 'cdpdf' from file 'D:\PACS\Prototipo_Lua\clibs\cdpdf.dll': Não foi possível encontrar o procedimento especificado. in 'dofile('lua/print.lua')'

    [CONQUESTPRINT01] UPACS THREAD 3: ENDED AT: Fri Sep 17 11:34:36 2021


    Não foi possível encontrar o procedimento especificado -> Could not find the specified procedure

    Do you have any idea what it might be?

    On linux it's even worse, the libs are conflicting, i downloaded the source based on the versions you recommended for windows and i'm compiling now on Centos7 i'll inform you as soon as i have some good news :)

  • On linux, a first step is to get to work. That uses just a few lua libraries.

    I assume you tried this:

    mkdir iup

    wget -O iuplibs.tar.gz…9.1_Linux44_64_lib.tar.gz

    wget -O iuplualibs.tar.gz…a51_Linux44_64_lib.tar.gz

    cd iup

    tar xvf ../iuplibs.tar.gz

    tar xvf ../iuplualibs.tar.gz

    sudo ./install

    ((export LUA_CPATH=./\?.so\;./lib\?.so\;./lib\?\;))


  • Hi,

    cdpdf is likely dependant on other modules, in particular pdflib.dll, cd.dll, cdpdf.dll, and msvcr80.dll. Are these all there?


    Hi again :)

    Yes, all files is here... I download from

    I try to use "regsvr32 /i msvcr80.dll" but no resolv the fail too :(

    my test is windows10 pro version.

  • Hi,

    you can just put msvcr80.dll next to the lua DLLs, if that is the DLL you are mssing. Of course you need the 64 bit version.

    I use (very old ones):


    You cannot mix versions!


  • Hi Marcel,

    now using

    On windows 10 works "print to default printer and print to pdf, without GUI :)", however the image comes out cropped right, I tried to adjust but I couldn't, I'm looking at the GUI code to see why it looks perfect "without Lua printing".

    would it be possible to put the PatientID in the name of the PDF file? I try to use export... did not work, I don't know how to pass the patient's information through the print...






    if command_line=='createbasicfilmbox' then

    --canvas = cd.CreateCanvas(cd.PRINTER, "test5")

    --canvas = cd.CreateCanvas(cd.PDF, "cd_pdf.pdf -w210 -h297 -s120")

    -- PatientID

    canvas = cd.CreateCanvas(cd.PDF, "saida\\cd_pdf.pdf -w210 -h297 -s120")

    canvas_w, canvas_h = canvas:GetSize()

    print(canvas_w, canvas_h)


    if string.find(command_line, '%.dcm') then

    local c = (Data.WindowCenter or 0) if c=='' then c=0 end

    local w = (Data.WindowWidth or 0) if w=='' then w=0 end

    local s = (Data.RescaleSlope or 1) if s=='' then s=1 end

    local i = (Data.RescaleIntercept or 0) if i=='' then i=0 end

    if string.find(c, '%\\') then

    c = string.match(c, '(.-)\\')


    if string.find(w, '%\\') then

    w = string.match(w, '(.-)\\')


    w = tonumber(w)/tonumber(s)

    c = tonumber(c)/tonumber(s)

    local vr = Data:GetVR(0x2020, 0x0110)

    vr[0]:Script('save jpg level '..math.floor(c)..' window '..(math.ceil(w/2)) .. ' to x.jpg')

    local image = im.FileImageLoad('x.jpg')

    local iw = image:Width()

    local ih = image:Height()

    local rows, cols, num = command_line:match('.*%.(.-)%.(.-)%.(.-)%.(.-)$')

    rows = tonumber(rows)

    cols = tonumber(cols)

    num = tonumber(num)

    local margin=100

    local row = num % rows

    local col = math.floor(num/rows)

    local sizex = (canvas_w-2*margin)/rows

    local sizey = (canvas_h-2*margin)/cols

    local posx = margin + row*sizex

    local posy = (canvas_h-sizey) - (margin + col*sizey)

    if iw>ih then sizey = sizex*ih/iw

    else sizex = sizey*iw/ih end

    image:cdCanvasPutImageRect(canvas, posx, posy, sizex, sizey, 0,0,0,0)

    canvas:Text(posx, posy-40, num)


    if command_line=='printbasicfilmbox' then

    --print("OEF -> final... ")



    I've already managed to solve part of the problem in Centos7, when I solve the libs post here the solution to install.

    thanks for help :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!