Xbasic

OBJECT.SAVEAS Function

Syntax

Output_Filename as C = Object_Type.Saveas(c layoutname [,c saveas_format [,c filter [,c order [,c filename [,l openoutputfile [,* printoptions [, SQL::Arguments arguments [,* options]]]]]]]])

Arguments

Object_TypeCharacter

The type of object to save. This can be one of the following:

  • "Label"
  • "Letter"
  • "Report"
layoutnameCharacter

The name of a label, letter, or report layout.

saveas_formatCharacter

Default = "PDF". The file format. The options for Format are:

Format
File Type
"PDF"

PDF format

"HTML"

Dynamic HTML format

"RTF"

Rich Text format

"TXT"

Plain Text format

"Excel"

Excel format

"XPS"

XPS format -- XML Paper Specification, an alternative to PDF

filterCharacter

Default = ".T." (All records). A filter expression that evaluates to a logical value and selects records from the table.

orderCharacter

Default = record order. An order expression that sorts selected records.

filenameCharacter

Default = Layout_Name in the same folder as the database. The path and name to give the saved file.

openoutputfileLogical

Default = .F.

.T. = After the layout is printed, Alpha Anywhere opens the file with its associated applications. For example, if you saved as a Rich Text Format file, and WordPerfect is the associated application for .RTF files on your computer, Alpha Anywhere will start WordPerfect and load the file.

.F. = Do not open associated application.

printOptionsPointer

Default = null_value(). You can override the default system settings on a permanent basis. When you override the system defaults, your settings are stored in a text file in the Alpha Anywhere program folder. These files are named:

AlphaFivePrinterDriver_htm.PrintOptions 
AlphaFivePrinterDriver_pdf.PrintOptions 
AlphaFivePrinterDriver_rtf.PrintOptions

Print options are described below. Print options are available for PDF, RTF, and HTML file types. The supported file types are indicated in the option's description.

PrintOptions.MultilingualSupportLogical

Default = .f.. PDF, RTF, and HTML.

PrintOptions.Colors2GrayScaleLogical

Default = .f.. PDF, RTF, and HTML.

PrintOptions.ConvertHyperlinksLogical

Default = .f.. PDF and HTML only.

PrintOptions.RTFTypeCharacter

Default = "Formatted Text". RTF only.

PrintOptions.HTMTypeCharacter

Default = "Layers". HTML only.

PrintOptions.ConcatenateLogical

Default = .f.. PDF only.

PrintOptions.HasWatermarkLogical

Default = .f.. PDF only.

PrintOptions.LinearizeForWebLogical

Default = .f.. PDF only.

PrintOptions.WatermarkTypeCharacter

Default = "Text". PDF only.

PrintOptions.WatermarkTextCharacter

Default = "D R A F T". PDF only.

PrintOptions.WatermarkFontNameCharacter

Default = "Times New Roman". PDF only.

PrintOptions.WatermarkFontSizeNumeric

Default = 172. PDF only.

PrintOptions.WatermarkRotationNumeric

Default = 450. PDF only.

PrintOptions.WatermarkColorHexCharacter

Default = upper("e8fed2"). PDF only.

PrintOptions.WatermarkHorizPosNumeric

Default = 120. PDF only.

PrintOptions.WatermarkVertPos. PDF only.Numeric

Default = 120. PDF only.

PrintOptions.WatermarkOnTopLogical

Default = .f.. PDF only.

PrintOptions.WatermarkPDFCharacter

Default = "". PDF only.

PrintOptions.EncryptLogical

Default = .f.. PDF only.

PrintOptions.OwnerPasswordCharacter

Default = "". PDF only.

PrintOptions.UserPasswordCharacter

Default = "". PDF only.

PrintOptions.CanPrintLogical

Default = .t.. PDF only.

PrintOptions.CanModifyDocumentLogical

Default = .t.. PDF only.

PrintOptions.CanCopyLogical

Default = .t.. PDF only.

PrintOptions.CanAddNotesLogical

Default = .t.. PDF only.

PrintOptions.Use128BitKeyLogical

Default = .f.

PrintOptions.EmbedFontsLogical

Default = .f.. PDF only.

If a font is protected, it can't be embedded. This is often the case for bar code fonts, such as Code39.

PrintOptions.JpegQualityCharacter

Default = "Low". PDF only.

JPEG quality can be "Low", "Medium", "High", or "No Compression".

argumentsSQL::Arguments

Default = null_value(). Arguments that retrieve value(s) from variable(s) or prompts for value(s) at runtime. Only applicable to SQL Reports.

optionsPointer

Default = null_value(). Sets filter (WHERE) and order (ORDER BY) expressions for a query against a passive-linked table. A pointer dot variable with 2 elements. See [Using the Options Argument].

filterCharacter

Replaces the ORDER BY clause in the underlying SQL expression.

orderCharacter

Adds to the WHERE clause in the underlying SQL expression.

Description

Prints a Report, Letter, or Label layout to file in PDF, HTML, RTF, TXT, Excel, or XPS format.

Discussion

The <Object>.saveAs() method prints Layout_Name to file in PDF, HTML, RTF, or TXT formats.

If no format is specified, the .PDF format is used. If you specify an optional Filter_Expression, the only records matching the filter are printed. (In addition to the filter specified here, the layout may have a filter defined within the layout definition). The layout is printed to Filename. If Filename is not specified, the layout is printed to a file with the same name as the Layout_Name in the same folder as the database.

Form.saveAs() and Browse.saveAs() are deprecated. If you want to print a browse or form layout, you must create a report and then import the form or browse as as new report. You can then use report.saveAs().

Example

This script saves a report as a RTF file.

filename = :Report.saveAs("Invoice","rtf")

This script saves a report as a PDF file, then launches Adobe Acrobat to view it.

dim fn as C
fn = report.saveAs("Customer List", "PDF", "", "", "C:\test.pdf", .T.)

This script saves copy of the Invoice report with an argument. You can add as many arguments to the arguments collection as you want.

DIM myargs as SQL::arguments 
myargs.add("whatcity","London") 
report.saveAs("report1", "PDF", "", "", "C:\test.pdf", .f., .f., myargs)

In this example, let's assume that the report is based on a SQL data source. If you specify a filter and order in the method's Filter_expression and Order_expression arguments, the filter and order will be applied after the data has been extracted from the SQL table and moved into a temporary local .dbf table. This is very inefficient. It would be much better to do the filtering and ordering on the server before the data is moved to the local temporary table. This is done using the optional Options argument. For example:

DIM myargs as SQL::arguments 
dim options as p
options.filter = "city = 'london' .and. title = 'manager'"
options.order = "lastname"
report.saveAs("report1", "PDF", "", "", "C:\test.pdf", .f., .f., myargs,options)

When you specify the filter in options.filter, you can use arguments. For example:

DIM myargs as SQL::arguments
myargs.add("whatcity","london")
myargs.add("whattitle","manager") 
  
dim options as p
options.filter = "city = :whatcity .and. title = :whatmanager"
options.order = "lastname"
report.saveAs("report1", "PDF", "", "", "C:\test.pdf", .f., .f., myargs, options)

When the report is based on a SQL data source you can combine local filtering with filtering on the server. In the above two examples, the filtering was performed on the server. However you can do further filtering on the client if you specify the Filter_expression argument. You might take this approach if you want to do some pre-filtering on the server to limit the number of record that are moved to the temporary local .dbf table, but then use some user-designed function in your local filter.

Using the Options Argument

If you have a SQL report called "nw_customers" with the SQL Select statement select * from customers, you could use the following <object>.saveAs() statements:

Saves a report with all customer records.
report.saveAs("Nw_customers")
Saves a report showing records for the city of London. Note: This method can be very slow for large databases.
report.saveAs("Nw_customers", "city = 'London'")

If the table had 1,000,000 records with 5 records for London, Alpha Anywhere would bring down all 1,000,000 records to the local computer and then do a filter on the table to get the 5 records to print.

Downloading 1,000,000 records and then post processing them with Alpha Anywhere can be very slow. It would be more efficient to do the filter as part of the SQL database query.

dim opt as P 
opt.filter = "city = 'London'" 
report.saveAs("nw_customers", "PDF", "", "", "C:\test.pdf", .f., .f., null_value(), opt)

Note, that since opt is the last argument in the function prototype, you must supply values for all of the preceding arguments, even if they were optional arguments. If you do not have a value for the arguments parameter, you may pass in null_value() or a "dummy" SQL::Arguments object as shown in the example below:

dim opt as P 
dim dummyargs as SQL::arguments 
opt.filter = "city = 'London'"
report.preview("nw_customers", "PDF", "", "", "C:\test.pdf", .f., .f., dummyargs, opt)

This example shows how to use the order property.

dim opt as P 
opt.filter = "city = 'London'" 
opt.order = "contactname, desc"

The filter argument is added to the existing SQL SELECT statement's WHERE clause. If the existing SQL SELECT statement was select * from customers where customertype = 'retail', and you specified options.filter = "city = 'London'", the actual SQL for the report would be select * from customers where customertype = 'retail' AND city = 'London'.

The order argument replaces any existing ORDER clause in the SQL statement. If the original sql statement was select * from customers order by city, and you set options.order to contactname, desc, region, the resulting SQL for the report will be select * from customers order by contactname, desc, region.

Limitations

Desktop applications only.

See Also