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
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.
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");
}
}
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