EVO HTML to PDF Converter

Set Initial Zoom Level of the Generated PDF Document

EVO HTML to PDF Converter for .NET Documentation

EVO HTML to PDF Converter can set the location in a PDF page where to go when the generated PDF is opened in a PDF viewer using a PdfActionGoTo object which can be assigned to DocumentOpenActionAction property. An object of DocumentOpenAction type is exposed by the DocumentOpenAction property. Additionally you can set the initial zoom level using the ExplicitDestinationZoomPercentage property of destination object used to construct the PdfActionGoTo object.

Code Sample - Set Initial Zoom Level of the Generated PDF Document

protected void convertToPdfButton_Click(object sender, EventArgs e)
{
    // Create a PDF document
    Document pdfDocument = new Document();

    // Set license key received after purchase to use the converter in licensed mode
    // Leave it not set to use the converter in demo mode
    pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

    // Add a page to PDF document
    PdfPage pdfPage = pdfDocument.AddPage();

    try
    {
        // Create a HTML to PDF element to add to document
        HtmlToPdfElement htmlToPdfElement = new HtmlToPdfElement(urlTextBox.Text);

        // Optionally set a delay before conversion to allow asynchonous scripts to finish
        htmlToPdfElement.ConversionDelay = 2;

        // Add the HTML to PDF element to document
        pdfPage.AddElement(htmlToPdfElement);

        int goToPageNumber = int.Parse(pageNumberTextBox.Text);
        if (goToPageNumber > pdfDocument.Pages.Count)
        {
            return;
        }

        // Get destination PDF page
        PdfPage goToPage = pdfDocument.Pages[goToPageNumber - 1];

        // Get the destination point in PDF page
        float goToX = float.Parse(xLocationTextBox.Text);
        float goToY = float.Parse(yLocationTextBox.Text);

        PointF goToLocation = new PointF(goToX, goToY);

        // Get the destination view mode
        DestinationViewMode viewMode = SelectedViewMode();

        // Create the destination in PDF document
        ExplicitDestination goToDestination = new ExplicitDestination(goToPage, goToLocation, viewMode);

        // Set the zoom level when the destination is displayed
        if (viewMode == DestinationViewMode.XYZ)
            goToDestination.ZoomPercentage = int.Parse(zoomLevelTextBox.Text);

        // Set the document Go To open action
        pdfDocument.OpenAction.Action = new PdfActionGoTo(goToDestination);

        // Save the PDF document in a memory buffer
        byte[] outPdfBuffer = pdfDocument.Save();

        // Send the PDF as response to browser

        // Set response content type
        Response.AddHeader("Content-Type", "application/pdf");

        // Instruct the browser to open the PDF file as an attachment or inline
        Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Set_Initial_Zoom_Level.pdf; size={0}", outPdfBuffer.Length.ToString()));

        // Write the PDF document buffer to HTTP response
        Response.BinaryWrite(outPdfBuffer);

        // End the HTTP response and stop the current page processing
        Response.End();
    }
    finally
    {
        // Close the PDF document
        pdfDocument.Close();
    }
}