A destination defines a particular view of a document, consisting
of the following:
- The page of the document to be displayed;
- The location of the document window on that page;
- The magnification (zoom) factor to use when displaying the page.
A destination is represented by the PdfDest object
creatable via PdfDocument's CreateDest method, or
alternatively, via PdfPage's CreateDest method.
Both CreateDest methods take an optional parameter object
or parameter string as an argument.
Once a destination object is created, it can be assigned to
PdfDocument's OpenAction property which controls
which part of the document is to be displayed, and at what zoom factor,
when the document is opened. A destination object can also be assigned
to an outline item, annotation or action (all described below).
A destination created with no parameters,
or with the Fit parameter set to True, displays a page magnified just enough
to fit the entire page both horizontally and vertically:
PdfDest objDest = objPage.CreateDest() or
PdfDest objDest = objPage.CreateDest("Fit=true");
A destination created with the FitH parameter
set to True displays a page magnified just enough to
fit the entire width of the page within the window. An optional
Top parameter specifies the vertical position of the page to
be displayed at the top edge of the window:
PdfDest objDest = objPage.CreateDest("FitH=true");
PdfDest objDest = objPage.CreateDest("FitH=true; Top=100");
Similarly, a destination created with the FitV parameter
set to True displays a page magnified just enough to
fit the entire height of the page within the window. An optional
Left parameter specifies the horizontal position of the page to
be displayed at the left edge of the window:
PdfDest objDest = objPage.CreateDest("FitV=true");
PdfDest objDest = objPage.CreateDest("FitV=true; Left=130");
A destination created with the XYZ parameter set to True
and additional optional parameters Left, Top and Zoom
displays page with the coordinates (Left, Top) positioned
at the top-left corner of the window and the content of the page
magnified by the factor Zoom.
A Zoom value of 1 means 100%, 2 - 200%, etc.
PdfDest objDest = objPage.CreateDest("XYZ=true; Left=100; Top=200; Zoom=2");
A destination created with the FitR parameter set to True
and additional required parameters Left, Bottom,
Right and Top displays a page magnified
just enough to fit the rectangle specified by
[Left, Bottom, Right, Top]
entirely within the window both horizontally and vertically:
PdfDest objDest = objPage.CreateDest("FitR=true;Left=10;Bottom=10;Right=200;Top=100");
A destination created with the FitB parameter set to true
displays a page magnified enough to fit its bounding box
entirely within the window both horizontally and vertically. The FitB
parameter can be used stand-alone as well as in conjunction with
FitH and FitV parameters:
PdfDest objDest = objPage.CreateDest("FitB=true");
PdfDest objDest = objPage.CreateDest("FitB=true; FitV=true; Left=130");
The following code sample creates a document with gridlines, and
sets the document's OpenAction
property to various destinations based on passed URL parameters:
| C# |
PdfManager objPdf = new PdfManager();
// Create empty document
PdfDocument objDoc = objPdf.CreateDocument();
// Add a new page
PdfPage objPage = objDoc.Pages.Add();
// Select one of the standard PDF fonts
PdfFont objFont = objDoc.Fonts["Helvetica"];
// vertical grid
for( float x = 0; x < objPage.Width; x += objPage.Width / 20 )
{
objPage.Canvas.DrawLine( x, 0, x, objPage.Height );
objPage.Canvas.DrawText( x.ToString(), "angle=90;y=5;x=" + x.ToString(), objFont );
}
// horizontal grid
for( float y = 0; y <= objPage.Height; y += objPage.Height / 20 )
{
objPage.Canvas.DrawLine( 0, y, objPage.Width, y );
objPage.Canvas.DrawText( y.ToString(), "x=5;y=" + y.ToString(), objFont );
}
// Create destination based on URL param
PdfParam objParam = objPdf.CreateParam();
if( Request["FitV"] != null )
{
objParam["FitV"] = 1; // true
objParam["Left"] = float.Parse(Request["Left"]);
}
if( Request["FitH"] != null )
{
objParam["FitH"] = 1;
objParam["Top"] = float.Parse(Request["Top"]);
}
if( Request["XYZ"] != null )
{
objParam["XYZ"] = 1;
objParam["Top"] = float.Parse(Request["Top"]);
objParam["Left"] = float.Parse(Request["Left"]);
objParam["Zoom"] = float.Parse(Request["Zoom"]);
}
PdfDest objDest = objPage.CreateDest( objParam );
// Assign destination to Doc's OpenAction
objDoc.OpenAction = objDest;
// Save document to HTTP stream
objDoc.SaveHttp( "attachment;filename=destdemo.pdf" );
|
| VB.NET |
Dim objPdf As PdfManager = new PdfManager()
' Create empty document
Dim objDoc As PdfDocument = objPdf.CreateDocument()
' Add a new page
Dim objPage As PdfPage = objDoc.Pages.Add()
' Select one of the standard PDF fonts
Dim objFont As PdfFont = objDoc.Fonts("Helvetica")
' vertical grid
For x As Single = 0 To objPage.Width step objPage.Width / 20
objPage.Canvas.DrawLine( x, 0, x, objPage.Height )
objPage.Canvas.DrawText( x.ToString(), "angle=90;y=5;x=" + x.ToString(), objFont )
Next
' horizontal grid
For y As Single = 0 to objPage.Height step objPage.Height / 20
objPage.Canvas.DrawLine( 0, y, objPage.Width, y )
objPage.Canvas.DrawText( y.ToString(), "x=5;y=" + y.ToString(), objFont )
Next
' Create destination based on URL param
Dim objParam As PdfParam = objPdf.CreateParam()
If Request("FitV") <> Nothing Then
objParam("FitV") = 1 ' true
objParam("Left") = Single.Parse(Request("Left"))
End If
If Request("FitH") <> Nothing Then
objParam("FitH") = 1
objParam("Top") = Single.Parse(Request("Top"))
End If
If Request("XYZ") <> Nothing Then
objParam("XYZ") = 1
objParam("Top") = Single.Parse(Request("Top"))
objParam("Left") = Single.Parse(Request("Left"))
objParam("Zoom") = Single.Parse(Request("Zoom"))
End If
Dim objDest As PdfDest = objPage.CreateDest( objParam )
' Assign destination to Doc's OpenAction
objDoc.OpenAction = objDest
' Save document to HTTP stream
objDoc.SaveHttp( "attachment;filename=destdemo.pdf" )
|
Click the links below to run this code sample:
http://localhost/asppdf.net/manual_10/10_dest.cs.aspx
http://localhost/asppdf.net/manual_10/10_dest.cs.aspx?FitV=true&left=100
http://localhost/asppdf.net/manual_10/10_dest.cs.aspx?FitH=true&top=500
http://localhost/asppdf.net/manual_10/10_dest.cs.aspx?XYZ=true&left=200&top=500&zoom=2
http://localhost/asppdf.net/manual_10/10_dest.vb.aspx
http://localhost/asppdf.net/manual_10/10_dest.vb.aspx?FitV=true&left=100
http://localhost/asppdf.net/manual_10/10_dest.vb.aspx?FitH=true&top=500
http://localhost/asppdf.net/manual_10/10_dest.vb.aspx?XYZ=true&left=200&top=500&zoom=2