GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / SaveToFile Method / SaveToFile(String,PdfEncryption,String,String,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean) Method
The file path where the currently loaded PDF document will be saved. If the specified file already exists, it will be overwritten.

You are allowed to overwrite the currently opened PDF document only if the document has been loaded into memory setting the LoadInMemory parameter to true in the previously called LoadFromFile method.

A member of the PdfEncryption enumeration. The encryption algorithm you have to specify. This algorithm will be used to encrypt the PDF document according to other specified parameters.
The user (open) password as a string. You can set null value here or an empty string as well. The null value will alway be converted to an empty string. Please read more about passwords in the Remarks section.
The owner (permission, master) password as a string. You can set null value here or an empty string as well. The null value will always be converted to an empty string. Please read more about passwords in the Remarks section.
Allows the user to print the document, but possibly not at the highest quality level, see also PdfRightCanPrintFull. It is ignored if the EncryptionScheme parameter is set to PdfEncryption.PdfEncryptionNone.
Allows the user to copy or extract text and graphics from the document. It is ignored if the EncryptionScheme parameter is set to PdfEncryption.PdfEncryptionNone.
Allows the user to modify the document. It is ignored if the EncryptionScheme parameter is set to PdfEncryption.PdfEncryptionNone.
Allows the user to add annotations. It is ignored if the EncryptionScheme parameter is set to PdfEncryption.PdfEncryptionNone.
Allows the user to fill-in form fields. It works only with 128-bit encryption.
Enables copying or extracting for use with accessibility features. It works only with 128-bit encryption.
Allows the user to assemble the document. It works only with 128-bit encryption.
Allows high resolution printing of the document. It works only with 128-bit encryption.
Example





In This Topic
SaveToFile(String,PdfEncryption,String,String,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean) Method
In This Topic
Encrypts the currently loaded PDF document according to a specified encryption algorithm and saves it to a file according to a file path you have specified. Encryption process is not allowed for PDF/A compliant documents.

Please note that encrypted PDF files are always saved without using the packing mechanism. You can however use the standard compression process.

Please read more about the password and permissions security in the SetPassword method.

Syntax
'Declaration
 
Public Overloads Function SaveToFile( _
   ByVal FilePath As String, _
   ByVal EncryptionScheme As PdfEncryption, _
   ByVal UserPass As String, _
   ByVal OwnerPass As String, _
   ByVal CanPrint As Boolean, _
   ByVal CanCopy As Boolean, _
   ByVal CanModify As Boolean, _
   ByVal CanAddNotes As Boolean, _
   ByVal CanFillFields As Boolean, _
   ByVal CanCopyAccess As Boolean, _
   ByVal CanAssemble As Boolean, _
   ByVal CanPrintFull As Boolean _
) As GdPictureStatus
public GdPictureStatus SaveToFile( 
   string FilePath,
   PdfEncryption EncryptionScheme,
   string UserPass,
   string OwnerPass,
   bool CanPrint,
   bool CanCopy,
   bool CanModify,
   bool CanAddNotes,
   bool CanFillFields,
   bool CanCopyAccess,
   bool CanAssemble,
   bool CanPrintFull
)
public function SaveToFile( 
    FilePath: String;
    EncryptionScheme: PdfEncryption;
    UserPass: String;
    OwnerPass: String;
    CanPrint: Boolean;
    CanCopy: Boolean;
    CanModify: Boolean;
    CanAddNotes: Boolean;
    CanFillFields: Boolean;
    CanCopyAccess: Boolean;
    CanAssemble: Boolean;
    CanPrintFull: Boolean
): GdPictureStatus; 
public function SaveToFile( 
   FilePath : String,
   EncryptionScheme : PdfEncryption,
   UserPass : String,
   OwnerPass : String,
   CanPrint : boolean,
   CanCopy : boolean,
   CanModify : boolean,
   CanAddNotes : boolean,
   CanFillFields : boolean,
   CanCopyAccess : boolean,
   CanAssemble : boolean,
   CanPrintFull : boolean
) : GdPictureStatus;
public: GdPictureStatus SaveToFile( 
   string* FilePath,
   PdfEncryption EncryptionScheme,
   string* UserPass,
   string* OwnerPass,
   bool CanPrint,
   bool CanCopy,
   bool CanModify,
   bool CanAddNotes,
   bool CanFillFields,
   bool CanCopyAccess,
   bool CanAssemble,
   bool CanPrintFull
) 
public:
GdPictureStatus SaveToFile( 
   String^ FilePath,
   PdfEncryption EncryptionScheme,
   String^ UserPass,
   String^ OwnerPass,
   bool CanPrint,
   bool CanCopy,
   bool CanModify,
   bool CanAddNotes,
   bool CanFillFields,
   bool CanCopyAccess,
   bool CanAssemble,
   bool CanPrintFull
) 

Parameters

FilePath
The file path where the currently loaded PDF document will be saved. If the specified file already exists, it will be overwritten.

You are allowed to overwrite the currently opened PDF document only if the document has been loaded into memory setting the LoadInMemory parameter to true in the previously called LoadFromFile method.

EncryptionScheme
A member of the PdfEncryption enumeration. The encryption algorithm you have to specify. This algorithm will be used to encrypt the PDF document according to other specified parameters.
UserPass
The user (open) password as a string. You can set null value here or an empty string as well. The null value will alway be converted to an empty string. Please read more about passwords in the Remarks section.
OwnerPass
The owner (permission, master) password as a string. You can set null value here or an empty string as well. The null value will always be converted to an empty string. Please read more about passwords in the Remarks section.
CanPrint
Allows the user to print the document, but possibly not at the highest quality level, see also PdfRightCanPrintFull. It is ignored if the EncryptionScheme parameter is set to PdfEncryption.PdfEncryptionNone.
CanCopy
Allows the user to copy or extract text and graphics from the document. It is ignored if the EncryptionScheme parameter is set to PdfEncryption.PdfEncryptionNone.
CanModify
Allows the user to modify the document. It is ignored if the EncryptionScheme parameter is set to PdfEncryption.PdfEncryptionNone.
CanAddNotes
Allows the user to add annotations. It is ignored if the EncryptionScheme parameter is set to PdfEncryption.PdfEncryptionNone.
CanFillFields
Allows the user to fill-in form fields. It works only with 128-bit encryption.
CanCopyAccess
Enables copying or extracting for use with accessibility features. It works only with 128-bit encryption.
CanAssemble
Allows the user to assemble the document. It works only with 128-bit encryption.
CanPrintFull
Allows high resolution printing of the document. It works only with 128-bit encryption.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

We strongly recommend always checking this status first.

Remarks
Some basic rules for better understanding the use of the user and the owner passwords are:

1. A null password (or a password, that is not set) will always be converted to an empty string password.

2. If both the user password and the owner password are empty (or they are not set), the PDF document is unencrypted and you have full access to the document content. This is defined by the PDF specification.

3. If the user password is set (assuming not null or empty) and the owner password is not set, the PDF document in encrypted. You will have full access to the document content right after the decrypting your document with the correct user password. The owner password is set to the user password by default, see the PDF specification.

4. If the owner password is set (assuming not null or empty) and the user password is not set, the toolkit tells you that the PDF document is unencrypted. You can use the GetEncryptionScheme and the GetRight methods to correctly operate with the PDF document respecting the defined access permissions.

5. Both passwords can be different of course. The IsOwnerPassword method tells you, if the password you have set by the SetPassword method is the owner password or not.

6. If both the user password and the owner password are set (assuming not null or empty) and they are the same, we consider that the PDF document does not have the owner password. Your PDF document in encrypted and you will have full access to the document content after the decrypting it with the correct user (or the owner) password.

This method requires the PDF Processing component to run.

Example
How to encrypt and save the PDF document.
Dim caption As String = "Example: SaveToFile"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
    If gdpicturePDF.SaveToFile("encrypted.pdf", PdfEncryption.PdfEncryption40BitRC4, "user", "owner", False, False, False, False, False, False, False, False) = GdPictureStatus.OK Then
        MessageBox.Show("The encrypted file has been saved successfully.", caption)
        'Closing the current document.
        gdpicturePDF.CloseDocument()
        'Loading the encrypted file.
        If gdpicturePDF.LoadFromFile("encrypted.pdf", False) = GdPictureStatus.OK Then
            'Checking if the file is encrypted.
            Dim encrypted As Boolean = gdpicturePDF.IsEncrypted()
            MessageBox.Show("The encrypted file has been loaded successfully." + vbCrLf + " The IsEncrypted method returns: " + encrypted.ToString() + "    status: " + gdpicturePDF.GetStat().ToString(), caption)
        Else
            MessageBox.Show("The encrypted file has failed to load.", caption)
        End If
    Else
        MessageBox.Show("The encrypted file has failed to save.", caption)
    End If
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: SaveToFile";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
    if (gdpicturePDF.SaveToFile("encrypted.pdf", PdfEncryption.PdfEncryption40BitRC4, "user", "owner", false, false, false, false, false, false, false, false) == GdPictureStatus.OK)
    {
        MessageBox.Show("The encrypted file has been saved successfully.", caption);
        //Closing the current document.
        gdpicturePDF.CloseDocument();
        //Loading the encrypted file.
        if (gdpicturePDF.LoadFromFile("encrypted.pdf", false) == GdPictureStatus.OK)
        {
            //Checking if the file is encrypted.
            bool encrypted = gdpicturePDF.IsEncrypted();
            MessageBox.Show("The encrypted file has been loaded successfully.\n The IsEncrypted method returns: " + encrypted.ToString() + "    status: " + gdpicturePDF.GetStat().ToString(), caption);
        }
        else
        {
            MessageBox.Show("The encrypted file has failed to load.", caption);
        }
    }
    else
    {
        MessageBox.Show("The encrypted file has failed to save.", caption);
    }
}
else
{
    MessageBox.Show("The file can't be loaded.", caption);
}
gdpicturePDF.Dispose();
See Also