Aller au contenu principal
Version: 20 R9

WP EXPORT VARIABLE

WP EXPORT VARIABLE ( wpDoc ; destination ; format {; option} )

ParamètresTypeDescription
wpDocObjectVariable 4D Write Pro
destinationText, BlobVariable pour recevoir les contenus exportés
formatIntegerFormat de sortie variable
optionObject, IntegerOptions d'export

Description

La commande WP EXPORT VARIABLE exporte l'objet wpDoc 4D Write Pro vers la variable 4D destination dans le format spécifié.

Dans wpDoc, passez l'objet 4D Write Pro que vous souhaitez exporter.

Dans destination, passez la variable que vous voulez remplir avec l'objet exporté de 4D Write Pro. Le type de cette variable dépend du format d'exportation spécifié dans le paramètre format :

  • Si vous passez le format .4wp natif ou le format .docx, la variable sera de type Blob,
  • Si vous passez un format HTML ou SVG, la variable sera du type Text.

Dans le paramètre format, passez une constante du thème 4D Write Pro Constants pour définir le format d'exportation que vous souhaitez utiliser. Chaque format est lié à une utilisation spécifique. Les formats suivants sont pris en charge:

ConstanteTypeValeurCommentaire
wk 4wpInteger44D 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 docxInteger7.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 htmlInteger14D 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 pdfInteger5.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 svgInteger84D 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 4DInteger3Le document 4D Write Pro est enregistré en HTML et comprend des balises spécifiques à 4D ; chaque expression est insérée sous forme d'espace insécable. Since this format is lossless, it is appropriate for storing purposes in a text field.

Notes :

  • "Balises spécifiques 4D" signifie XHTML 4D avec un espace de noms 4D et des styles CSS 4D.
  • Pour plus d'informations sur le format du document 4D Write Pro, reportez-vous à .4wp document format.
  • Pour consulter la liste des différences ou des incompatibilités connues lors de l'utilisation du format .docx, voir Importation et exportation au format .docx.
  • Lors de l'exportation au format SVG avec cette commande, les images sont intégrées au format base64.
  • Pour plus d'informations sur l'exportation au format SVG, voir Exportation au format SVG.

option parameter

Pass an object in option containing the values to define the properties of the exported document. Les propriétés suivantes sont disponibles :

ConstanteValeurCommentaire
wk CID host domain namecidHostDomainCID host domain name: host domain that will be added to generated CID URLs including an '@' as separator. Disponible uniquement lorsque le format wk mime html est utilisé.
wk embedded picturesembeddedPicturesFor 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: 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 xfacturXFor PDF export only. Value: object configuring a "Factur-X (ZUGFeRD)" PDF export (see wk factur x object).
    wk filesHistoriqueFor PDF export only. Value: collection of objects, each of them describing a file to be embedded in the final document (see wk files collection). For PDF export only. 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 taggoogleFontsTagFor 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. Utile si vous voulez utiliser des polices qui ne sont pas disponibles par défaut sur Windows ou macOS.
  • Note: Cette propriété est définie sur false par défaut car, lorsqu'elle est activée, les polices Google ont la priorité sur les polices natives, et ces dernières sont généralement mieux rendues dans le navigateur.
    wk HTML pretty printhtmlPrettyPrintHTML code is formatted to be easier to read.
    wk max picture DPImaxPictureDPIUsed 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 foroptimizedForDefines 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). Si une image contient plus d'un format, le format de rendu d'écran est utilisé.
  • Note: Les documents exportés au format wk docx sont toujours optimisés pour wk print (l'option wk optimized for est ignorée).
    wk page indexpageIndexFor 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 versionpdfaVersionExports 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". 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.
  • wk recompute formulasrecomputeFormulasDefines if formulas must be recomputed when exported. Valeurs possibles :
  • true - Valeur par défaut. Toutes les formules sont recalculées
  • false - Ne pas recalculer les formules
  • wk visible background and anchored elementsvisibleBackgroundDisplays 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 imagesvisibleEmptyImagesDisplays 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 footersvisibleFootersDisplays or exports the footers (for display, visible effect in Page view mode only). Possible values: True/False
    wk visible headersvisibleHeadersDisplays or exports the headers (for display, visible effect in Page view mode only). Possible values: True/False
    wk visible referencesvisibleReferencesDisplays or exports all 4D expressions inserted in the document as references. Possible values: True/False
    wk whitespacewhitespaceSets the "white-space" css value for wk mime html export format. The white-space css style is applied to paragraphs. Possible values: "normal", "nowrap", "pre", "pre-wrap" (default), "pre-line", "break-spaces".

    Le tableau suivant indique l'option disponible par format d'export :

    wk 4wpwk docxwk mime htmlwk pdfwk web page html 4dwk svg
    wk CID host domain name-----
    wk embedded pictures----- (par défaut : true)
    wk factur x-----
    wk files-----
    wk google fonts tag----- (par défaut : false)
    wk HTML pretty print (par défaut : false)- (par défaut : False) (par défaut : False) (par défaut : False) (par défaut : false)
    wk max picture DPI-toujours 300 (par défaut : 300)- (par défaut : 300)
    wk optimized for-toujours wk print (default: wk screen)toujours wk print- (par défaut : wk print)
    wk page index----- (par défaut : 1)
    wk pdfa version-----
    wk recompute formulas- (par défaut : true) (par défaut : true) (par défaut : true)- (par défaut : true)
    wk visible background and anchored elements- (par défaut : true)toujours true (par défaut : true)- (par défaut : true)
    wk visible empty images- (par défaut : true) (par défaut : true) (par défaut : true)- (par défaut : true)
    wk visible footers-toujours truetoujours false (par défaut : true)- (par défaut : true)
    wk visible headers-toujours truetoujours false (par défaut : true)- (par défaut : true)
    wk visible references--- (par défaut : false)- (par défaut : false)
    wk whitespace-- (par défaut : "pre-wrap")---

    Compatibility Note: Passing a longint value in option is supported for compatibility reasons, but it is recommended to use an object parameter.

    Exemple 1

    Vous voulez exporter le contenu de l'objet myArea 4D Write Pro au format MIME et ajouter "gmail.com" comme domaine hôte :

     var $option;$export : Object

    $option[wk CID host domain name]:="gmail.com"

    WP EXPORT VARIABLE(myArea;$export;wk mime html;$option)

    Exemple 2

    Vous voulez envoyer un email contenant du texte stylé, des références 4D et des images. Vous pouvez utiliser une zone 4D Write Pro exportée au format MIME et envoyée en utilisant SMTP:

      // créer le transporteur
    $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)

    // ajouter des photos (le cas échéant)
    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

    Exemple 3

    Pour exporter la première page d'un 4D Write Pro en SVG dans une variable Texte et masquer les en-têtes :

     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)

    Voir également

    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