CreateThumbnailHQ(Int32,Int32,GdPictureColor) Method
In This Topic
Creates a custom sized high quality (HQ) thumbnail of the currently selected page of the loaded PDF document. The current page is converted to an image resource with the size and the background color you have specified, which is subsequently stored as an object of the type GdPictureImage. The created image is clearly recognizable by the returned unique image identifier and you can take advantages of the
GdPictureImaging class and its methods for further manipulation with the thumbnail.
Syntax
'Declaration
Public Overloads Function CreateThumbnailHQ( _
ByVal As Integer, _
ByVal As Integer, _
ByVal As GdPictureColor _
) As Integer
public int CreateThumbnailHQ(
int ,
int ,
GdPictureColor
)
public function CreateThumbnailHQ(
: Integer;
: Integer;
: GdPictureColor
): Integer;
public function CreateThumbnailHQ(
: int,
: int,
: GdPictureColor
) : int;
public: int CreateThumbnailHQ(
int ,
int ,
GdPictureColor
)
public:
int CreateThumbnailHQ(
int ,
int ,
GdPictureColor
)
Parameters
- Width
- The required width of the newly created thumbnail image, in pixels.
- Height
- The required height of the newly created thumbnail image, in pixels.
- BackColor
- A color object that defines the background color of the thumbnail's margins. The created thumbnail image includes predefined margin on both sides,
that is painted with the specified color.
Return Value
A unique image identifier of the GdPictureImage object representing the newly created thumbnail's image resource. The returned value is non-zero if the image is successfully created. Please first of all use the
GdPicturePDF.GetStat method to determine if this method has been successful.
Be aware that you need to release the image after being used, for the suitable method please refer to the Remarks section below.
Example
How to create page thumbnails for all pages of the PDF document.
Dim caption As String = "Example: CreateThumbnailHQ"
Dim gdpicturePDF As New GdPicturePDF()
Dim gdpictureImaging As New GdPictureImaging()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
Dim count As Integer = gdpicturePDF.GetPageCount()
Dim status As GdPictureStatus = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
Dim message As String = ""
Dim thumb_index As Integer = 0
Dim filename As String = "thumbnail_page0.png"
For i As Integer = 1 To count
status = gdpicturePDF.SelectPage(i)
If status = GdPictureStatus.OK Then
thumb_index = gdpicturePDF.CreateThumbnailHQ(300, 300, Color.Orange)
status = gdpicturePDF.GetStat()
If (status = GdPictureStatus.OK) AndAlso (thumb_index <> 0) Then
filename = filename.Replace((i - 1).ToString(), i.ToString())
status = gdpictureImaging.SaveAsPNG(thumb_index, filename)
If status = GdPictureStatus.OK Then
message = message + "The thumbnail of the page nr." + i.ToString() + " has been successfully saved." + vbCrLf
Else
message = message + "The SaveAsPNG() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + vbCrLf
End If
gdpictureImaging.ReleaseGdPictureImage(thumb_index)
'Or you can use this one:
'GdPictureDocumentUtilities.DisposeImage(thumb_index)
Else
message = message + "The CreateThumbnailHQ() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + vbCrLf
End If
Else
message = message + "The SelectPage() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + vbCrLf
End If
Next
MessageBox.Show(message, caption)
Else
MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption)
End If
Else
MessageBox.Show("The file can't be loaded.", caption)
End If
gdpictureImaging.Dispose()
gdpicturePDF.Dispose()
string caption = "Example: CreateThumbnailHQ";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureImaging gdpictureImaging = new GdPictureImaging();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
int count = gdpicturePDF.GetPageCount();
GdPictureStatus status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
{
string message = "";
int thumb_index = 0;
string filename = "thumbnail_page0.png";
for (int i = 1; i <= count; i++)
{
status = gdpicturePDF.SelectPage(i);
if (status == GdPictureStatus.OK)
{
thumb_index = gdpicturePDF.CreateThumbnailHQ(300, 300, Color.Orange);
status = gdpicturePDF.GetStat();
if ((status == GdPictureStatus.OK) && (thumb_index != 0))
{
filename = filename.Replace((i - 1).ToString(), i.ToString());
status = gdpictureImaging.SaveAsPNG(thumb_index, filename);
if (status == GdPictureStatus.OK)
message = message + "The thumbnail of the page nr." + i.ToString() + " has been successfully saved.\n";
else
message = message + "The SaveAsPNG() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + "\n";
gdpictureImaging.ReleaseGdPictureImage(thumb_index);
//Or you can use this one:
//GdPictureDocumentUtilities.DisposeImage(thumb_index);
}
else
message = message + "The CreateThumbnailHQ() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + "\n";
}
else
message = message + "The SelectPage() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + "\n";
}
MessageBox.Show(message, 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);
gdpictureImaging.Dispose();
gdpicturePDF.Dispose();
Example
How to create page thumbnails for all pages of the PDF document.
Dim caption As String = "Example: CreateThumbnailHQ"
Dim gdpicturePDF As New GdPicturePDF()
Dim gdpictureImaging As New GdPictureImaging()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
Dim count As Integer = gdpicturePDF.GetPageCount()
Dim status As GdPictureStatus = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
Dim message As String = ""
Dim thumb_index As Integer = 0
Dim filename As String = "thumbnail_page0.png"
For i As Integer = 1 To count
status = gdpicturePDF.SelectPage(i)
If status = GdPictureStatus.OK Then
thumb_index = gdpicturePDF.CreateThumbnailHQ(300, 300, Color.Orange)
status = gdpicturePDF.GetStat()
If (status = GdPictureStatus.OK) AndAlso (thumb_index <> 0) Then
filename = filename.Replace((i - 1).ToString(), i.ToString())
status = gdpictureImaging.SaveAsPNG(thumb_index, filename)
If status = GdPictureStatus.OK Then
message = message + "The thumbnail of the page nr." + i.ToString() + " has been successfully saved." + vbCrLf
Else
message = message + "The SaveAsPNG() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + vbCrLf
End If
gdpictureImaging.ReleaseGdPictureImage(thumb_index)
'Or you can use this one:
'GdPictureDocumentUtilities.DisposeImage(thumb_index)
Else
message = message + "The CreateThumbnailHQ() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + vbCrLf
End If
Else
message = message + "The SelectPage() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + vbCrLf
End If
Next
MessageBox.Show(message, caption)
Else
MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption)
End If
Else
MessageBox.Show("The file can't be loaded.", caption)
End If
gdpictureImaging.Dispose()
gdpicturePDF.Dispose()
string caption = "Example: CreateThumbnailHQ";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureImaging gdpictureImaging = new GdPictureImaging();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
int count = gdpicturePDF.GetPageCount();
GdPictureStatus status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
{
string message = "";
int thumb_index = 0;
string filename = "thumbnail_page0.png";
for (int i = 1; i <= count; i++)
{
status = gdpicturePDF.SelectPage(i);
if (status == GdPictureStatus.OK)
{
thumb_index = gdpicturePDF.CreateThumbnailHQ(300, 300, Color.Orange);
status = gdpicturePDF.GetStat();
if ((status == GdPictureStatus.OK) && (thumb_index != 0))
{
filename = filename.Replace((i - 1).ToString(), i.ToString());
status = gdpictureImaging.SaveAsPNG(thumb_index, filename);
if (status == GdPictureStatus.OK)
message = message + "The thumbnail of the page nr." + i.ToString() + " has been successfully saved.\n";
else
message = message + "The SaveAsPNG() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + "\n";
gdpictureImaging.ReleaseGdPictureImage(thumb_index);
//Or you can use this one:
//GdPictureDocumentUtilities.DisposeImage(thumb_index);
}
else
message = message + "The CreateThumbnailHQ() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + "\n";
}
else
message = message + "The SelectPage() method has failed for the page nr." + i.ToString() + " with the status: " + status.ToString() + "\n";
}
MessageBox.Show(message, 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);
gdpictureImaging.Dispose();
gdpicturePDF.Dispose();
See Also