GetPageImageResName Method (GdPicturePDF)
In This Topic
Returns the resource name of an image, specified by its index within the currently selected page of the loaded PDF document. The returned resource
name is strictly bounded to the current document and can be only used inside this document, for example, when drawing etc.
Syntax
'Declaration
Public Function GetPageImageResName( _
ByVal As Integer _
) As String
public string GetPageImageResName(
int
)
public function GetPageImageResName(
: Integer
): String;
public function GetPageImageResName(
: int
) : String;
public: string* GetPageImageResName(
int
)
public:
String^ GetPageImageResName(
int
)
Parameters
- ImageIdx
- The 0-based index of the image within the current page. It must be a value from 0 to GdPicturePDF.GetPageImageCount-1.
Return Value
The resource name of the image. The
GdPicturePDF.GetStat method can be subsequently used to determine if this method has been successful.
Example
How to redraw all images from the first page of the PDF document to one image per new page within the same document using the image resource name.
Dim caption As String = "Example: GetPageImageResName"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
Dim pageCount As Integer = gdpicturePDF.GetPageCount()
Dim status As GdPictureStatus = gdpicturePDF.GetStat()
If (status = GdPictureStatus.OK) AndAlso (pageCount > 0) Then
'The first page is automatically selected as the current page.
Dim imageCount As Integer = gdpicturePDF.GetPageImageCount()
status = gdpicturePDF.GetStat()
If (status = GdPictureStatus.OK) AndAlso (imageCount > 0) Then
Dim message As String = ""
Dim imageResName As String = ""
Dim width As Integer = 0, height As Integer = 0
For i As Integer = 0 To imageCount - 1
imageResName = gdpicturePDF.GetPageImageResName(i)
status = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
If (gdpicturePDF.GetPageImageSize(i, width, height) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.DrawImage(imageResName, 0, 0, width, height) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SelectPage(1) = GdPictureStatus.OK) Then
'We need to move again to the page nr.1 because the newly added page is selected after drawing.
message = message + "The image indexed as " + i.ToString() + " has been drawn successfully." + vbCrLf
Else
message = message + "The image indexed as " + i.ToString() + " has failed to draw with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
End If
Else
message = message + "The GetPageImageResName() method has failed with the status: " + status.ToString()
End If
Next
If gdpicturePDF.SaveToFile("test_GetPageImageResName.pdf") = GdPictureStatus.OK Then
message = message + "The file has been saved successfully."
Else
message = message + "The file has not been saved successfully."
End If
MessageBox.Show(message, caption)
Else
If status = GdPictureStatus.OK Then
MessageBox.Show("The first page doesn't contain any image.", caption)
Else
MessageBox.Show("The GetPageImageCount() method has failed with the status: " + status.ToString(), caption)
End If
End If
Else
If status = GdPictureStatus.OK Then
MessageBox.Show("This file doesn't contain any page.", caption)
Else
MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption)
End If
End If
Else
MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetPageImageResName";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
int pageCount = gdpicturePDF.GetPageCount();
GdPictureStatus status = gdpicturePDF.GetStat();
if ((status == GdPictureStatus.OK) && (pageCount > 0))
{
//The first page is automatically selected as the current page.
int imageCount = gdpicturePDF.GetPageImageCount();
status = gdpicturePDF.GetStat();
if ((status == GdPictureStatus.OK) && (imageCount > 0))
{
string message = "";
string imageResName = "";
int width = 0, height = 0;
for (int i = 0; i < imageCount; i++)
{
imageResName = gdpicturePDF.GetPageImageResName(i);
status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
{
if ((gdpicturePDF.GetPageImageSize(i, ref width, ref height) == GdPictureStatus.OK) &&
(gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK) &&
(gdpicturePDF.DrawImage(imageResName, 0, 0, width, height) == GdPictureStatus.OK) &&
(gdpicturePDF.SelectPage(1) == GdPictureStatus.OK))
{
//We need to move again to the page nr.1 because the newly added page is selected after drawing.
message = message + "The image indexed as " + i.ToString() + " has been drawn successfully.\n";
}
else
message = message + "The image indexed as " + i.ToString() + " has failed to draw with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
}
else
message = message + "The GetPageImageResName() method has failed with the status: " + status.ToString();
}
if (gdpicturePDF.SaveToFile("test_GetPageImageResName.pdf") == GdPictureStatus.OK)
message = message + "The file has been saved successfully.";
else
message = message + "The file has not been saved successfully.";
MessageBox.Show(message, caption);
}
else
{
if (status == GdPictureStatus.OK)
MessageBox.Show("The first page doesn't contain any image.", caption);
else
MessageBox.Show("The GetPageImageCount() method has failed with the status: " + status.ToString(), caption);
}
}
else
{
if (status == GdPictureStatus.OK)
MessageBox.Show("This file doesn't contain any page.", caption);
else
MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption);
}
}
else
MessageBox.Show("The file can't be loaded.", caption);
gdpicturePDF.Dispose();
Example
How to redraw all images from the first page of the PDF document to one image per new page within the same document using the image resource name.
Dim caption As String = "Example: GetPageImageResName"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
Dim pageCount As Integer = gdpicturePDF.GetPageCount()
Dim status As GdPictureStatus = gdpicturePDF.GetStat()
If (status = GdPictureStatus.OK) AndAlso (pageCount > 0) Then
'The first page is automatically selected as the current page.
Dim imageCount As Integer = gdpicturePDF.GetPageImageCount()
status = gdpicturePDF.GetStat()
If (status = GdPictureStatus.OK) AndAlso (imageCount > 0) Then
Dim message As String = ""
Dim imageResName As String = ""
Dim width As Integer = 0, height As Integer = 0
For i As Integer = 0 To imageCount - 1
imageResName = gdpicturePDF.GetPageImageResName(i)
status = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
If (gdpicturePDF.GetPageImageSize(i, width, height) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.DrawImage(imageResName, 0, 0, width, height) = GdPictureStatus.OK) AndAlso
(gdpicturePDF.SelectPage(1) = GdPictureStatus.OK) Then
'We need to move again to the page nr.1 because the newly added page is selected after drawing.
message = message + "The image indexed as " + i.ToString() + " has been drawn successfully." + vbCrLf
Else
message = message + "The image indexed as " + i.ToString() + " has failed to draw with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
End If
Else
message = message + "The GetPageImageResName() method has failed with the status: " + status.ToString()
End If
Next
If gdpicturePDF.SaveToFile("test_GetPageImageResName.pdf") = GdPictureStatus.OK Then
message = message + "The file has been saved successfully."
Else
message = message + "The file has not been saved successfully."
End If
MessageBox.Show(message, caption)
Else
If status = GdPictureStatus.OK Then
MessageBox.Show("The first page doesn't contain any image.", caption)
Else
MessageBox.Show("The GetPageImageCount() method has failed with the status: " + status.ToString(), caption)
End If
End If
Else
If status = GdPictureStatus.OK Then
MessageBox.Show("This file doesn't contain any page.", caption)
Else
MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption)
End If
End If
Else
MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetPageImageResName";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
int pageCount = gdpicturePDF.GetPageCount();
GdPictureStatus status = gdpicturePDF.GetStat();
if ((status == GdPictureStatus.OK) && (pageCount > 0))
{
//The first page is automatically selected as the current page.
int imageCount = gdpicturePDF.GetPageImageCount();
status = gdpicturePDF.GetStat();
if ((status == GdPictureStatus.OK) && (imageCount > 0))
{
string message = "";
string imageResName = "";
int width = 0, height = 0;
for (int i = 0; i < imageCount; i++)
{
imageResName = gdpicturePDF.GetPageImageResName(i);
status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
{
if ((gdpicturePDF.GetPageImageSize(i, ref width, ref height) == GdPictureStatus.OK) &&
(gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK) &&
(gdpicturePDF.DrawImage(imageResName, 0, 0, width, height) == GdPictureStatus.OK) &&
(gdpicturePDF.SelectPage(1) == GdPictureStatus.OK))
{
//We need to move again to the page nr.1 because the newly added page is selected after drawing.
message = message + "The image indexed as " + i.ToString() + " has been drawn successfully.\n";
}
else
message = message + "The image indexed as " + i.ToString() + " has failed to draw with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
}
else
message = message + "The GetPageImageResName() method has failed with the status: " + status.ToString();
}
if (gdpicturePDF.SaveToFile("test_GetPageImageResName.pdf") == GdPictureStatus.OK)
message = message + "The file has been saved successfully.";
else
message = message + "The file has not been saved successfully.";
MessageBox.Show(message, caption);
}
else
{
if (status == GdPictureStatus.OK)
MessageBox.Show("The first page doesn't contain any image.", caption);
else
MessageBox.Show("The GetPageImageCount() method has failed with the status: " + status.ToString(), caption);
}
}
else
{
if (status == GdPictureStatus.OK)
MessageBox.Show("This file doesn't contain any page.", caption);
else
MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption);
}
}
else
MessageBox.Show("The file can't be loaded.", caption);
gdpicturePDF.Dispose();
See Also