KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method to Handle Thread Stack Size for Printing
PRODUCT: 4D | VERSION: 21 | PLATFORM: Win
Published On: April 6, 2026
Since Windows 11 versions 24H2—and even more so with 25H2—changes to the Microsoft Print to PDF driver have increased the depth and complexity of system calls during certain PDF generation scenarios. As a result, complex or resource-intensive printing operations may require more stack space than the default 4D thread stack size on Windows (512 KB). This can potentially lead to thread aborts in 4D when using commands such as OPEN PRINTING JOB, PRINT FORM, or when generating multi-page documents.

A maintainable approach is to execute such printing workloads in a dedicated process configured with a larger stack size, typically between 2 MB and 5 MB.

UTIL_LaunchPrintingProcess:

#DECLARE($printingMethod : Text; $stackSizeMB : Real; $data : Object; \
  $processName : Text)

If ($printingMethod="")
   ALERT("Error: printing method name is required.")
   return
End if

If ($stackSizeMB<=0)
   $stackSizeMB:=2
End if

If ($processName="")
   $processName:="Print_"+$printingMethod+"_"+String(Tickcount)
End if

var $stackBytes : Integer
$stackBytes:=Round($stackSizeMB*1024*1024; 0)

var $procID : Integer

If (Count parameters>=3)
   $procID:=New process($printingMethod; $stackBytes; $processName; $data; *)
Else
   $procID:=New process($printingMethod; $stackBytes; $processName; *)
End if

If ($procID<=0)
   ALERT("Unable to create the printing process.")
End if


Example:

UTIL_LaunchPrintingProcess("YourPrintingMethod"; 2)


A stack size of 2 MB is a safe baseline for most printing operations. Increase it to 4–5 MB only when handling complex documents with numerous styles, images, tables, or very long multi-page content. The memory impact remains negligible, as each print process consumes only 2–5 MB of virtual memory.