wPDF in a multithreaded application

  • Hello Mr. Ziersch!

    My company recently upgraded from wPDF2 TEAM License to wPDF3 Server License PRO.
    Migrating was easy and with the INTWPSWITCH symbol unset we are compiling wPDF into our Delphi 7 application now instead of using the DLL.

    Ultimately our application is supposed to run as part of a Web-Service where concurrent i.e. multithreaded generation of PDF files (or rather streams) is required.

    What else do we have to take into account to achieve this goal?

    When we talked on the phone about two month ago, you mentioned that it might be necessary to use a mutex or even edit some Delphi library functions. Could you please explain that in detail?

    Thanks in advance,

    Eugen Wittmann
    Condor Lebensversicherungs-AG

    • Offizieller Beitrag

    Hello,

    the VCL is not 100% threadsave when it comes to metafile creation. The resources which are used by the paint routine are used in all threads. Under certain circumstances it is possible that resources are freed.

    So there are two options:

    a) synchronize the painting. Everything which goes to wPDF.Canvas should not be interrupted. Then call wPDF.CloseCanvas.
    After that multitasking is possible again since the wPDF engine is save.

    b) patch the graphics source code to not free the resources. The resources should only be freed while no thread is running. This can be done by a global procedure which is called when there is time.

    I hope this helps,

    Julian Ziersch

  • Ok, I'll use a mutex - locking it before StartPage and releasing after EndPage (where CloseCanvas is called). That should do the trick :wink:

    Thanks!

    Eugen Wittmann
    Condor Lebensversicherungs-AG