The SetBookmark method creates a bookmark on the current printing page and location. Users will then be able to browse through the document by clicking on the bookmarks tree. Bookmarks are currently available in PDF files only.
System.Int32 SetBookmark(System.IntPtr hDC, System.Int32 lParent, System.String Title)
long SetBookmark(HANDLE hDC, long lParent, LPCSTR szTitle)
hDC
Handle to printer device context returned by a call to CreateDC, or returned by the application.
lParent
Id of parent bookmark.
Title, szTitle
Bookmark title.
The return value is the identifier of the bookmark that was created, or 0 if the function fails.
PDF bookmarks are structured in a tree. The root has an ID of 0. SetBookmark returns the bookmark ID which can be used to insert other bookmarks as children of the current bookmark.
The bookmark 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 SetBookmark immediately after, the bookmark will point to the middle of page 3 of the PDF document.
Member of CDIntfEx.CDIntfEx.
To create the following bookmark structure:
<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 Pages As Integer
Sub Main()
' 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
' 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()
End Sub
Public Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs)
' Print a Text
Dim pFont As Font = New Font("Comic Sans MS", 20)
ev.Graphics.DrawString("Hello World", pFont, Brushes.Black, 100, 100)
' Create a Bookmark
Dim n = PDF.SetBookmark(ev.Graphics.GetHdc(), 0, "BookMark " + Pages.ToString())
ev.Graphics.ReleaseHdc()
n = PDF.SetBookmark(ev.Graphics.GetHdc(), n, "BookMark A" + Pages.ToString())
ev.Graphics.ReleaseHdc()
PDF.SetBookmark(ev.Graphics.GetHdc(), n, "BookMark B" + Pages.ToString())
ev.Graphics.ReleaseHdc()
' 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()
Pages += 1
ev.HasMorePages = Pages < 4
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 int Pages { get; set; }
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);
// 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);
// Create a Bookmark
var n = PDF.SetBookmark((int)ev.Graphics.GetHdc(), 0, "BookMark " + Pages);
ev.Graphics.ReleaseHdc();
n = PDF.SetBookmark((int)ev.Graphics.GetHdc(), n, "BookMark A" + Pages);
ev.Graphics.ReleaseHdc();
n = PDF.SetBookmark((int)ev.Graphics.GetHdc(), n, "BookMark B" + Pages);
ev.Graphics.ReleaseHdc();
// 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();
Pages++;
ev.HasMorePages = Pages < 4;
}
// 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")));
// Set BookMark to the previous text
SetBookmark(printerDC, 0, "First BookMark");
// 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;
}