This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v20 R7
WP EXPORT DOCUMENT
|
WP EXPORT DOCUMENT ( wpDoc ; filePath {; format {; option}} ) | ||||||||
Parameter | Type | Description | ||||||
wpDoc | Object |
![]() |
4D Write Pro variable | |||||
filePath | String |
![]() |
Path of exported file | |||||
format | Longint |
![]() |
Document output format | |||||
option | Object, Longint |
![]() |
Export options | |||||
The WP EXPORT DOCUMENT command exports the wpDoc 4D Write Pro object to a document on disk according to the filePath parameter as well as any optional parameters.
In wpDoc, pass the 4D Write Pro object that you want to export.
In filePath, pass the destination path and the name of the document to be exported. If you pass only the document name, it will be saved at the same level as the 4D structure file.
You can omit the format parameter, in which case you need to specify the extension in filePath. You can also pass a constant from the 4D Write Pro Constants theme in the format parameter. In this case, 4D adds the appropriate extension to the file name if needed. The following formats are supported:
Notes:
Pass an object in option containing the values to define the properties of the exported document. The following properties are available:
Constant | Value | Comment |
wk CID host domain name | cidHostDomain | CID host domain name: host domain that will be added to generated CID URLs including an '@' as separator. Available only when the wk mime html format is used. |
wk embedded pictures | embeddedPictures | For SVG Export only. Sets whether pictures are embedded in the exported .svg file when you call WP EXPORT DOCUMENT. Available values:
|
wk factur x | facturX | For PDF export only. Value: object configuring a "Factur-X (ZUGFeRD)" PDF export (see wk factur x object). |
wk files | files | For PDF export only. Value: collection of objects, each of them describing a file to be embedded in the final document (see wk files collection). This feature is only supported in PDF/A-3 documents: when the wk files attribute is used, the "PDF/A-3" version is automatically set (the wk pdfa version attribute is ignored). In case of a Factur-X PDF export (see below), the first object of the collection must contain the Factur-X xml file. |
wk google fonts tag | googleFontsTag | For SVG export only. Sets the import rule for google fonts in the exported SVG. Possible values:
Note: This property is set to false by default because when enabled, Google fonts override native fonts, and native fonts are generally better rendered in the browser. |
wk HTML pretty print | htmlPrettyPrint | HTML code is formatted to be easier to read. |
wk max picture DPI | maxPictureDPI | Used for resampling (reducing) images to preferred resolution. For SVG images in Windows, used for rasterization. Default values:
Maximum possible value: 1440 |
wk optimized for | optimizedFor | Defines how an exported document is optimized based on its intended medium. Possible values:
Note: Documents exported in wk docx format are always optimized for wk print (wk optimized for option is ignored). |
wk page index | pageIndex | For SVG export only. Index of the page to export to svg format (default is 1). Page index starts at 1 for the first page of the document. Note: Page index is independent from page numbering. |
wk pdfa version | pdfaVersion | Exports PDF with conformance to a PDF/A version. For more information on PDF/A properties and versions, please refer to the PDF/A page on Wikipedia. Possible values:
Note: On macOS, wk pdfa2 may export to PDF/A-2 or PDF/A-3 or higher, depending on platform implementation. Also, wk pdfa3 means "exports to at least PDF/A-3". On Windows, the output PDF file will always be equal to the desired conformance. |
wk recompute formulas | recomputeFormulas | Defines if formulas must be recomputed when exported. Possible values:
|
wk visible background and anchored elements | visibleBackground | Displays or exports background images/color, anchored images and text boxes (for display, visible effect in Page or Embedded view mode only). Possible values: True/False |
wk visible empty images | visibleEmptyImages | Displays or exports a default black rectangle for images that cannot be loaded or computed (empty images or images in an unsupported format). Possible values: True/False. Default value: True If value is False, missing image elements will not be displayed at all even if they have borders, width, height, or background; this may impact the page layout for inline images. |
wk visible footers | visibleFooters | Displays or exports the footers (for display, visible effect in Page view mode only). Possible values: True/False |
wk visible headers | visibleHeaders | Displays or exports the headers (for display, visible effect in Page view mode only). Possible values: True/False |
wk visible references | visibleReferences | Displays or exports all 4D expressions inserted in the document as references. Possible values: True/False |
The following table indicates the option available per export format:
wk 4wp | wk docx | wk mime html | wk pdf | wk web page html 4D | wk svg | |
wk CID host domain name | - | - | ![]() | - | - | - |
wk HTML pretty print | ![]() | - | ![]() | ![]() | ![]() | ![]() |
wk max picture DPI | - | always 300 | ![]() | ![]() | - | ![]() |
wk optimized for | - | always wk print | ![]() | always wk print | - | ![]() |
wk recompute formulas | - | ![]() | ![]() | ![]() | - | ![]() |
wk visible background and anchored elements | - | ![]() | always true | ![]() | - | ![]() |
wk visible footers | - | always true | always false | ![]() | - | ![]() |
wk visible headers | - | always true | always false | ![]() | - | ![]() |
wk visible empty images | - | ![]() | ![]() | ![]() | - | ![]() |
wk visible references | - | - | - | ![]() | - | ![]() |
wk pdfa version | - | - | - | ![]() | - | - |
wk factur x | - | - | - | ![]() | - | - |
wk files | - | - | - | ![]() | - | - |
wk page index | - | - | - | - | - | ![]() |
wk embedded pictures | - | - | - | - | - | ![]() |
wk google fonts tag | - | - | - | - | - | ![]() |
Compatibility Note: Passing a longint value in option is supported for compatibility reasons, but it is recommended to use an object parameter.
The wk files property allows you to export a PDF with attachments. This property must contain a collection of objects describing the files to be embedded in the final document. Each object of the collection can contain the following properties:
Property | Type | Description |
name | Text | File name. Optional if the file property is used, in which case the name is inferred by default from the file name. Mandatory if the data property is used (except for the first file of a Factur-X export, in which case the name for the file is automatically "factur-x.xml", see below) |
description | Text | Optional. If omitted, default value for the first export file to Factur-X is "Factur-X/ZUGFeRD Invoice", otherwise empty. |
mimeType | Text | Optional. If omitted, default value can usually be guessed from file extension; otherwise, "application/octet-stream" is used. If passed, make sure to use an ISO mime type, otherwise the exported file could be invalid. |
data | Text or BLOB | Mandatory if file property is missing |
file | 4D.File object | Mandatory if data property is missing, ignored otherwise. |
relationship | Text | Optional. If omitted, default value is "Data". Possible values for Factur-X first file:
|
If the option parameter also contains a wk factur x property, then the first element of the wk files collection must be the Factur-X (ZUGFeRD) invoice xml file (see below).
Note: PDF attachments are only supported by the PDF/A-3 version. When you pass the wk files property, the "PDF/A-3" version is automatically used.
The wk factur x property is an object that can contains up to two properties:
Property | Type | Description |
profile | Text | Optional for standard profiles, mandatory otherwise. If omitted, profile is determined from the provided xml file or text (which must use a standard profile). If passed, it can be a non-standard profile name (for using other profiles - for instance RECHNUNG). Note: Standard profile names are: MINIMUM, BASIC WL, BASIC, EN 16931 (aka COMFORT which is an alias), EXTENDED. |
version | Text | Optional. Default value is "1.0" |
About Factur-X / ZUGFeRD PDF documents
Factur-X / ZUGFeRD is a European standard for hybrid e-invoices (PDF for users and XML data for process automation). For more information, please read this blog post.
To trigger a "Factur-X" PDF export, pass both the wk factur x and wk files properties in the option parameter (see Example 5). In this case:
Note: For a detailed example of Factur-X / ZUGFeRD export implementation, you can download this HDI 4D project.
You want to export the contents of the myArea 4D Write Pro object in both HTML and PDF format:
// export HTML
var $option : Object
$option:=New object
$option[wk recompute formulas]:=False
$option[wk HTML pretty print]:=False
$option[wk optimized for]:=wk print
$option[wk max picture DPI]:=600 //override default value for print (300 DPI)
WP EXPORT DOCUMENT(myArea;$path;wk web page complete;$option)
//export PDF
var $option : Object
$option:=New object
$option[wk visible headers]:=True
$option[wk visible footers]:=True
$option[wk visible background]:=True
$option[wk max picture DPI]:=96 //override default value for screen (192 DPI) to limit doc size
$option[wk optimized for]:=wk screen
$option[wk recompute formulas]:=True
WP EXPORT DOCUMENT(myArea;$path;wk pdf;$option)
You want to export the contents of the myArea 4D Write Pro object in .4wp format:
C_TEXT($path)
C_LONGINT($docRef)
Case of
:(Form event code=On Clicked)
$path:=Get 4D folder(Database folder)+"Export"+Folder separator
$path:=Select document($path;".4wp";" title";File name entry)
If($path#"")
WP EXPORT DOCUMENT(myArea;document;wk 4wp)
End if
End case
To export the second page of the document as SVG and export the pictures from the document:
var $options : Object
$options:=New object
$options[wk embedded pictures]:=False
$options[wk page index]:=2
WP EXPORT DOCUMENT(WPArea;"my exported document";wk svg;$options)
Exporting a PDF document with PDF/A-2 conformance:
Examples of Factur-X PDF exports:
//BASIC (standard profile)
var $options;$fileInfo : Object
$options:={}
$options[wk factur x]:={}
$options[wk factur x].profile:="BASIC"
$options[wk factur x].version:="1.0"
$fileInfo:={}
$fileInfo.file:=$file //$file is a 4D.File with an .xml file as target
$options[wk files]:=[$fileInfo]
WP EXPORT DOCUMENT(wpDoc;"facturX_basic.pdf";wk pdf;$options)
//RECHNUNG profile (custom profile)
$options:={}
$options[wk factur x]:={}
$options[wk factur x].profile:="RECHNUNG"
$options[wk factur x].version:="2.1" //last version for RECHNUNG
$fileInfo:={}
$fileInfo.file:=$file //$file is a 4D.File with an .xml file as target
$fileInfo.name:="rechnung.xml" //mandatory file name in PDF for RECHNUNG
$fileInfo.relationship:="Alternative" //mandatory for Germany
$fileInfo.description:="ZUGFeRD Rechnung"
$options[wk files]:=[$fileInfo]
WP EXPORT DOCUMENT(wpDoc;"facturX_rechnung.pdf";wk pdf;$options)
4D QPDF (Component) - PDF Get attachments
Blog post - 4D Write Pro: Electronic invoice generation
Blog post - 4D Write Pro: Export to PDF with enclosures
Exporting to HTML and MIME HTML formats
Exporting to SVG format
Importing and Exporting in .docx format
WP EXPORT VARIABLE
Product: 4D
Theme: 4D Write Pro Language
Number:
1337
Created: 4D v14 R5
Modified: 4D v15 R2
Modified: 4D v17 R4
Modified: 4D v19 R3
Modified: 4D v20
Modified: 4D v20 R3
Modified: 4D v20 R4
4D Write Pro Reference ( 4D v20 R7)