The Print class
cs.bspkComponent.Print prints your application's 4D forms, to a printer or as a PDF, with page headers repeated on every page, a footer pushed to the bottom of the page, pagination, and objects that grow with their content.
An example
$vo_Param:={vt_Mode: "pdf"; vt_TypeFile: "pdf"; vb_Erase: True; vb_Preview: False}
$vo_Param.vt_PathFolder:=Folder(Data folder; *).folder("temporary files").platformPath // ends with a separator
$vo_Param.vt_Filename:="Order_"+$vt_Number
$Print:=cs.bspkComponent.Print.new($vo_Param) // opens the printing job
If ($vo_Param.vb_OK_Print)
vo_Form:=New object // YOUR application's process variable, read by the form
vo_Form.vt_Number:=$vt_Number
$Print.printForm("OrderPrint"; Form header)
$Print.printForm("OrderPrint"; Form header1; "H2_ovt_Supplier") // the object grows with its text
// from here on, these markers are reprinted at the top of every new page
$Print.vc_ConstantMarkerHeader:=New collection(Form header4; Form header5)
$Print.vb_HeaderPage:=True
$vc_Bloc:=[{vt_FormName: "OrderPrint"; vl_ConstantMarker: Form detail; vl_NumberMarker: 1}; \
{vt_FormName: "OrderPrint"; vl_ConstantMarker: Form break0; vl_NumberMarker: 1}]
For each ($Line; $Order.Lines)
vo_Form.vt_Designation:=$Line.designation
If (Not($Print.canPrintBloc($vc_Bloc; True; 0))) // the line and the closing break no longer fit
$Print.printForm("OrderPrint"; Form break0)
$Print.nextPage(False; "OrderPrint") // prints the footer, new page
End if
$Print.printForm("OrderPrint"; Form detail; "Body_ovt_Designation")
End for each
$Print.printForm("OrderPrint"; Form break0)
$Print.printForm("OrderPrint"; Form footer)
$Print.endPrint()
End if
return $Print.vt_PathFile
Three rules:
- always
new()first (it opens the printing job) andendPrint()at the end; - the form method of a printed form is
BSPK_EXEC_FC; - every printed form keeps its last two markers 1 pixel apart.
Constructor parameters
| Property | Default | Role |
|---|---|---|
vt_Mode | "print" | "print" (printer), "pdf" (file), "file" (PDF sent to the browser, in a web request) |
vt_PathFolder | — | The file's folder, ending with a separator. Empty: a folder dialog opens. Created if missing. |
vt_Filename, vt_TypeFile | "Print", "pdf" | The file name, without extension, and the extension. |
vb_Erase | False | False: an existing file is kept and the new one gets a (n) suffix. |
vb_Preview | True | In "pdf" mode, opens the PDF at the end. |
vl_Orientation | 1 | Page orientation. |
vb_NeedPrintSetting | true in "print" mode | Shows the print settings dialogs. |
vc_ConstantMarkerHeader | [] | The markers reprinted at the top of every page (or a single one: vl_ConstantMarkerHeader). |
vb_FooterEndPage | True | Pushes the footer to the bottom of the page. |
vt_Lang | — | The translation language during the print. |
vt_Printer, vl_NumberCopy, vl_Scale, vl_PaperWidth / vl_PaperHeight, vl_DoubleSided, vl_RangeStart / vl_RangeEnd | — | Passed to 4D's print options. |
There is no margin setting: margins are set to zero.
Functions
| Function | Role |
|---|---|
printForm($form; $marker; $growingObject; $endOfPage) | Prints one area of the form. If it no longer fits, prints the footer and moves to the next page; prints the page header when needed. $growingObject: the object(s) (separated by ;) to grow with their content, whose bottom sits on the marker. |
canPrintBloc($areas; $withFooter; $margin) → Boolean | Does this group of areas still fit on the page? |
nextPage($withoutFooter; $form) | Ends the page (with or without footer). |
endPrint() | Closes the print, opens the PDF or sends it to the browser. Returns nothing. |
The produced file is in $Print.vt_PathFile. To mail it: $Mail.addAttachements($Print.vt_PathFile; "Order.pdf") (see The Mail class).
The component prints your forms through your project's BSPH_Print_Form method: do not delete it.
Depending on the platform
- On Windows, the PDF goes through the Generic PDF driver if installed, otherwise through Microsoft Print to PDF. The current printer is not restored after printing.
- On macOS, through 4D's PDF output.
- On 4D Server, avoid modes that open dialogs (folder choice, print settings).
Good to know
- With
vb_Preview, the component already opens the PDF: do not open it a second time. - If the folder choice is cancelled, no file path is set.
vo_Formis a process variable of your application: initialise it afternew().

