Haru Free PDF Library
text_annotation.c
/*
* << Haru Free PDF Library 2.0.0 >> -- text_annotation.c
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
* It is provided "as is" without express or implied warranty.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "hpdf.h"
#include "handler.h"
#include "utils.h"
int main(int argc, char **argv)
{
HPDF_Rect rect1 = {50, 350, 150, 400};
HPDF_Rect rect2 = {210, 350, 350, 400};
HPDF_Rect rect3 = {50, 250, 150, 300};
HPDF_Rect rect4 = {210, 250, 350, 300};
HPDF_Rect rect5 = {50, 150, 150, 200};
HPDF_Rect rect6 = {210, 150, 350, 200};
HPDF_Rect rect7 = {50, 50, 150, 100};
HPDF_Rect rect8 = {210, 50, 350, 100};
HPDF_Doc pdf;
char fname[256];
HPDF_Page page;
HPDF_Font font;
HPDF_Encoder encoding;
strcpy (fname, argv[0]);
strcat (fname, ".pdf");
pdf = HPDF_New (demo_error_handler, NULL);
if (!pdf) {
printf ("error: cannot create PdfDoc object\n");
return 1;
}
if (setjmp(env)) {
HPDF_Free (pdf);
return 1;
}
/* use Times-Roman font. */
font = HPDF_GetFont (pdf, "Times-Roman", "WinAnsiEncoding");
page = HPDF_AddPage (pdf);
HPDF_Page_SetWidth (page, 400);
HPDF_Page_SetHeight (page, 500);
HPDF_Page_SetFontAndSize (page, font, 16);
HPDF_Page_MoveTextPos (page, 130, 450);
HPDF_Page_ShowText (page, "Annotation Demo");
annot = HPDF_Page_CreateTextAnnot (page, rect1, "Annotation with Comment "
"Icon. \n This annotation set to be opened initially.",
NULL);
annot = HPDF_Page_CreateTextAnnot (page, rect2,
"Annotation with Key Icon", NULL);
annot = HPDF_Page_CreateTextAnnot (page, rect3,
"Annotation with Note Icon", NULL);
annot = HPDF_Page_CreateTextAnnot (page, rect4,
"Annotation with Help Icon", NULL);
annot = HPDF_Page_CreateTextAnnot (page, rect5,
"Annotation with NewParagraph Icon", NULL);
annot = HPDF_Page_CreateTextAnnot (page, rect6,
"Annotation with Paragraph Icon", NULL);
annot = HPDF_Page_CreateTextAnnot (page, rect7,
"Annotation with Insert Icon", NULL);
encoding = HPDF_GetEncoder (pdf, "ISO8859-2");
const char *annotation_text = "Annotation with ISO8859 text %s";
char buf[50] = {0};
HPDF_snprintf(buf, 50, annotation_text, iso8859_2_text);
buf, encoding);
HPDF_Page_SetFontAndSize (page, font, 11);
HPDF_Page_MoveTextPos (page, rect1.left + 35, rect1.top - 20);
HPDF_Page_ShowText (page, "Comment Icon.");
HPDF_Page_MoveTextPos (page, rect2.left + 35, rect2.top - 20);
HPDF_Page_ShowText (page, "Key Icon");
HPDF_Page_MoveTextPos (page, rect3.left + 35, rect3.top - 20);
HPDF_Page_ShowText (page, "Note Icon.");
HPDF_Page_MoveTextPos (page, rect4.left + 35, rect4.top - 20);
HPDF_Page_ShowText (page, "Help Icon");
HPDF_Page_MoveTextPos (page, rect5.left + 35, rect5.top - 20);
HPDF_Page_ShowText (page, "NewParagraph Icon");
HPDF_Page_MoveTextPos (page, rect6.left + 35, rect6.top - 20);
HPDF_Page_ShowText (page, "Paragraph Icon");
HPDF_Page_MoveTextPos (page, rect7.left + 35, rect7.top - 20);
HPDF_Page_ShowText (page, "Insert Icon");
HPDF_Page_MoveTextPos (page, rect8.left + 35, rect8.top - 20);
HPDF_Page_ShowText (page, "Text Icon(ISO8859-2 text)");
/* save the document to a file */
HPDF_SaveToFile (pdf, fname);
/* clean up */
HPDF_Free (pdf);
return 0;
}
HPDF_STATUS HPDF_SaveToFile(HPDF_Doc pdf, const char *filename)
Saves the current document to file.
void HPDF_Free(HPDF_Doc pdf)
Revoke a document object and all resources.
HPDF_Doc HPDF_New(HPDF_Error_Handler user_error_fn, void *user_data)
Create an instance of a document object and initialize it.
HPDF_Encoder HPDF_GetEncoder(HPDF_Doc pdf, const char *encoding_name)
Get encoder object handle by specified encoding name.
HPDF_Font HPDF_GetFont(HPDF_Doc pdf, const char *font_name, const char *encoding_name)
Get requested font object handle.
HPDF_STATUS HPDF_Page_SetFontAndSize(HPDF_Page page, HPDF_Font font, HPDF_REAL size)
Set the type of font and size leading.
HPDF_STATUS HPDF_Page_ShowText(HPDF_Page page, const char *text)
Put text at the current text position on the page.
HPDF_STATUS HPDF_Page_BeginText(HPDF_Page page)
Begin text object and set text position to (0, 0).
HPDF_STATUS HPDF_Page_EndText(HPDF_Page page)
Finish text object.
HPDF_STATUS HPDF_Page_MoveTextPos(HPDF_Page page, HPDF_REAL x, HPDF_REAL y)
Change current text position using the specified offset values.
HPDF_Page HPDF_AddPage(HPDF_Doc pdf)
Create new page and add it after the last page of document.
HPDF_STATUS HPDF_Page_SetWidth(HPDF_Page page, HPDF_REAL value)
Change page width.
HPDF_STATUS HPDF_Page_SetHeight(HPDF_Page page, HPDF_REAL value)
Change page height.
#define HPDF_TRUE
Definition: hpdf_consts.h:26
@ HPDF_ANNOT_ICON_NEW_PARAGRAPH
"NewParagraph"
Definition: hpdf_types.h:456
@ HPDF_ANNOT_ICON_PARAGRAPH
"Paragraph"
Definition: hpdf_types.h:458
@ HPDF_ANNOT_ICON_HELP
"Help"
Definition: hpdf_types.h:454
@ HPDF_ANNOT_ICON_COMMENT
"Comment"
Definition: hpdf_types.h:448
@ HPDF_ANNOT_ICON_INSERT
"Insert"
Definition: hpdf_types.h:460
@ HPDF_ANNOT_ICON_NOTE
"Note"
Definition: hpdf_types.h:452
Definition: hpdf_objects.h:421
Definition: hpdf_doc.h:36
Definition: hpdf_encoder.h:115
Definition: hpdf_types.h:110
HPDF_REAL top
Definition: hpdf_types.h:114
HPDF_REAL left
Definition: hpdf_types.h:111