GdPicture.NET.14
GdPicture14 Namespace / GdPictureDocumentConverter Class / SaveAsPDF Method / SaveAsPDF(Stream,PdfConformance) Method
A stream object where the current document is saved to as a PDF document. This output stream must be initialized before it can be sent into this method and it should stay open for subsequent use.

If the output stream is not opened for writing, the method will fail returning the GdPictureStatus.InvalidParameter status.

A member of the PdfConformance enumeration. Specifies the required conformance to the PDF or PDF/A standard of the saved PDF document.

You can use the value of the PdfConformance.PDF to save the file as a common PDF document.

Example





In This Topic
SaveAsPDF(Stream,PdfConformance) Method
In This Topic
This method converts and saves (in other words, creates a brand new destination document) the currently loaded document to an instantiated stream object according to what you have specified. The output document format is PDF.

The PDF conformance level of the saved PDF document is set according to the parameter specified by you.

Syntax
'Declaration
 
Public Overloads Function SaveAsPDF( _
   ByVal Stream As Stream, _
   Optional ByVal Conformance As PdfConformance _
) As GdPictureStatus
public GdPictureStatus SaveAsPDF( 
   Stream Stream,
   PdfConformance Conformance
)
public function SaveAsPDF( 
    Stream: Stream;
    Conformance: PdfConformance
): GdPictureStatus; 
public function SaveAsPDF( 
   Stream : Stream,
   Conformance : PdfConformance
) : GdPictureStatus;
public: GdPictureStatus SaveAsPDF( 
   Stream* Stream,
   PdfConformance Conformance
) 
public:
GdPictureStatus SaveAsPDF( 
   Stream^ Stream,
   PdfConformance Conformance
) 

Parameters

Stream
A stream object where the current document is saved to as a PDF document. This output stream must be initialized before it can be sent into this method and it should stay open for subsequent use.

If the output stream is not opened for writing, the method will fail returning the GdPictureStatus.InvalidParameter status.

Conformance
A member of the PdfConformance enumeration. Specifies the required conformance to the PDF or PDF/A standard of the saved PDF document.

You can use the value of the PdfConformance.PDF to save the file as a common PDF document.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.
Remarks
Keep noted that the output stream should be open for writing and should be closed/disposed by the user as well.

If you use the value of the PdfConformance.PDF, the library will create the PDF document conformed to the lowest PDF version (version 1.3 is the minimum) based on what the output PDF document will contain.

para>
Example
Converting and saving a JPEG image to a single PDF document using a stream.
Using gdpictureDocumentConverter As New GdPictureDocumentConverter()
    Dim status As GdPictureStatus = gdpictureDocumentConverter.LoadFromFile("image.jpg", GdPicture14.DocumentFormat.DocumentFormatJPEG)
    If status = GdPictureStatus.OK Then
        MessageBox.Show("The file has been loaded successfully.", "GdPicture")
        gdpictureDocumentConverter.PdfImageQuality = 50
        Dim oFileStream As New System.IO.FileStream("output.pdf", System.IO.FileMode.Create)
        status = gdpictureDocumentConverter.SaveAsPDF(oFileStream, PdfConformance.PDF)
        If status = GdPictureStatus.OK Then
            MessageBox.Show("The file has been saved successfully.", "GdPicture")
        Else
            MessageBox.Show("The file has failed to save. Status: " + status.ToString(), "GdPicture")
        End If
        oFileStream.Dispose()
    Else
        MessageBox.Show("The file has failed to load. Status: " + status.ToString(), "GdPicture")
    End If
End Using
using (GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter())
{
    GdPictureStatus status = gdpictureDocumentConverter.LoadFromFile("image.jpg", GdPicture14.DocumentFormat.DocumentFormatJPEG);
    if (status == GdPictureStatus.OK)
    {
        MessageBox.Show("The file has been loaded successfully.", "GdPicture");
        gdpictureDocumentConverter.PdfImageQuality = 50;
        System.IO.FileStream oFileStream = new System.IO.FileStream("output.pdf", System.IO.FileMode.Create);
        status = gdpictureDocumentConverter.SaveAsPDF(oFileStream, PdfConformance.PDF);
        if (status == GdPictureStatus.OK)
        {
            MessageBox.Show("The file has been saved successfully.", "GdPicture");
        }
        else
        {
            MessageBox.Show("The file has failed to save. Status: " + status.ToString(), "GdPicture");
        }
        oFileStream.Dispose();
    }
    else
    {
        MessageBox.Show("The file has failed to load. Status: " + status.ToString(), "GdPicture");
    }
}
See Also