Dim caption As String = "Example: GetPageImageSize"
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() + " with the dimensions [width = " + width.ToString() + ", height = " + height.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_GetPageImageSize.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: GetPageImageSize";
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() + " with the dimensions [width = " + width.ToString() + ", height = " + height.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_GetPageImageSize.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();