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:
Set Dest = Page.CreateDest or
Set Dest = Page.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:
Set Dest = Page.CreateDest("FitH=true")
Set Dest = Page.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:
Set Dest = Page.CreateDest("FitV=true")
Set Dest = Page.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.
Set Dest = Page.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:
Set Dest = Page.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:
Set Dest = Page.CreateDest("FitB=true")
Set Dest = Page.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:
VBScript |
Set Pdf = Server.CreateObject("Persits.Pdf")
Set Doc = Pdf.CreateDocument
Set Page = Doc.Pages.Add
Set Font = Doc.Fonts("Helvetica")
' vertical grid
For x = 0 to Page.Width step Page.Width / 20
Page.Canvas.DrawLine x, 0, x, Page.Height
Page.Canvas.DrawText x, "angle=90;y=5;x=" & x, Font
Next
' horizontal grid
For y = 0 to Page.Height step Page.Height / 20
Page.Canvas.DrawLine 0, y, Page.Width, y
Page.Canvas.DrawText y, "x=5;y=" & y, Font
Next
' Create destination based on URL param
Set Param = Pdf.CreateParam
If Request("FitV") <> "" Then
Param("FitV") = True
Param("Left") = Request("Left")
End If
If Request("FitH") <> "" Then
Param("FitH") = True
Param("Top") = Request("Top")
End If
If Request("XYZ") <> "" Then
Param("XYZ") = True
Param("Top") = Request("Top")
Param("Left") = Request("Left")
Param("Zoom") = Request("Zoom")
End If
Set Dest = Page.CreateDest(Param)
' Assign destination to Doc's OpenAction
Doc.OpenAction = Dest
' Save to HTTP stream
Doc.SaveHttp "attachment;filename=destdemo.pdf"
|
C# |
IPdfManager objPdf = new PdfManager();
IPdfDocument objDoc = objPdf.CreateDocument(Missing.Value);
IPdfPage objPage = objDoc.Pages.Add(Missing.Value, Missing.Value, Missing.Value);
IPdfFont objFont = objDoc.Fonts["Helvetica", Missing.Value];
// 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
IPdfParam objParam = objPdf.CreateParam( Missing.Value );
if( Request["FitV"] != null )
{
objParam["FitV"].Value = 1; // true
objParam["Left"].Value = float.Parse(Request["Left"]);
}
if( Request["FitH"] != null )
{
objParam["FitH"].Value = 1;
objParam["Top"].Value = float.Parse(Request["Top"]);
}
if( Request["XYZ"] != null )
{
objParam["XYZ"].Value = 1;
objParam["Top"].Value = float.Parse(Request["Top"]);
objParam["Left"].Value = float.Parse(Request["Left"]);
objParam["Zoom"].Value = float.Parse(Request["Zoom"]);
}
IPdfDest objDest = objPage.CreateDest( objParam );
// Assign destination to Doc's OpenAction
objDoc.OpenAction = objDest;
// Save document to HTTP stream
objDoc.SaveHttp( "attachment;filename=destdemo.pdf", Missing.Value );
|
Click the links below to run this code sample:
http://localhost/asppdf/manual_10/10_dest.asp
http://localhost/asppdf/manual_10/10_dest.asp?FitV=true&left=100
http://localhost/asppdf/manual_10/10_dest.asp?FitH=true&top=500
http://localhost/asppdf/manual_10/10_dest.asp?XYZ=true&left=200&top=500&zoom=2
http://localhost/asppdf/manual_10/10_dest.aspx
http://localhost/asppdf/manual_10/10_dest.aspx?FitV=true&left=100
http://localhost/asppdf/manual_10/10_dest.aspx?FitH=true&top=500
http://localhost/asppdf/manual_10/10_dest.aspx?XYZ=true&left=200&top=500&zoom=2