The file path of the source image. Supported file format is JPEG (jpg, jpeg, jpe ...). Please note that the files of larger size than 2GB are not supported.
Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / AddJpegImageFromFile Method

AddJpegImageFromFile Method (GdPicturePDF)

In This Topic
Creates an image resource directly from your JPEG image file without the need of lossy encoding and decoding process. The image resource is subsequently added into the currently loaded PDF document. You can use this resource straightforward, for example, with the DrawImage method. This process allows you to easily draw an image from your JPEG file onto a page within the currently loaded PDF document.
Syntax
'Declaration
 
Public Function AddJpegImageFromFile( _
   ByVal FilePath As String _
) As String
public string AddJpegImageFromFile( 
   string FilePath
)
public function AddJpegImageFromFile( 
    FilePath: String
): String; 
public function AddJpegImageFromFile( 
   FilePath : String
) : String;
public: string* AddJpegImageFromFile( 
   string* FilePath
) 
public:
String^ AddJpegImageFromFile( 
   String^ FilePath
) 

Parameters

FilePath
The file path of the source image. Supported file format is JPEG (jpg, jpeg, jpe ...). Please note that the files of larger size than 2GB are not supported.

Return Value

Returns a name of the newly created image resource strictly bounded to the currently loaded PDF document. The GetStat method can be subsequently used to determine if this method has been successful.

This name can be subsequently used with the DrawImage method to draw an image onto the page. For the correct usage please see the example below.

Remarks
This method is only allowed for use with non-encrypted documents.

It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any.

Example
How to draw a JPEG image from a file onto a new page and save it to a PDF file.
Dim caption As String = "Example: AddJpegImageFromFile"
Using gdpicturePDF As New GdPicturePDF()
    Dim status As GdPictureStatus = gdpicturePDF.NewPDF()
    If status = GdPictureStatus.OK Then
        Dim image_name As String = gdpicturePDF.AddJpegImageFromFile("image.jpg")
        status = gdpicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            status = gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4)
            If status <> GdPictureStatus.OK Then
                Return
            End If
            gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginBottomLeft)
            gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)
            status = gdpicturePDF.DrawImage(image_name, 0, 0, 210, 297)
            If status <> GdPictureStatus.OK Then
                Return
            End If
            status = gdpicturePDF.SaveToFile("Test_AddJpegImage.pdf")
            If status = GdPictureStatus.OK Then
                MessageBox.Show("Your image has been successfully saved to a pdf file.", caption)
            Else
                MessageBox.Show("The file can't be saved. Status: " + status.ToString(), caption)
            End If
        Else
            MessageBox.Show("The AddJpegImageFromFile() method has failed with the status: " + status.ToString(), caption)
        End If
    Else
        MessageBox.Show("The NewPDF() method has failed with the status: " + status.ToString(), caption)
    End If
End Using
string caption = "Example: AddJpegImageFromFile";
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
    GdPictureStatus status = gdpicturePDF.NewPDF();
    if (status == GdPictureStatus.OK)
    {
        string image_name = gdpicturePDF.AddJpegImageFromFile("image.jpg");
        status = gdpicturePDF.GetStat();
        if (status == GdPictureStatus.OK)
        {
            status = gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4);
            if (status != GdPictureStatus.OK) return;
            gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginBottomLeft);
            gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter);
            status = gdpicturePDF.DrawImage(image_name, 0, 0, 210, 297);
            if (status != GdPictureStatus.OK) return;
            status = gdpicturePDF.SaveToFile("Test_AddJpegImage.pdf");
            if (status == GdPictureStatus.OK)
            {
                MessageBox.Show("Your image has been successfully saved to a pdf file.", caption);
            }
            else
            {
                MessageBox.Show("The file can't be saved. Status: " + status.ToString(), caption);
            }
        }
        else
        {
            MessageBox.Show("The AddJpegImageFromFile() method has failed with the status: " + status.ToString(), caption);
        }
    }
    else
    {
        MessageBox.Show("The NewPDF() method has failed with the status: " + status.ToString(), caption);
    }
}
See Also