AddAnnot: Insert a PDF annotation   [ 68 ]

Description

This function enables a program to introduce PDF annotations which will span on a rectangular area.  It takes 10 parameters described below.
  1. X    ⇒  float number which is the X location of the upper left corner of the rectangle above which this annotation will apply.
  2. Y    ⇒  float number which is the Y location of the upper left corner of the rectangle above which this annotation will apply.
  3. W    ⇒  float number which is the width of the rectangle above which this annotation will apply.
  4. H    ⇒  float number which is the height of the rectangle above which this annotation will apply.
  5. Txt  ⇒  pointer to a character string which is the text content of the annotation.
  6. Typ  ⇒  pointer to a character string which specifies which type of allocation is required.  The most common use of this parameter is "Text" but other values are possible: "Square" - "Circle" - "Link" - "Line".
  7. Nam  ⇒  Name of the icon which further qualifies the annotation; possible values are: "Note" - "Comment" - "Key" - "Help" - "Paragraph" - "NewParagraph"- "Insert".
  8. Tit  ⇒  pointer to a character string which specifies the title which will appear above the annotation proper.
  9. Col  ⇒  pointer to a character string which specifies the color of the annotation in terme of RGB: "0 0 0" means black while "1 1 1" means white and "0.5 0.5 0.5" means gray.

C calling syntax
void AddAnnot (float x, float y, float w, float h, char *txt, char *typ, char *nam, char *tit, char *col, char *prm);
Cobol calling syntax
Call "AddAnnot" using by value X,Y,W,H,TXT,TYP,NAM,TYP,COL,PRM.
C sample code
#include   "fpdf.h"

static char   f_ini ??(??) = ??< "ini??/??/demofpdf.ini" ??>;
static char   f_out ??(??) = ??< "pdf??/??/demo_g.pdf" ??>;
static char   bufr ??(128??);
static char   file_txt ??(??) = ??< "data/embeddedData.txt" ??>;
static char   file_htm ??(??) = ??< "data/embeddedData.htm" ??>;
static char   filexlsx ??(??) = ??< "data/embeddedData.xlsx" ??>;

/* ----------------------------------------------------------------- */

int  main (int argc, char *argv [])

??<

NewPdfy (f_ini, 1);
AddPage ("P");
SetFont ("Arial", "BI", 20);
strcpy (bufr, "Illustration of Annotations and Embedded data");
Text (20, 25, bufr);

SetFont ("Arial", "N", 16);
strcpy (bufr, "Text Type Annotation example - Note Icon");
Text (20, 50, bufr);
AddAnnot (20 + GetStringWidth (bufr) + 10, 40, 10, 6, "Annotation #1 content from demo_g",
          "Text", "Note", "Annotation #1 title", "0 0 1", "");

SetFont ("Arial", "I", 16);
strcpy (bufr, "Link Type Annotation example - Key Icon");
Text (20, 70, bufr);
AddAnnot (20 + GetStringWidth (bufr) + 10, 65, 10, 6, "Annotation #2 content from demo_g",
          "Link", "Key", "Annotation #2 title", "0 1 0", "");

SetFont ("Courier", "N", 16);
strcpy (bufr, "Circle Type Annotation example - Help Icon");
Text (20, 90, bufr);
AddAnnot (20 + GetStringWidth (bufr) + 10, 95, 10, 6, "Annotation #3 content from demo_g",
          "Circle", "Help", "Annotation #3 title", "1 1 0", "");

SetFont ("Courier", "N", 16);
strcpy (bufr, "Square Type Annotation example - Help Icon");
Text (20, 110, bufr);
AddAnnot (20 + GetStringWidth (bufr) + 10, 105, 10, 6, "Annotation #4 content from demo_g",
          "Square", "Help", "Annotation #4 title", "1 0 0", "");

SetFont ("Courier", "A", 16);
Text (20, 155, "Embedded Text Data :");
AttachFile (file_txt, "EmbeddedData.txt", 1, 100, 150, "Y", "Y", "Y", "F");
Text (20, 175, "Embedded HTML Data :");
AttachFile (file_htm, "EmbeddedData.html", 1, 100, 170, "Y", "Y", "Y", "F");
Text (20, 195, "Embedded XLSX Data :");
AttachFile (filexlsx, "EmbeddedData.xlsx", 1, 100, 190, "N", "N", "N", "F");

FlushPdf (f_out, 2, "CUSTZZ", "demo_g");
??>
Description of sample code
This programs illustrates annotation as well as embedded data features found in FPDF4ZOS.  It opens a PDF context, insert a page and:
- Put three different annotations
- Attaches three files of different types: Text, HTML, Excel.

The following functions are used in this piece:
- NewPdfy()      -->  Initialisation of a pdf context
- AddPage()      -->  As it says
- SetFont()      -->  Set current font
- Text()         -->  Insert Text at a specific location
- SetMargins()   -->  Specify page margins (left, top, right)
- AddAnnot()     -->  Addan annotation
- AttachFile()   -->  Embed a file within target PDF
- FlushPdf()     -->  Output PDF file taking into account all the instructions invoked since context initialization
See sample source code in 'C' as well as PDF execution result  -  NB: For encrypted PDFs, user password is USER-PSWD