Dim caption As String = "Example: AddImageFromGdPictureImage"
Dim gdpictureImaging As New GdPictureImaging()
Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("image.tif")
If gdpictureImaging.GetStat() = GdPictureStatus.OK Then
Dim width As Double = gdpictureImaging.GetWidthInches(imageID)
Dim draw As Boolean = (gdpictureImaging.GetStat() <> GdPictureStatus.OK)
Dim height As Double = gdpictureImaging.GetHeightInches(imageID)
draw = draw OrElse (gdpictureImaging.GetStat() <> GdPictureStatus.OK)
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", True) = GdPictureStatus.OK Then
Dim imageResName As String = ""
If draw Then
'The original width or the height of the image can't be found, so
'the image is drawn directly on the whole surface of the newly added page and
'the dimensions of the page are the same as the original dimensions of the image.
imageResName = gdpicturePDF.AddImageFromGdPictureImage(imageID, False, True)
If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
MessageBox.Show("The AddImageFromGdPictureImage() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
'The original width or the height of the image has been found correctly, so
'the image is added into the document, but it is not drawn directly.
imageResName = gdpicturePDF.AddImageFromGdPictureImage(imageID, False, False)
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
'The image is drawn retaining its original size onto the newly added page according to your preferences.
If (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) <> GdPictureStatus.OK) OrElse
(gdpicturePDF.DrawImage(imageResName, 0, 0, CSng(width), CSng(height)) <> GdPictureStatus.OK) Then
MessageBox.Show("The NewPage() or the DrawImage() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
Else
MessageBox.Show("The AddImageFromGdPictureImage() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
End If
gdpictureImaging.ReleaseGdPictureImage(imageID)
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
'The document is overwritten.
If gdpicturePDF.SaveToFile("test.pdf", True) = GdPictureStatus.OK Then
MessageBox.Show("The example has been followed successfully and the file has been saved.", caption)
Else
MessageBox.Show("The example has been followed successfully, but the file can't be saved. Status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
End If
Else
MessageBox.Show("The LoadFromFile() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
End If
gdpicturePDF.Dispose()
Else
MessageBox.Show("The CreateGdPictureImageFromFile() method has failed with the status: " + gdpictureImaging.GetStat().ToString(), caption)
End If
gdpictureImaging.Dispose()
string caption = "Example: AddImageFromGdPictureImage";
GdPictureImaging gdpictureImaging = new GdPictureImaging();
int imageID = gdpictureImaging.CreateGdPictureImageFromFile("image.tif");
if (gdpictureImaging.GetStat() == GdPictureStatus.OK)
{
double width = gdpictureImaging.GetWidthInches(imageID);
Boolean draw = (gdpictureImaging.GetStat() != GdPictureStatus.OK);
double height = gdpictureImaging.GetHeightInches(imageID);
draw = draw || (gdpictureImaging.GetStat() != GdPictureStatus.OK);
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", true) == GdPictureStatus.OK)
{
string imageResName = "";
if (draw)
//The original width or the height of the image can't be found.
{
//The image is drawn directly on the whole surface of the newly added page and
//the dimensions of the page are the same as the original dimensions of the image.
imageResName = gdpicturePDF.AddImageFromGdPictureImage(imageID, false, true);
if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
MessageBox.Show("The AddImageFromGdPictureImage() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
else
//The original width or the height of the image has been found correctly.
{
//The image is added into the document, but it is not drawn directly.
imageResName = gdpicturePDF.AddImageFromGdPictureImage(imageID, false, false);
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
//The image is drawn retaining its original size onto the newly added page according to your preferences.
if ((gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) != GdPictureStatus.OK) ||
(gdpicturePDF.DrawImage(imageResName, 0, 0, (float)width, (float)height) != GdPictureStatus.OK))
MessageBox.Show("The NewPage() or the DrawImage() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
else
MessageBox.Show("The AddImageFromGdPictureImage() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
}
gdpictureImaging.ReleaseGdPictureImage(imageID);
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
//The document is overwritten.
if (gdpicturePDF.SaveToFile("test.pdf", true) == GdPictureStatus.OK)
MessageBox.Show("The example has been followed successfully and the file has been saved.", caption);
else
MessageBox.Show("The example has been followed successfully, but the file can't be saved. Status: " + gdpicturePDF.GetStat().ToString(), caption);
}
}
else
MessageBox.Show("The LoadFromFile() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
gdpicturePDF.Dispose();
}
else
MessageBox.Show("The CreateGdPictureImageFromFile() method has failed with the status: " + gdpictureImaging.GetStat().ToString(), caption);
gdpictureImaging.Dispose();