SetHyperLink

The SetHyperLink hyperlink creates a hyperlink on the current printing text or image object. Users will then be able to click on the hyperlink to browse to another location inside the document or to an external URL. Hyperlinks are currently available in PDF and HTML files only.

 

Syntax

ActiveX:

System.Int32 SetHyperLink(System.IntPtr hDC, System.System URL)

DLL:

long SetHyperLink(HANDLE hDC, LPCSTR szURL)

 

Parameters

hDC

Handle to printer device context returned by a call to CreateDC or by the application.

URL, szURL

Hyperlink destination.

 

Return Value

The return value is always 0.

 

Remarks

Hyperlinks can be set to an external URL such as http://www.amyuni.com or to a bookmark in the same document. To add a hyperlink to an internal bookmark, the Destination should start with the # sign followed by the bookmark title.

 

The hyperlink will be inserted at the location where the last text drawing operation occurred. E.g.: if we draw text in the middle of page 3 of the document and call SetHyperlink immediately after, the hyperlink will be set on the text in the middle of page 3 of the PDF document.

 

Member of CDIntfEx.CDIntfEx.

 

Example

<Flags()>

Public Enum acFileNameOptions As Integer

    ' Please check FileNameOptions for the complete flags version

    NoPrompt = &H1

    UseFileName = &H2

    Concatenate = &H4

    DisableCompression = &H8

    EmbedFonts = &H10

    BroadcastMessages = &H20

    PrintWatermark = &H40

End Enum

 

Dim PrintDocument1 As New System.Drawing.Printing.PrintDocument

 

' Declare a new cdintfex object if it does not exist in the form.

Public PDF As New CDIntfEx.CDIntfEx

 

Public Sub Sample()

    ' Constants for Activation codes

    Const strLicenseTo As String = "Amyuni PDF Converter Evaluation"

    Const strActivationCode As String = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

    Const AMYUNIPRINTERNAME As String = "Amyuni PDF Converter"

 

    ' Get a reference to the installed printer.

    ' This will fail if the printer name passed to the DriverInit method is 

    ' not found in the printer’s folder

    PDF.DriverInit(AMYUNIPRINTERNAME)

 

    ' The SetDefaultPrinter function sets the system default printer to the one

    ' initialized by the DriverInit functions.

    PDF.SetDefaultPrinter()

 

    ' The EnablePrinter() method needs to be called right before each print job.

    ' and before the configuration

    ' Calling the EnablePrinter() method will start a 20 second time-out value

    PDF.EnablePrinter(strLicenseTo, strActivationCode)

 

    ' Resulting PDF document stored here

    PDF.DefaultFileName = "c:\temp\amyuni.pdf"

 

    ' Set Printer options

    PDF.FileNameOptionsEx = acFileNameOptions.NoPrompt Or acFileNameOptions.UseFileName

 

    ' Print Something

    AddHandler PrintDocument1.PrintPage, AddressOf PrintDocument1_PrintPage

    PrintDocument1.Print()

 

    ' The RestoreDefaultPrinter function resets the system default printer 

    ' to the printer that was the default before the call to SetDefaultPrinter.

    PDF.RestoreDefaultPrinter()

 

    ' This function will simply detach from an existing printer because the handle was created using DriverInit

    PDF.DriverEnd()

End Sub

 

Public Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs)

    ' Print a Text

    DDim pFont As Font = New Font("Comic Sans MS", 20)

    ev.Graphics.DrawString("Hello World", pFont, Brushes.Black, 100, 100)

 

    ' Print a Text

    ev.Graphics.DrawString("Amyuni Technologies", pFont, Brushes.Black, 100, 200)

 

    ' Create HyperLink

    PDF.SetHyperLink(ev.Graphics.GetHdc(), "https://www.amyuni.com")

    ev.Graphics.ReleaseHdc()

End Sub

[Flags]

public enum acFileNameOptions

{

    // Please check FileNameOptions for the complete flags version

    NoPrompt = 0x00000001,

    UseFileName = 0x00000002,

    Concatenate = 0x00000004,

    DisableCompression = 0x00000008,

    EmbedFonts = 0x00000010,

    BroadcastMessages = 0x00000020,

    PrintWatermark = 0x00000040

}

 

System.Drawing.Printing.PrintDocument PrintDocument1 = new System.Drawing.Printing.PrintDocument(); 

 

// Declare a new cdintfex object if it does not exist in the form.

CDIntfEx.CDIntfEx PDF = new CDIntfEx.CDIntfEx();

 

public void Sample()

{

    // Constants for Activation codes

    const string strLicenseTo = "Amyuni PDF Converter Evaluation";

    const string strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA";

    const string AMYUNIPRINTERNAME = "Amyuni PDF Converter";

 

    // Get a reference to the installed printer.

    // This will fail if the printer name passed to the DriverInit method is 

    // not found in the printer’s folder

    PDF.DriverInit(AMYUNIPRINTERNAME);

 

    // The SetDefaultPrinter function sets the system default printer to the one

    // initialized by the DriverInit functions.

    PDF.SetDefaultPrinter();

 

    // The EnablePrinter() method needs to be called right before each print job.

    // and before the configuration

    // Calling the EnablePrinter() method will start a 20 second time-out value

    PDF.EnablePrinter(strLicenseTo, strActivationCode);

 

    // Resulting PDF document stored here

    PDF.DefaultFileName = "c:\temp\amyuni.pdf";

 

    // Set Printer options

    PDF.FileNameOptionsEx = (int)(acFileNameOptions.NoPrompt | acFileNameOptions.UseFileName);

 

    // The EnablePrinter() method needs to be called right before each print job.

    // and before the configuration

    // Calling the EnablePrinter() method will start a 20 second time-out value

    PDF.EnablePrinter(strLicenseTo, strActivationCode);

 

    // Print Something

    PrintDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintDocument1_PrintPage);

 

    // Print the document.

    PrintDocument1.Print();

 

    // The RestoreDefaultPrinter function resets the system default printer 

    // to the printer that was the default before the call to SetDefaultPrinter.

    PDF.RestoreDefaultPrinter();

 

    // This function will simply detach from an existing printer because the handle was created using DriverInit

    PDF.DriverEnd();

}

 

public void PrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ev)

{

    // Print a Text

    Font pFont = new Font("Comic Sans MS", 20);

    ev.Graphics.DrawString("Hello World", pFont, Brushes.Black, 100, 100);

 

    // Print a Text

    ev.Graphics.DrawString("Amyuni Technologies", pFont, Brushes.Black, 100, 200);

 

    // Create HyperLink

    PDF.SetHyperLink((int)ev.Graphics.GetHdc(), "https://www.amyuni.com");

    ev.Graphics.ReleaseHdc();

}

// PDF Converter Cpp.cpp : Defines the entry point for the console application.

// 

# include <Windows.h>

# include <string>

# include <iostream>

# include "CdIntf.h"

# pragma comment (lib, "CDIntf.lib")

 

using namespace std;

int main()

{

     // Constants for Activation codes

    #define strLicenseTo  "Amyuni PDF Converter Evaluation"

    #define strActivationCode "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

    #define AMYUNIPRINTERNAME "Amyuni PDF Converter"

 

    // Get a reference to the installed printer.

    // This will fail if the printer name passed to the DriverInit method is 

    // not found in the printer’s folder

    HANDLE PDF = DriverInit(AMYUNIPRINTERNAME);

 

    // The CDISetDefaultPrinter function sets the system default printer to the one

    // initialized by the DriverInit functions.

    CDISetDefaultPrinter(PDF);

 

    // The EnablePrinter() method needs to be called right before each print job.

    // and before the configuration

    // Calling the EnablePrinter() method will start a 20 second time-out value

    EnablePrinter(PDF, strLicenseTo, strActivationCode);

 

    // Resulting PDF document stored here

    SetDefaultFileName(PDF, "C:\temp\\amyuni.pdf");

 

    // Set Printer options

    SetFileNameOptions(PDF, NoPrompt | UseFileName);

 

    // Create Device Context for Amyuni PDF printer

    HDC printerDC = CDICreateDC (PDF);

 

    // Initialize the Printer

    DOCINFO di;

    ::ZeroMemory (&di, sizeof(DOCINFO));

    di.cbSize = sizeof(DOCINFO);

    di.lpszDocName = _T("myDocTitle");

    di.lpszOutput = _T("C:\temp\\amyuni.pdf");

    StartDoc(printerDC, &di);

    StartPage(printerDC);

 

    // Print a Text

    TextOut(printerDC, 0, 200, _T("Hello World"), lstrlen (_T("Hello World")));

 

    // Print a Text

    TextOut(printerDC, 0, 400, _T("Amyuni Technologies"), lstrlen (_T("Amyuni Technologies")));

 

    // Set Hyperlink to the previous text

    SetHyperLink(printerDC, "https://www.amyuni.com");

 

    // End Print

    EndPage(printerDC);

    EndDoc(printerDC);

    DeleteDC(printerDC);

 

    // The RestoreDefaultPrinter function resets the system default printer 

    // to the printer that was the default before the call to SetDefaultPrinter.

    RestoreDefaultPrinter(PDF);

 

    // This function will simply detach from an existing printer because the handle was created using DriverInit

    DriverEnd(PDF);

 

    // Destroy PDF object

    PDF = nullptr;    

 

    return 0;

}