Description
Saves the contents in a RichTextEdit control as a PDF document.
Applies to
RichTextEdit controls
Syntax
rtename.SaveDocumentAsPDF(string filePathName{, string standard{, string userPassword, string masterPassword{, string restrictions}}})
Argument |
Description |
---|---|
rtename |
The name of the RichTextEdit control in which you want to save the contents as a PDF document. |
filePathName |
A string whose value is the name of the document to be saved (including the file path). Make sure you have write permission to the directory specified by the filePathName argument. Otherwise, the document will fail to be saved or be saved in %LocalAppData%\VirtualStore (the behavior of OS). |
standard (optional) |
The format indicating the level of PDF conformance. Values are:
Note: Only the values of "0" and "2" are supported now. |
userPassword (optional) |
A password that enables you to open the generated PDF document. The userPassword argument can be set as an empty string, so you can open the document without any password. If userPassword is a non-empty string, you must also set masterPassword as a non-empty string. The user password and the master password cannot be the same, otherwise this function will fail. |
masterPassword (optional) |
A password that enables you to restrict the permissions of the generated PDF document. You can set the permissions by the restrictions argument. If masterPassword is an empty string, the restrictions argument will be ignored and no actions (copy/print/edit/etc.) will be restricted. |
restrictions (optional) |
The permission settings that enable you to restrict certain actions (such as copying/printing/editing) of a PDF document. One or more of the following string values can be contained (multiple strings are separated by ","). You can set the restrictions argument as an empty string. In this case, if masterPassword is valid, all permissions will be restricted, and if the masterPassword is invalid, the permissions will not be restricted.
Note: If standard is set to "2" - PDF/A-1b, the three arguments (userPassword, masterPassword, restrictions) will be ignored. The PDF document will be saved using PDF/A-1b standard and will be opened without any password. |
Return value
Integer.
Returns 1 for success and the following values for failure. If any argument's value is null, returns null.
-1 -- Failed for unknown reasons
-2 -- The standard argument is not compatible with the PDF/A conformance
-3 -- The userPassword argument is set while the masterPassword argument is not
-4 -- Both userPassword and masterPassword are non-null values but the same
Usage
The SaveDocument function supports exporting data to PDF documents in PDF standard, but does not support setting the passwords and restrictions of the PDF document; however, the SaveDocumentAsPDF function supports exporting data to PDF documents in both PDF and PDF/A standards, and supports setting the passwords and restrictions.
The following two lines of code are equivalent:
rte.SaveDocument("C:\test.pdf", FileTypePDF!)
rte.SaveDocumentAsPDF("C:\test.pdf")
To have a deep understanding of the SaveDocumentAsPDF function, you can refer to the following properties in DataWindow objects.
Export.PDF.NativePDF.UserPassword
Export.PDF.NativePDF.MasterPassword
Export.PDF.NativePDF.Restrictions
The basic rules do not change a lot, except for one difference. If the userPassword argument is set while the masterPassword argument is not, the PDF document will be saved successfully by using the SaveAs function in DataWindow and all passwords will be ignored. However, if you use the SaveDocumentAsPDF function, the PDF document will fail to be saved.
Examples
This example saves the contents of the RichTextEdit rte_1 to a PDF document called test.pdf:
integer li_rtn li_rtn = rte_1.SaveDocumentAsPDF("c:\pbtest\test.pdf")
This example exports PDF using PDF/A-1b standard, and saves the contents of the RichTextEdit rte_1 to a document called test.pdf:
integer li_rtn li_rtn = rte_1.SaveDocumentAsPDF("c:\pbtest\test.pdf","2")
This example sets the userPassword and the masterPassword, and saves the contents to a document called test.pdf:
integer li_rtn li_rtn = rte_1.SaveDocumentAsPDF("c:\pbtest\test.pdf","0","test","admini123")
This example prevents the PDF document being printed and copied, sets the userPassword and the masterPassword, and saves the contents to a document called test.pdf:
integer li_rtn li_rtn = rte_1.SaveDocumentAsPDF("c:\pbtest\test.pdf","0","test","admini123","noprint!,nocopy!")
See also