WP EXPORT VARIABLE
WP EXPORT VARIABLE ( wpDoc ; destination ; format {; option} )
Parameter | Type | Description | |
---|---|---|---|
wpDoc | Object | → | 4D Write Pro variable |
destination | Text variable, BLOB variable | 🡘 | Variable to receive exported contents |
format | Longint | → | Variable output format |
option | Object, Longint | → | Export options |
Description
The WP EXPORT VARIABLE command exports the wpDoc 4D Write Pro object to the 4D destination variable in the specified format.
In wpDoc, pass the 4D Write Pro object that you want to export.
In destination, pass the variable that you want to fill with the exported 4D Write Pro object. The type of this variable depends on the export format specified in the format parameter:
- If you pass the native .4wp format or the .docx format, the variable will be of the Blob type,
- If you pass an HTML or SVG format, the variable will be of the Text type.
In the format parameter, pass a constant from the 4D Write Pro Constants theme to set the export format you want to use. Each format is related to a specific use. The following formats are supported:
Constant | Type | Value | Comment |
---|---|---|---|
wk 4wp | Longint | 4 | 4D Write Pro document is saved in a native archive format (zipped HTML and images saved in a separate folder). 4D specific tags are included and 4D expressions are not computed. This format is particularly suitable for saving and archiving 4D Write Pro documents on disk without any loss. |
wk docx | Longint | 7 | .docx extension. 4D Write Pro document is saved in Microsoft Word format. Certified support for Microsoft Word 2010 and newer. The document parts exported are: Body / headers / footers / sectionsPage / print settings (margins, background color / image, borders, padding, paper size / orientation)Images - inline, anchored, and background image pattern (defined with wk background image)Compatible variables and expressions (page number, number of pages, date, time, metadata). Non-compatible variables and expressions will be evaluated and frozen before export.Links - BookmarksURLsNote that some 4D Write Pro settings may not be available or may behave differently in Microsoft Word. |
wk mime html | Longint | 1 | 4D Write Pro document is saved as standard MIME HTML with HTML documents and images embedded as MIME parts (encoded in base64). Expressions are computed and 4D specific tags and method links are removed. Only text boxes anchored to embedded view are exported (as divs). This format is particularly suitable for sending HTML emails with the command. |
wk pdf | Longint | 5 | .pdf extension. 4D Write Pro document is saved in PDF format, based on Page view mode. The following metadata is exported in a PDF document: Title Author Subject Content creator Notes: Expressions are automatically frozen when document is exported Links to methods are NOT exported |
wk svg | Longint | 8 | 4D Write Pro document page is saved in SVG format, based on Page view mode. Note: When exporting to SVG, you can only export one page at a time. Use the wk page index to specify which page to export. |
wk web page html 4D | Longint | 3 | 4D Write Pro document is saved as HTML and includes 4D specific tags; each expression is inserted as a non-breaking space. Since this format is lossless, it is appropriate for storing purposes in a text field. |
Notes:
- "4D specific tags" means 4D XHTML with a 4D namespace and 4D CSS styles.
- For more information about the 4D Write Pro document format, refer to .4wp document format.
- To view a list of known differences or incompatibility when using the .docx format, see Importing and Exporting in .docx format.
- When exporting to SVG format with this command, images are embedded in base64 format.
- For more information on exporting to SVG format, see Exporting to SVG format.
option parameter
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: true (default): Pictures are embedded in the exported .svg file false: Pictures are exported in a folder called "filename_images" at the level of the exported .svg file, "filename" being the name passed to the command for the file, without the extension. The pictures are not embedded, but referenced in the .svg file. Note that: If the folder already exists, it is emptied before the file is exported If there is no image on the exported page, the folder is deleted |
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: false (default): No google fonts import rule is added. true: Adds the @import rule to the exported file. Useful if you want to use fonts that are not available by default on Windows or macOS. 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: 300 (for wk optimized for = wk print) 192 (for wk optimized for = wk screen) Maximum possible value: 1440 |
wk optimized for | optimizedFor | Defines how an exported document is optimized based on its intended medium. Possible values: wk print (default value for wk pdf and wk svg) Bitmap pictures may be downscaled using the DPI defined by wk max picture DPI or 300 (default value) and may be converted to PNG if codec is not supported for the export type. Vectorial pictures are converted to PNG using the DPI defined by wk max picture DPI or 300 (Windows only) If a picture contains more than one format, the best format for printing is used (e.g., .tiff instead or .jpg) wk screen (default value for wk web page complete and wk mime html) Bitmap pictures may be downscaled using the DPI defined by wk max picture DPI or 192 (default value) and may be converted to JPEG (opaque images) or PNG (transparent images) if codec is not supported for the export type. Vectorial pictures are converted to PNG using the DPI defined by wk max picture DPI or 192 (Windows only) If a picture contains more than one format, the format for screen rendering is used. 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: wk pdfa2: Exports to version "PDF/A-2" wk pdfa3: Exports to version "PDF/A-3" 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: true - Default value. All formulas are recomputed false - Do not recompute formulas |
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
| (default: false) | - | (default: False) | (default: False) | (default: False) | (default: False) |
| wk max picture DPI
| - | always 300 | | (default: 300) | - | (default: 300) |
| wk optimized for
| - | always wk print | (default:wk screen)
| always wk print | - | (default:wk print)
|
| wk recompute formulas
| - | (default: true) | (default: true) | (default: true) | - | (default: true) |
| wk visible background and anchored elements
| - | (default: true) | always true | (default: true) | - | (default: true) |
| wk visible footers
| - | always true | always false | (default: true) | - | (default: true) |
| wk visible headers
| - | always true | always false | (default: true) | - | (default: true) |
| wk visible empty images
| - | (default: true) | (default: true) | (default: true) | - | (default: true) |
| wk visible references
| - | - | - | (default: false) | - | (default: false) |
| wk pdfa version
| - | - | - | | - | - |
| wk page index
| - | - | - | - | - | (default: 1) |
| wk factur x
| - | - | - | | - | - |
| wk files
| - | - | - | | - | - |
| wk embedded pictures
| - | - | - | - | - | (default: true) |
| wk google fonts tag
| - | - | - | - | - | (default: false) |
Compatibility Note: Passing a longint value in option is supported for compatibility reasons, but it is recommended to use an object parameter.
Example 1
You want to export the contents of the myArea 4D Write Pro object in MIME format and add "gmail.com" as the host domain:
var $option;$export : Object
$option[wk CID host domain name]:="gmail.com"
WP EXPORT VARIABLE(myArea;$export;wk mime html;$option)
Example 2
You want to send an email containing styled text, 4D references and images. You can use a 4D Write Pro area exported in MIME format and sent using SMTP:
// create the transporter
$server:=New object
$server.host:="smtp.gmail.com"
$server.port:=465
$server.user:="4D@gmail.com"
$server.password:="XXXX"
$transporter:=SMTP New transporter($server)
WP EXPORT VARIABLE(WParea;$mime;wk mime html)
$mailTmp:=MAIL Convert from MIME($mime)
// add pictures (if any)
If($mailTmp.attachments#Null)
$email.attachments:=$mailTmp.attachments
End if
$email.bodyStructure:=$mailTmp.bodyStructure
$email.bodyValues:=$mailTmp.bodyValues
$status:=$transporter.send($email)
If(Not($status.success))
ALERT("An error occurred: "+$status.statusText)
End if
Example 3
To export the first page of a 4D Write Pro as SVG in a Text variable and hide the headers:
var $options : Object
var $destination : Text
$options:=New object
$options[wk optimized for]:=wk screen
$options[wk visible headers]:=False
WP EXPORT VARIABLE(WPArea;$destination;wk svg;$options)
See also
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
Importing and Exporting in .docx format
WP EXPORT DOCUMENT