Aller au contenu principal
Version: Suivant

WP EXPORT DOCUMENT

WP EXPORT DOCUMENT ( wpDoc ; filePath {; format {; option}} )
WP EXPORT DOCUMENT ( wpDoc ; fileObj {; format {; option}} )

ParamètresTypeDescription
wpDocObjectVariable 4D Write Pro
filePathTextChemin du fichier d'export
fileObj4D.FileObjet du fichier à exporter
formatIntegerFormat de sortie du document (ex : .docx, .pdf, etc.)
optionObject, IntegerOptions d'export, qui peuvent varier en fonction du format choisi.

Description

La commande WP EXPORT DOCUMENT exporte l'objet 4D Write Pro wpDoc vers un document sur disque selon le paramètre filePath ou fileObj ainsi que tout paramètre optionnel.

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

Vous pouvez passer soit un filePath ou fileObj :

  • Dans filePath, passez le chemin de destination et le nom du document à exporter. Si vous ne passez que le nom du document, il sera sauvegardé au même niveau que le fichier de structure 4D.

  • Dans le paramètre fileObj, passez un objet 4D.File représentant le fichier à exporter.

Vous pouvez omettre le paramètre format, auquel cas vous devez spécifier l'extension dans filePath. Vous pouvez également passer une constante du thème 4D Write Pro Constants dans le paramètre format. Dans ce cas, 4D ajoute l'extension appropriée au nom du fichier si nécessaire. Les formats suivants sont pris en charge:

ConstanteValeurCommentaire
wk 4wp44D 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 docx7.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 html14D 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 pdf5.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 svg84D 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 complete2.htm or .html extension. Document is saved as standard HTML and its resources are saved separately. 4D tags and links to 4D methods are removed and expressions are computed. Only text boxes anchored to embedded view are exported (as divs). Only text boxes anchored to embedded view are exported (as divs).

Notes :

  • "Balises spécifiques 4D" signifie XHTML 4D avec un espace de noms 4D et des styles CSS 4D.
  • For more information about the 4D Write Pro document format, refer to .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.
  • 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. 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. Available only when the wk mime html format is used.
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). 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 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. 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 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). 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 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". On Windows, the output PDF file will always be equal to the desired conformance.
  • wk recompute formulasrecomputeFormulasDefines 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 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 and wk web page complete export formats. 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 completewk 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 (default: 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-- (default: "pre-wrap")- (default: "pre-wrap")-

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

    wk files collection

    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:

    PropriétéTypeDescription
    nameTextFile 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)
    DescriptionTextOptionnel. If omitted, default value for the first export file to Factur-X is "Factur-X/ZUGFeRD Invoice", otherwise empty.
    mimeTypeTextOptionnel. 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.
    dataText ou BLOBMandatory if file property is missing
    file4D.File objectMandatory if data property is missing, ignored otherwise.
    relationshipTextOptionnel. If omitted, default value is "Data". Possible values for Factur-X first file:for BASIC, EN 16931 or EXTENDED profiles: "Alternative", "Source" or "Data" ("Alternative" only for German invoice)for MINIMUM and BASIC WL profiles: "Data" only.for other profiles: "Alternative", "Source" or "Data" (with restrictions perhaps depending on country: see profile specification for more info about other profiles - for instance for RECHNUNG profile only "Alternative" is allowed)for other files (but Factur-X invoice xml file) : "Alternative", "Source", "Data", "Supplement" or "Unspecified"any other value generates an error.

    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.

    wk factur x object

    The wk factur x property is an object that can contains up to two properties:

    PropriétéTypeDescription
    profileTextOptionnel. 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.
    versionTextOptionnel. Default value is "1.0"

    À propos des documents PDF Factur-X / ZUGFeRD

    Factur-X / ZUGFeRD est une norme européenne pour les factures électroniques hybrides (PDF pour les utilisateurs et données XML pour l'automatisation des processus). Pour plus d'informations, veuillez lire cet article de blog.

    Pour déclencher une exportation PDF "Factur-X", passez les propriétés wk factur x et wk files dans le paramètre option (voir exemple 5). Dans ce cas :

    • un PDF Factur-X (ZUGFeRD) est généré,
    • le premier élément de la collection wk files est utilisé comme fichier xml Factur-X,
    • si la propriété wk files est manquante ou contient une collection vide, ou si son premier élément n'est pas un fichier xml, une erreur est générée.
    note

    Pour un exemple détaillé de la mise en œuvre de l'exportation Factur-X / ZUGFeRD, vous pouvez télécharger ce projet HDI 4D.

    Exemple 1

    Vous souhaitez exporter le contenu de l'objet 4D Write Pro myArea aux formats HTML et PDF :

      // exporter 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 //remplacer la valeur par défaut pour l'impression (300 DPI)

    WP EXPORT DOCUMENT(myArea;$path;wk web page complete;$option)

    //exporter 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 //remplacer la valeur par défaut pour l'écran (192 DPI) pour limiter la taille du document
    $option[wk optimized for]:=wk screen
    $option[wk recompute formulas]:=True

    WP EXPORT DOCUMENT(myArea;$path;wk pdf;$option)

    Exemple 2

    Vous souhaitez exporter le contenu de l'objet 4D Write Pro myArea au format .4wp :

     var $path : Text

    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

    Exemple 3

    Pour exporter la deuxième page du document en SVG et exporter les images depuis le 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)

    Exemple 4

    Exportation d'un document PDF conforme à la norme PDF/A-2 :

     var $options: Object:={}
    $options[wk visible empty images] :=False
    $options[wk pdfa version]:=wk pdfa2 // conformité "PDF/A-2"
    WP EXPORT DOCUMENT(wpDoc;"invoice.pdf";wk pdf;$options)

    Exemple 5

    Exemples d'exportations PDF de Factur-X :

      //BASIC (profil standard)
    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 est un 4D.File avec un fichier .xml comme cible
    $options[wk files]:=[$fileInfo]

    WP EXPORT DOCUMENT(wpDoc;"facturX_basic.pdf";wk pdf;$options)

    //Profil RECHNUNG (profil personnalisé)
    $options:={}
    $options[wk factur x]:={}
    $options[wk factur x].profile:="RECHNUNG"
    $options[wk factur x].version:="2.1" //dernière version pour RECHNUNG

    $fileInfo:={}
    $fileInfo.file:=$file //$file est un 4D.File avec un fichier .xml comme cible
    $fileInfo.name:="rechnung.xml" //Nom de fichier obligatoire dans le PDF pour RECHNUNG
    $fileInfo.relationship:="Alternative" //obligatoire pour l'Allemagne
    $fileInfo.description:="ZUGFeRD Rechnung"
    $options[wk files]:=[$fileInfo]

    WP EXPORT DOCUMENT(wpDoc;"facturX_rechnung.pdf";wk pdf;$options)

    Exemple 6

    Exportation d'un document docx en utilisant un objet File :

    var $file : 4D.File

    $file:=File("/DATA/test-export")

    $options:=New object(wk visible background and anchored elements; False)

    WP EXPORT DOCUMENT(WParea; $file; wk docx; $options)

    Voir également

    4D QPDF (Component) - PDF Get attachments
    Exporting to HTML and MIME HTML formats
    Importing and Exporting in .docx format
    Blog post - 4D Write Pro: Electronic invoice generation
    Blog post - 4D Write Pro: Export to PDF with enclosures
    WP EXPORT VARIABLE