GetRegionWidthPixels Method (GdViewer)
In This Topic
Gets the width of the highlighted region's rectangle, in pixels, related to the actual document (meaning the document pages area). The highlighted region is specified by its unique identifier related to the document currently displayed in the GdViewer control. These regions, if present, determines the currently defined highlighted regions on the displayed document.
You can define the width of the region's rectangle when adding regions using AddRegion(String,Int32,Int32,Int32,Int32,ForegroundMixMode,Int32) or AddRegionInches(String,Single,Single,Single,Single,ForegroundMixMode,Int32) methods or directly using the SetRegionWidthPixels method.
Syntax
'Declaration
Public Function GetRegionWidthPixels( _
ByVal As Integer _
) As Integer
public int GetRegionWidthPixels(
int
)
public function GetRegionWidthPixels(
: Integer
): Integer;
public function GetRegionWidthPixels(
: int
) : int;
public: int GetRegionWidthPixels(
int
)
public:
int GetRegionWidthPixels(
int
)
Parameters
- RegionID
- A unique region identifier of the specified region. You can obtain this identifier using the GetRegionID method or when creating regions using AddRegion(String,Int32,Int32,Int32,Int32,ForegroundMixMode,Int32) or AddRegionInches(String,Single,Single,Single,Single,ForegroundMixMode,Int32) methods.
Return Value
The width, in pixels, of the highlighted region's rectangle, related to the actual document. The
GetStat method can be subsequently used to determine if this method has been successful.
Example
How to draw a rectangle on the document's page according to the user's selection of the highlighted rectangle in the GdViewer control.
'We assume that the GdViewer1 control has been properly integrated
'and some PDF document is loaded and displayed as well.
'Here we make use of the RegionSelectedByUser event.
Sub GdViewer1_RegionSelectedByUser(ByVal RegionID As Integer)
Dim page As Integer = GdViewer1.GetRegionPage(RegionID)
'Converting pixels to PDF points.
Dim left As Integer = GdViewer1.GetRegionLeftPixels(RegionID) * 0.75
Dim top As Integer = GdViewer1.GetRegionTopPixels(RegionID) * 0.75
Dim width As Integer = GdViewer1.GetRegionWidthPixels(RegionID) * 0.75
Dim height As Integer = GdViewer1.GetRegionHeightPixels(RegionID) * 0.75
Using oPDF As GdPicturePDF = New GdPicturePDF()
If oPDF.LoadFromFile(GdViewer1.GetLastPath(), False) = GdPictureStatus.OK Then
oPDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitPoint)
oPDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
'Drawing a rectangle on the document's page according to the selected rectangle in the GdViewer1 control.
If (oPDF.SelectPage(page) = GdPictureStatus.OK) AndAlso
(oPDF.SetFillAlpha(150) = GdPictureStatus.OK) AndAlso
(oPDF.SetFillColor(0, 191, 255) = GdPictureStatus.OK) AndAlso
(oPDF.DrawRectangle(left, top, width, height, True, False) = GdPictureStatus.OK) Then
If oPDF.SaveToFile("test_region.pdf") = GdPictureStatus.OK Then
MessageBox.Show("The file has been saved successfully.", "GdViewer.GetRegionWidthPixels")
Else
MessageBox.Show("The file can't be saved. Status: " + oPDF.GetStat().ToString(), "GdViewer.GetRegionWidthPixels")
End If
Else
MessageBox.Show("The graphics operations have failed. Status: " + oPDF.GetStat().ToString(), "GdViewer.GetRegionWidthPixels")
End If
Else
MessageBox.Show("The file can't be loaded. Status: " + oPDF.GetStat().ToString(), "GdViewer.GetRegionWidthPixels")
End If
End Using
End Sub
//We assume that the GdViewer1 control has been properly integrated
//and some PDF document is loaded and displayed as well.
//Here we make use of the RegionSelectedByUser event.
void GdViewer1_RegionSelectedByUser(int RegionID)
{
int page = GdViewer1.GetRegionPage(RegionID);
//Converting pixels to PDF points.
int left = (int)(GdViewer1.GetRegionLeftPixels(RegionID) * 0.75);
int top = (int)(GdViewer1.GetRegionTopPixels(RegionID) * 0.75);
int width = (int)(GdViewer1.GetRegionWidthPixels(RegionID) * 0.75);
int height = (int)(GdViewer1.GetRegionHeightPixels(RegionID) * 0.75);
using (GdPicturePDF oPDF = new GdPicturePDF())
{
if (oPDF.LoadFromFile(GdViewer1.GetLastPath(), false) == GdPictureStatus.OK)
{
oPDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitPoint);
oPDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
//Drawing a rectangle on the document's page according to the selected rectangle in the GdViewer1 control.
if ((oPDF.SelectPage(page) == GdPictureStatus.OK) &&
(oPDF.SetFillAlpha(150) == GdPictureStatus.OK) &&
(oPDF.SetFillColor(0, 191, 255) == GdPictureStatus.OK) &&
(oPDF.DrawRectangle(left, top, width, height, true, false) == GdPictureStatus.OK))
{
if (oPDF.SaveToFile("test_region.pdf") == GdPictureStatus.OK)
MessageBox.Show("The file has been saved successfully.", "GdViewer.GetRegionWidthPixels");
else
MessageBox.Show("The file can't be saved. Status: " + oPDF.GetStat().ToString(), "GdViewer.GetRegionWidthPixels");
}
else
MessageBox.Show("The graphics operations have failed. Status: " + oPDF.GetStat().ToString(), "GdViewer.GetRegionWidthPixels");
}
else
MessageBox.Show("The file can't be loaded. Status: " + oPDF.GetStat().ToString(), "GdViewer.GetRegionWidthPixels");
}
}
Example
How to draw a rectangle on the document's page according to the user's selection of the highlighted rectangle in the GdViewer control.
'We assume that the GdViewer1 control has been properly integrated
'and some PDF document is loaded and displayed as well.
'Here we make use of the RegionSelectedByUser event.
Sub GdViewer1_RegionSelectedByUser(ByVal RegionID As Integer)
Dim page As Integer = GdViewer1.GetRegionPage(RegionID)
'Converting pixels to PDF points.
Dim left As Integer = GdViewer1.GetRegionLeftPixels(RegionID) * 0.75
Dim top As Integer = GdViewer1.GetRegionTopPixels(RegionID) * 0.75
Dim width As Integer = GdViewer1.GetRegionWidthPixels(RegionID) * 0.75
Dim height As Integer = GdViewer1.GetRegionHeightPixels(RegionID) * 0.75
Using oPDF As GdPicturePDF = New GdPicturePDF()
If oPDF.LoadFromFile(GdViewer1.GetLastPath(), False) = GdPictureStatus.OK Then
oPDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitPoint)
oPDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
'Drawing a rectangle on the document's page according to the selected rectangle in the GdViewer1 control.
If (oPDF.SelectPage(page) = GdPictureStatus.OK) AndAlso
(oPDF.SetFillAlpha(150) = GdPictureStatus.OK) AndAlso
(oPDF.SetFillColor(0, 191, 255) = GdPictureStatus.OK) AndAlso
(oPDF.DrawRectangle(left, top, width, height, True, False) = GdPictureStatus.OK) Then
If oPDF.SaveToFile("test_region.pdf") = GdPictureStatus.OK Then
MessageBox.Show("The file has been saved successfully.", "GdViewer.GetRegionWidthPixels")
Else
MessageBox.Show("The file can't be saved. Status: " + oPDF.GetStat().ToString(), "GdViewer.GetRegionWidthPixels")
End If
Else
MessageBox.Show("The graphics operations have failed. Status: " + oPDF.GetStat().ToString(), "GdViewer.GetRegionWidthPixels")
End If
Else
MessageBox.Show("The file can't be loaded. Status: " + oPDF.GetStat().ToString(), "GdViewer.GetRegionWidthPixels")
End If
End Using
End Sub
//We assume that the GdViewer1 control has been properly integrated
//and some PDF document is loaded and displayed as well.
//Here we make use of the RegionSelectedByUser event.
void GdViewer1_RegionSelectedByUser(int RegionID)
{
int page = GdViewer1.GetRegionPage(RegionID);
//Converting pixels to PDF points.
int left = (int)(GdViewer1.GetRegionLeftPixels(RegionID) * 0.75);
int top = (int)(GdViewer1.GetRegionTopPixels(RegionID) * 0.75);
int width = (int)(GdViewer1.GetRegionWidthPixels(RegionID) * 0.75);
int height = (int)(GdViewer1.GetRegionHeightPixels(RegionID) * 0.75);
using (GdPicturePDF oPDF = new GdPicturePDF())
{
if (oPDF.LoadFromFile(GdViewer1.GetLastPath(), false) == GdPictureStatus.OK)
{
oPDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitPoint);
oPDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
//Drawing a rectangle on the document's page according to the selected rectangle in the GdViewer1 control.
if ((oPDF.SelectPage(page) == GdPictureStatus.OK) &&
(oPDF.SetFillAlpha(150) == GdPictureStatus.OK) &&
(oPDF.SetFillColor(0, 191, 255) == GdPictureStatus.OK) &&
(oPDF.DrawRectangle(left, top, width, height, true, false) == GdPictureStatus.OK))
{
if (oPDF.SaveToFile("test_region.pdf") == GdPictureStatus.OK)
MessageBox.Show("The file has been saved successfully.", "GdViewer.GetRegionWidthPixels");
else
MessageBox.Show("The file can't be saved. Status: " + oPDF.GetStat().ToString(), "GdViewer.GetRegionWidthPixels");
}
else
MessageBox.Show("The graphics operations have failed. Status: " + oPDF.GetStat().ToString(), "GdViewer.GetRegionWidthPixels");
}
else
MessageBox.Show("The file can't be loaded. Status: " + oPDF.GetStat().ToString(), "GdViewer.GetRegionWidthPixels");
}
}
See Also
Reference
GdViewer Class
GdViewer Members
AddRegion(String,Int32,Int32,Int32,Int32,ForegroundMixMode,Int32) Method
AddRegionInches(String,Single,Single,Single,Single,ForegroundMixMode,Int32) Method
SetRegionWidthPixels Method
GetRegionID Method
AddRegion(String,Int32,Int32,Int32,Int32,ForegroundMixMode,Int32) Method
AddRegionInches(String,Single,Single,Single,Single,ForegroundMixMode,Int32) Method
GetStat Method
RegionSelectedByUser Event
SetRegionWidthPixels Method
RegionCount Method
GetRegionID Method
SearchText(String,Int32,Boolean) Method
AddRegion(String,Int32,Int32,Int32,Int32,ForegroundMixMode,Int32) Method
AddRegionInches(String,Single,Single,Single,Single,ForegroundMixMode,Int32) Method
GetRegionWidth Method
SetRegionWidth Method