Qdabra Forms - qRules Command Guide Every qRules command, its parameters and behavior All manuals

Chapter 10 - Files, attachments and images

First draft. This chapter has not been reviewed yet and may contain mistakes. Please read it with that in mind, and tell us about anything that does not match what you see.

These nine commands work with files: resize pictures, download or inspect file attachments, read, list, save and delete files on the network, and render the form as a PDF or as plain text. Chapter 1 explains the command syntax, dynamic parameter values and where results go; this chapter assumes you know it.

Network file commands. DeleteFile, GetNetworkFile, ListDirectory, SaveToNetwork and SubmitToNetwork work with files and folders that the FormsViewer server can reach (for example \\fileserver\share\folder or D:\Forms\Out). The server does the work, so paths are resolved on the server, not on the user's computer, and the server's account needs access to them. These commands are only available on FormsViewer deployments that have local network file access enabled, typically an on-premises installation. On other deployments they fail with the error message the server returns.

The examples use this main data source:

my:myFields
  my:Photo                  (picture control, base64 image)
  my:Thumbnail              (picture control, base64 image)
  my:Receipt                (file attachment)
  my:Attachments
    my:Attachment           (repeating)
      my:File               (file attachment; attributes my:qRulesFilename, my:qRulesLink)
      my:FileName
  my:Directory
    my:Entry                (repeating; attributes my:FullPath, my:Modified)
  my:PdfCopy                (file attachment)
  my:PdfLink
  my:FileName

10.1 AlterImage

Resizes a base64 image and can change its format and quality. Use it to shrink photos before they are saved or submitted, for example after a user adds a large picture from a phone camera.

Syntax

AlterImage /image=<base64> | /imagexpath=<XPath> [/imageds=<data source>] [/width=<n> | /maxwidth=<n>] [/height=<n> | /maxheight=<n>] [/maintainproportions=true] [/quality=<1-100>] [/format=png|jpg|<type>]
Parameter Required Description
/image One of the two A base64 image value. The altered image is returned in Result.
/imagexpath One of the two XPath to one or more fields that hold base64 images. Each field is changed in place. Empty fields are skipped.
/imageds No Data source of /imagexpath. Omit for the main data source.
/width No New width in pixels.
/maxwidth No Maximum width. An image that is already narrower keeps its width. Cannot be combined with /width.
/height No New height in pixels.
/maxheight No Maximum height. An image that is already lower keeps its height. Cannot be combined with /height.
/maintainproportions No true scales the other side in proportion. Default false: the side you do not give keeps its original size. Ignored when both sides, or neither, are given.
/quality No A number greater than 0 and up to 100. Default 100. Applies only to formats that support quality, such as jpg.
/format No Output format, for example png or jpg. Default png. A format the browser does not support falls back to png.

Result: with /image, the altered image as base64. With /imagexpath, the number of images changed.

Examples

AlterImage /imagexpath=/my:myFields/my:Photo /maxwidth=800 /maxheight=800 /maintainproportions=true /format=jpg /quality=80
AlterImage /image-xpath=/my:myFields/my:Photo /width=200 /maintainproportions=true /resultxpath=/my:myFields/my:Thumbnail

The first fits the photo inside 800 x 800 pixels, keeping its shape, and stores it as a jpg. The second leaves the photo as it is and writes a 200-pixel-wide copy into another field.

Notes

Related: DownloadAttachment, GetAttachmentAttribute.

10.2 DownloadAttachment

Downloads a file stored in a form field (a file attachment, or a picture stored as base64) to the user's computer, or opens it in a new browser tab. Use it on a button next to an attachment, for example "Open receipt".

Syntax

DownloadAttachment /xpath=<XPath> [/dsname=<data source>] [/filename=<name>] [/open=true]
Parameter Required Description
/xpath Yes The field that holds the file. If several fields match, the first is used.
/dsname No Data source. Omit for the main data source.
/filename No File name for the download. Default: the name stored with the attachment. For a plain base64 picture, which has no stored name, the type is detected and the file is named Picture.gif, Picture.jpg, Picture.png or Picture.bmp.
/open No true opens the file in a new browser tab instead of downloading it. A file type the browser cannot show is downloaded instead. Default false.

Result: empty on success.

Examples

DownloadAttachment /xpath=/my:myFields/my:Receipt
DownloadAttachment /xpath=/my:myFields/my:Attachments/my:Attachment[2]/my:File /open=true
DownloadAttachment /xpath=/my:myFields/my:Photo /filename=Site photo.jpg

The first downloads the receipt with its original name; the second opens the second attachment in a new tab; the third downloads the photo under a chosen name.

Notes

Related: GetAttachmentAttribute, GetNetworkFile.

10.3 GetAttachmentAttribute

Reads one property of a file attachment: its file name, extension, size, or the file content without the attachment header. Use it to show the name of an attached file, to check its type before submitting, or to pass the bare file content to a web service.

Syntax

GetAttachmentAttribute /xpath=<XPath> /attr=name|ext|size|file [/dsname=<data source>]
Parameter Required Description
/xpath Yes The file attachment field. If several fields match, the first is used.
/attr Yes name (file name with extension), ext (extension without the period, for example pdf), size (file size) or file (the file content as plain base64). Not case-sensitive.
/dsname No Data source. Omit for the main data source.

Result: the requested value.

Examples

GetAttachmentAttribute /xpath=/my:myFields/my:Receipt /attr=name /resultxpath=/my:myFields/my:Attachments/my:Attachment[1]/my:FileName
GetAttachmentAttribute /xpath=/my:myFields/my:Receipt /attr=ext

The first copies the receipt's file name into a field; the second returns, for example, pdf, which a following rule can check before the form is submitted.

Notes

Related: DownloadAttachment, SaveToNetwork.

10.4 DeleteFile

Deletes a file on the network. Requires a FormsViewer deployment with local network file access (see the start of this chapter).

Syntax

DeleteFile /path=<file path>
Parameter Required Description
/path Yes Full path of the file to delete, as the FormsViewer server sees it.

Result: empty on success.

Example

DeleteFile /path-xpath=/my:myFields/my:Directory/my:Entry[1]/@my:FullPath

Deletes the first file listed by ListDirectory, using the full path that ListDirectory stored in the row.

Notes

Related: ListDirectory, SaveToNetwork.

10.5 GetNetworkFile

Gets a file from the network. It can start a download of the file, return a link to it, or load an XML file into one of the form's data sources. Requires a FormsViewer deployment with local network file access (see the start of this chapter).

Syntax

GetNetworkFile /path=<file path> [/action=download|link|load] [/dsname=<data source>]
Parameter Required Description
/path Yes Full path of the file, as the FormsViewer server sees it.
/action No download (default) opens the file's download address in a new window. link returns that address in Result. load reads the file as XML and loads it into a data source. Not case-sensitive.
/dsname No With /action=load: the data source to load the file into. Default: the main data source.

Result: with /action=link, the download address; otherwise empty.

Examples

GetNetworkFile /path=\\fileserver\forms\Templates\Instructions.pdf
GetNetworkFile /path-xpath=/my:myFields/my:Directory/my:Entry[1]/@my:FullPath /action=link /resultxpath=/my:myFields/my:PdfLink
GetNetworkFile /path=\\fileserver\forms\Saved\Order-1001.xml /action=load

The first downloads a file; the second stores a download link in a field, which a hyperlink control can show; the third replaces the current form data with a saved XML file.

Notes

Related: ListDirectory, SubmitToNetwork, DownloadAttachment.

10.6 ListDirectory

Lists the files, or the subfolders, of a network folder and writes one row per item into a repeating group. Use it to let users pick a file, or to show what has already been saved. Requires a FormsViewer deployment with local network file access (see the start of this chapter).

Syntax

ListDirectory /path=<folder path> /parent=<XPath> /child=<element name> [/dsname=<data source>] [/mode=file|directory] [/clear=true|false] [/fullpathattributename=<attribute>] [/lastmodifiedlocalattributename=<attribute>]
Parameter Required Description
/path Yes Full path of the folder, as the FormsViewer server sees it.
/parent Yes The group that receives the rows. If it matches several groups, each one receives the rows.
/child Yes Name of the row element to create, for example my:Entry. Each row's text is the file or folder name.
/dsname No Data source of /parent. Omit for the main data source.
/mode No file (default) lists files; directory lists subfolders.
/clear No Default true: remove everything inside /parent before adding the rows. false adds the rows after the existing content.
/fullpathattributename No Attribute of the row that receives the item's full path, for example my:FullPath.
/lastmodifiedlocalattributename No Attribute of the row that receives the item's last-modified date and time, in the server's local time zone.

Result: the number of items listed.

Example

ListDirectory /path=\\fileserver\forms\Saved /parent=/my:myFields/my:Directory /child=my:Entry /fullpathattributename=my:FullPath /lastmodifiedlocalattributename=my:Modified

Fills Directory with one Entry row per file, each with its full path and last-modified time in attributes.

Notes

Related: GetNetworkFile, DeleteFile.

10.7 SaveToNetwork

Saves the files in one or more file attachment fields to a network folder, one file per field. By default it then clears each field and records the saved file's name and link in attributes of the field, so the form keeps a reference to the file instead of the file itself. Requires a FormsViewer deployment with local network file access (see the start of this chapter).

Syntax

SaveToNetwork /path=<folder path> /xpath=<XPath> [/dsname=<data source>] [/name=<file name> | /namexpath=<relative XPath>] [/uniquename=true|false] [/overwrite=true] [/clear=true|false] [/createdirectory=true|false]
Parameter Required Description
/path Yes The destination folder, as the FormsViewer server sees it.
/xpath Yes The file attachment field(s) to save. Every selected field is saved.
/dsname No Data source. Omit for the main data source.
/name No File name to use. Used for every selected field.
/namexpath No XPath, relative to each file field, of a field that holds that file's name. Takes precedence over /name.
/uniquename No Default true: when neither /name nor /namexpath is given, the attachment's own name is prefixed with a date-time stamp and an underscore, for example 20261009143015123_receipt.pdf. false uses the attachment's name as it is.
/overwrite No true replaces an existing file with the same name. Default false.
/clear No Default true: empty the field (set it to nil) after its file is saved.
/createdirectory No Default true: create the destination folder if it does not exist.

Result: the number of files saved.

Example

SaveToNetwork /path=\\fileserver\forms\Receipts /xpath=/my:myFields/my:Attachments/my:Attachment/my:File[. != ''] /namexpath=../my:FileName

Saves every filled attachment row under the name in that row's FileName field, then clears each File field and fills its my:qRulesFilename and my:qRulesLink attributes.

Notes

Related: SubmitToNetwork, GetAttachmentAttribute, DeleteFile.

10.8 SubmitToNetwork

Saves the XML of the form, or of any data source, as a file in a network folder. Use it to keep a copy of each submitted form on a file share. Requires a FormsViewer deployment with local network file access (see the start of this chapter).

Syntax

SubmitToNetwork /path=<full file path> | /path=<folder path> /filename=<name> [/dsname=<data source>] [/createdirectory=true] [/overwrite=true]
Parameter Required Description
/path Yes With /filename: the destination folder. Without it: the full path of the file, including its name.
/filename No File name to save as.
/dsname No The data source whose XML is saved. Omit for the main data source.
/createdirectory No true creates the folder if it does not exist. Default false: the command fails if the folder is missing.
/overwrite No true replaces an existing file. Default false: the command fails if the file exists.

Result: empty on success.

Examples

SubmitToNetwork /path=\\fileserver\forms\Saved\Order-1001.xml
SubmitToNetwork /path=\\fileserver\forms\Saved /filename-xpath=/my:myFields/my:FileName /createdirectory=true /overwrite=true

The first saves the form under a fixed name; the second takes the name from a field, creates the folder if needed and replaces an earlier version.

Notes

Related: SaveToNetwork, GetNetworkFile.

10.9 RenderForm

Renders the form's data through one or more views and returns the result as a PDF or as plain text. Use it to attach a PDF copy of the form to an e-mail, to store it in a file attachment field before submitting, or to open it for printing. PDFs are generated by the FormsViewer server.

Syntax

RenderForm /format=pdf|text [/views=<view>[&<view>...]] [/output=base64|base64raw|text] [/filename=<name>] [/open=browser|download|none] [/templatename=<template> [/dsname=<data source>]] [/useactualview=true] [/includebuttons=true] [/attachmentsxpath=<XPath> /attachmentsmode=inline] [/headertext=<text>] [/headerfontfamily=<font>] [/headerfontsize=<points>] [/headeralignment=<alignment>] [/footertext=<text>] [/footerfontfamily=<font>] [/footerfontsize=<points>] [/footeralignment=<alignment>]
Parameter Required Description
/format Yes pdf or text, in lower case.
/views No View name(s), separated by &. Several views are merged into one PDF. Default: the current view.
/output No For pdf: base64 (default) returns a file attachment value, ready for a file attachment field; base64raw returns the PDF as plain base64. For text: text (the default and only value).
/filename No Name of the PDF file. Default rendered.pdf. Stored in the attachment value with /output=base64, and used as the download name.
/open No What to do with the PDF: browser (default) opens it in the browser, download downloads it, none does nothing. Not case-sensitive. Behavior can vary by browser.
/templatename No Render with a view of another template. Requires /views. PDF only.
/dsname No Data source to render as the main data source. Default: the main data source. Intended for use with /templatename.
/useactualview No true renders the view exactly as it is shown in the browser instead of rendering it fresh from the data. Current view only. Default false.
/includebuttons No Text format: true includes button labels. Default false.
/attachmentsxpath No PDF only: XPath to file attachment or picture fields whose files are included in the PDF.
/attachmentsmode With /attachmentsxpath How to include the attachments. Only inline is supported: the attachment content is included in the PDF.
/headertext No Text at the top of every page. {CrtPage} is replaced by the page number and {PageCount} by the number of pages.
/headerfontfamily No Header font. Default Arial.
/headerfontsize No Header font size in points. Default 8.
/headeralignment No left (default), center, right or justify.
/footertext No Text at the bottom of every page, with the same placeholders as /headertext.
/footerfontfamily No Footer font. Default Arial.
/footerfontsize No Footer font size in points. Default 8.
/footeralignment No left (default), center, right or justify.

Result: the PDF (as a file attachment value or plain base64), or the view's text.

Examples

RenderForm /format=pdf /open=none /filename=Expense report.pdf /resultxpath=/my:myFields/my:PdfCopy
RenderForm /format=pdf /views=Summary&Details /footertext=Page {CrtPage} of {PageCount} /footeralignment=center /open=download
RenderForm /format=pdf /attachmentsxpath=/my:myFields/my:Attachments/my:Attachment/my:File /attachmentsmode=inline /open=browser
RenderForm /format=text /views=Summary

The first stores a PDF of the current view in a file attachment field without showing it, for example before a submit. The second merges two views with page numbers and downloads the result. The third opens a PDF that includes the attached files. The fourth returns the Summary view as plain text, for example for an e-mail body.

Notes

Related: GetAttachmentAttribute, SaveToNetwork, DownloadAttachment. To send the PDF by e-mail, see SendEmail; to save it to SharePoint, see SaveToSharePoint.

Back to the Command Index.

© Qdabra Software  |  Questions and corrections: [email protected]  |  Preview copy, not linked from the public site.