GdPicture14 Namespace
/
GdPicturePDF Class
/
SaveToStream Method
/ SaveToStream(Stream,PdfEncryption,String,String,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean) Method
SaveToStream(Stream,PdfEncryption,String,String,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean) Method
In This Topic
Encrypts the currently loaded PDF document according to the specified encryption algorithm and saves it to an instantiated Stream object according to what you have specified. Encryption process is not allowed for PDF/A compliant documents.
Please read more about the password and permissions security in the GdPicturePDF.SetPassword method.
Syntax
'Declaration
Public Overloads Function SaveToStream( _
ByVal As Stream, _
ByVal As PdfEncryption, _
ByVal As String, _
ByVal As String, _
ByVal As Boolean, _
ByVal As Boolean, _
ByVal As Boolean, _
ByVal As Boolean, _
ByVal As Boolean, _
ByVal As Boolean, _
ByVal As Boolean, _
ByVal As Boolean _
) As GdPictureStatus
public GdPictureStatus SaveToStream(
Stream ,
PdfEncryption ,
string ,
string ,
bool ,
bool ,
bool ,
bool ,
bool ,
bool ,
bool ,
bool
)
public function SaveToStream(
: Stream;
: PdfEncryption;
: String;
: String;
: Boolean;
: Boolean;
: Boolean;
: Boolean;
: Boolean;
: Boolean;
: Boolean;
: Boolean
): GdPictureStatus;
public function SaveToStream(
: Stream,
: PdfEncryption,
: String,
: String,
: boolean,
: boolean,
: boolean,
: boolean,
: boolean,
: boolean,
: boolean,
: boolean
) : GdPictureStatus;
public: GdPictureStatus SaveToStream(
Stream* ,
PdfEncryption ,
string* ,
string* ,
bool ,
bool ,
bool ,
bool ,
bool ,
bool ,
bool ,
bool
)
public:
GdPictureStatus SaveToStream(
Stream^ ,
PdfEncryption ,
String^ ,
String^ ,
bool ,
bool ,
bool ,
bool ,
bool ,
bool ,
bool ,
bool
)
Parameters
- Stream
- A Stream object where the currently loaded PDF document will be saved to. This Stream object must be initialized before it can be sent into this method and it should remain open for subsequent use.
- EncryptionScheme
- A member of the PdfEncryption enumeration. The encryption algorithm you have to specify. This algorithm will be used to encrypt your 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.
Example
How to encrypt and save the PDF document to a stream.
Dim caption As String = "Example: SaveToStream"
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = GdPictureStatus.OK
If gdpicturePDF.LoadFromFile("testPDF.pdf", False) = GdPictureStatus.OK Then
Dim oFileStream As New System.IO.FileStream("encryptedStream.pdf", System.IO.FileMode.Create)
'Encrypting and saving the document to a stream.
status = gdpicturePDF.SaveToStream(oFileStream, PdfEncryption.PdfEncryption256BitAES, "user", "owner", False, False, False, False, False, False, False, False)
If status = GdPictureStatus.OK Then
MessageBox.Show("The encrypted file has been saved successfully.", caption)
'Closing the current file.
gdpicturePDF.CloseDocument()
oFileStream.Dispose()
oFileStream = New System.IO.FileStream("encryptedStream.pdf", System.IO.FileMode.Open)
'Loading the encrypted document.
status = gdpicturePDF.LoadFromStream(oFileStream)
If status = GdPictureStatus.OK Then
Dim encrypted As Boolean = gdpicturePDF.IsEncrypted()
status = gdpicturePDF.GetStat()
MessageBox.Show("The encrypted file has been loaded successfully." + vbCrLf + "The IsEncrypted method returns: " + encrypted.ToString() + " status: " + status.ToString(), caption)
Else
MessageBox.Show("The encrypted file has failed to load.", caption)
End If
oFileStream.Dispose()
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: SaveToStream";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = GdPictureStatus.OK;
if (gdpicturePDF.LoadFromFile("testPDF.pdf", false) == GdPictureStatus.OK)
{
System.IO.FileStream oFileStream = new System.IO.FileStream("encryptedStream.pdf", System.IO.FileMode.Create);
//Encrypting and saving the document to a stream.
status = gdpicturePDF.SaveToStream(oFileStream, PdfEncryption.PdfEncryption256BitAES, "user", "owner", false, false, false, false, false, false, false, false);
if (status == GdPictureStatus.OK)
{
MessageBox.Show("The encrypted file has been saved successfully.", caption);
//Closing the current file.
gdpicturePDF.CloseDocument();
oFileStream.Dispose();
oFileStream = new System.IO.FileStream("encryptedStream.pdf", System.IO.FileMode.Open);
//Loading the encrypted document.
status = gdpicturePDF.LoadFromStream(oFileStream);
if (status == GdPictureStatus.OK)
{
bool encrypted = gdpicturePDF.IsEncrypted();
status = gdpicturePDF.GetStat();
MessageBox.Show("The encrypted file has been loaded successfully.\nThe IsEncrypted method returns: " + encrypted.ToString() + " status: " + status.ToString(), caption);
}
else
{
MessageBox.Show("The encrypted file has failed to load.", caption);
}
oFileStream.Dispose();
}
else
{
MessageBox.Show("The encrypted file has failed to save.", caption);
}
}
else
{
MessageBox.Show("The file can't be loaded.", caption);
}
gdpicturePDF.Dispose();
Example
How to encrypt and save the PDF document to a stream.
Dim caption As String = "Example: SaveToStream"
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = GdPictureStatus.OK
If gdpicturePDF.LoadFromFile("testPDF.pdf", False) = GdPictureStatus.OK Then
Dim oFileStream As New System.IO.FileStream("encryptedStream.pdf", System.IO.FileMode.Create)
'Encrypting and saving the document to a stream.
status = gdpicturePDF.SaveToStream(oFileStream, PdfEncryption.PdfEncryption256BitAES, "user", "owner", False, False, False, False, False, False, False, False)
If status = GdPictureStatus.OK Then
MessageBox.Show("The encrypted file has been saved successfully.", caption)
'Closing the current file.
gdpicturePDF.CloseDocument()
oFileStream.Dispose()
oFileStream = New System.IO.FileStream("encryptedStream.pdf", System.IO.FileMode.Open)
'Loading the encrypted document.
status = gdpicturePDF.LoadFromStream(oFileStream)
If status = GdPictureStatus.OK Then
Dim encrypted As Boolean = gdpicturePDF.IsEncrypted()
status = gdpicturePDF.GetStat()
MessageBox.Show("The encrypted file has been loaded successfully." + vbCrLf + "The IsEncrypted method returns: " + encrypted.ToString() + " status: " + status.ToString(), caption)
Else
MessageBox.Show("The encrypted file has failed to load.", caption)
End If
oFileStream.Dispose()
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: SaveToStream";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = GdPictureStatus.OK;
if (gdpicturePDF.LoadFromFile("testPDF.pdf", false) == GdPictureStatus.OK)
{
System.IO.FileStream oFileStream = new System.IO.FileStream("encryptedStream.pdf", System.IO.FileMode.Create);
//Encrypting and saving the document to a stream.
status = gdpicturePDF.SaveToStream(oFileStream, PdfEncryption.PdfEncryption256BitAES, "user", "owner", false, false, false, false, false, false, false, false);
if (status == GdPictureStatus.OK)
{
MessageBox.Show("The encrypted file has been saved successfully.", caption);
//Closing the current file.
gdpicturePDF.CloseDocument();
oFileStream.Dispose();
oFileStream = new System.IO.FileStream("encryptedStream.pdf", System.IO.FileMode.Open);
//Loading the encrypted document.
status = gdpicturePDF.LoadFromStream(oFileStream);
if (status == GdPictureStatus.OK)
{
bool encrypted = gdpicturePDF.IsEncrypted();
status = gdpicturePDF.GetStat();
MessageBox.Show("The encrypted file has been loaded successfully.\nThe IsEncrypted method returns: " + encrypted.ToString() + " status: " + status.ToString(), caption);
}
else
{
MessageBox.Show("The encrypted file has failed to load.", caption);
}
oFileStream.Dispose();
}
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
Reference
GdPicturePDF Class
GdPicturePDF Members
Overload List
SetPassword Method
SaveToFile(String,PdfEncryption,String,String,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean) Method
SaveToFile(String) Method
LoadFromFile Method
LoadFromStream Method
EnableCompression Method
RemoveUnusedResources Method
Dispose Method
IsEncrypted Method
SetPassword Method