Use 4D Write Pro to Create & Print a Batch of Documents

Automatically translated from English

Whatever your business, you must create listings, inventories, tracking sheets, product sheets, invoices, and many other documents. These documents are usually printed or saved in PDF for archiving.

4D Write Pro is the ideal tool to create all your documents. Here is a list of several features available in 4D Write Pro that can help you make beautiful documents for printing:

 

Using these different features, here are some examples of documents produced.

a simple list like an inventory

To print a list of records, developers usually use the list form. The disadvantage of this form is that it does not benefit from the power of ORDA.

With 4D Write Pro, you can print the result of an ORDA query using a document template. This has become very easy to do, thanks to the data context.

In this example, we want to print the list of vehicles belonging to a rental agency. Thus, an Agency entity is passed as data context. Then the “cars” relation attribute from the Agency table to the Car table is defined as the table’s data source.

For example, to generate the PDF document from an entity selected by the customer, it is enough to write:

// $context: Entity selected by customer
var $context : cs.AgencyEntity
$context:=ds.Agency.query("ID = 1").first()

// Load write pro model
$doc:=WP Import document(File("/RESOURCES/wpModel/Inventory.4wp").platformPath)
// Defines the entity as the data context of the document
WP SET DATA CONTEXT($doc; $context)
// Generate the document
WP COMPUTE FORMULAS($doc)
// Export in PDF
WP EXPORT DOCUMENT($doc; Folder(fk documents folder).file("Inventory.pdf").platformPath; wk pdf)

A simple document like a contract or a letter

Another type of document that is often printed is legal documents like contracts. It is a template containing some formulas to retrieve the contractors’ name, surname, and address, for example.

For example, to generate the PDF document from an entity selected by the customer, it is enough to write:

// $context: Entity selected by customer
var $context : cs.ReservationEntity
$context:=ds.Reservation.query("ID = 1").first()

// Load write pro model
$doc:=WP Import document(File("/RESOURCES/wpModel/CarRentContract.4wp").platformPath)
// Defines the entity as the data context of the document
WP SET DATA CONTEXT($doc; $context)
// Generate the document
WP COMPUTE FORMULAS($doc)
// Export in PDF
WP EXPORT DOCUMENT($doc; Folder(fk documents folder).file("Contract.pdf").platformPath; wk pdf)

A complex document

Another example, you use the Print form on detail forms to print complex forms with information and several lists in subforms. You can also create this type of document with 4D Write Pro. It is possible to insert several tables with different data sources.

In this example, for an agency, the list of actions of the day is displayed on two tables, one for cars picked up by customers and the other for cars to receive. An Agency entity is passed as data context. The two tables are filled by the computed attributes: Agency.reservationsDeparted and Agency.reservationsArrival. These two computed attributes return an entity selection from the Reservation table.

For example, to generate the PDF document from an entity selected by the customer, it is enough to write:

// $context: Entity selected by customer
var $context : cs.AgencyEntity
$context:=ds.Agency.query("ID = 1").first()

// Load write pro model
$doc:=WP Import document(File("/RESOURCES/wpModel/DayAction.4wp").platformPath)
// Defines the entity as the data context of the document
WP SET DATA CONTEXT($doc; $context)
// Generate the document
WP COMPUTE FORMULAS($doc)
// Export in PDF
WP EXPORT DOCUMENT($doc; Folder(fk documents folder).file("DayAction.pdf").platformPath; wk pdf)

Next…

4D Write Pro is composed of many features, each more interesting than the other. You can find all the features and possibilities in the documentation and, of course, in the blog posts with the “4D Write Pro” tag

 

Vanessa Talbot

• Product Owner •

Vanessa Talbot joined 4D Program team in June, 2014. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.

Since her arrival, she has worked to define key features in 4D. She has worked on most of preemptive multi-threading new features and also on a very complex subject: the new architecture for engined application. Vanessa has a degree from Telecom Saint-Etienne. She began her career at the Criminal Research Institute as a developer for the audiovisual department. She has also worked in media and medical fields as expert in technical support, production as well as documenting new features.