Beispiel #1
0
void
draw_graph (HPDF_Page   page)
{
    char buf[50];
    int i;

    /* Draw 16 X 15 cells */

    /* Draw vertical lines. */
    HPDF_Page_SetLineWidth (page, 0.5);

    for (i = 0; i <= 17; i++) {
        int x = i * CELL_WIDTH + 40;

        HPDF_Page_MoveTo (page, x, PAGE_HEIGHT - 60);
        HPDF_Page_LineTo (page, x, 40);
        HPDF_Page_Stroke (page);

        if (i > 0 && i <= 16) {
            HPDF_Page_BeginText (page);
            HPDF_Page_MoveTextPos (page, x + 5, PAGE_HEIGHT - 75);
#ifdef __WIN32__
            _snprintf(buf, 5, "%X", i - 1);
#else
            snprintf(buf, 5, "%X", i - 1);
#endif
            HPDF_Page_ShowText (page, buf);
            HPDF_Page_EndText (page);
        }
    }

    /* Draw horizontal lines. */
    for (i = 0; i <= 15; i++) {
       int y = i * CELL_HEIGHT + 40;

        HPDF_Page_MoveTo (page, 40, y);
        HPDF_Page_LineTo (page, PAGE_WIDTH - 40, y);
        HPDF_Page_Stroke (page);

        if (i < 14) {
            HPDF_Page_BeginText (page);
            HPDF_Page_MoveTextPos (page, 45, y + 5);
#ifdef __WIN32__
            _snprintf(buf, 5, "%X", 15 - i);
#else
            snprintf(buf, 5, "%X", 15 - i);
#endif
            HPDF_Page_ShowText (page, buf);
            HPDF_Page_EndText (page);
        }
    }
}
Beispiel #2
0
static HPDF_STATUS
Page_BeforeWrite  (HPDF_Dict    obj)
{
    HPDF_STATUS ret;
    HPDF_Page page = (HPDF_Page)obj;
    HPDF_PageAttr attr = (HPDF_PageAttr)obj->attr;

    HPDF_PTRACE((" HPDF_Page_BeforeWrite\n"));

    if (attr->gmode == HPDF_GMODE_PATH_OBJECT) {
        HPDF_PTRACE((" HPDF_Page_BeforeWrite warning path object is not"
                    " end\n"));

        if ((ret = HPDF_Page_EndPath (page)) != HPDF_OK)
           return ret;
    }

    if (attr->gmode == HPDF_GMODE_TEXT_OBJECT) {
        HPDF_PTRACE((" HPDF_Page_BeforeWrite warning text block is not end\n"));

        if ((ret = HPDF_Page_EndText (page)) != HPDF_OK)
            return ret;
    }

    if (attr->gstate)
        while (attr->gstate->prev) {
            if ((ret = HPDF_Page_GRestore (page)) != HPDF_OK)
                return ret;
        }

    return HPDF_OK;
}
/*
 * Class:     org_libharu_PdfPage
 * Method:    endText
 * Signature: ()V
 */
JNIEXPORT void JNICALL
Java_org_libharu_PdfPage_endText(JNIEnv *env, jobject obj) {
    jint page;
    /* Get mHPDFPagePointer */
    page = (*env)->GetIntField(env, obj, mHPDFPagePointer);
    HPDF_Page_EndText((HPDF_Page) page);
}
Beispiel #4
0
void
draw_image (HPDF_Doc     pdf,
            const char  *filename,
            float        x,
            float        y,
            const char  *text)
{
#ifdef __WIN32__
    const char* FILE_SEPARATOR = "\\";
#else
    const char* FILE_SEPARATOR = "/";
#endif
    char filename1[255];

    HPDF_Page page = HPDF_GetCurrentPage (pdf);
    HPDF_Image image;

    strcpy(filename1, "images");
    strcat(filename1, FILE_SEPARATOR);
    strcat(filename1, filename);

    image = HPDF_LoadJpegImageFromFile (pdf, filename1);

    /* Draw image to the canvas. */
    HPDF_Page_DrawImage (page, image, x, y, HPDF_Image_GetWidth (image),
                HPDF_Image_GetHeight (image));

    /* Print the text. */
    HPDF_Page_BeginText (page);
    HPDF_Page_SetTextLeading (page, 16);
    HPDF_Page_MoveTextPos (page, x, y);
    HPDF_Page_ShowTextNextLine (page, filename);
    HPDF_Page_ShowTextNextLine (page, text);
    HPDF_Page_EndText (page);
}
Beispiel #5
0
void
draw_fonts (HPDF_Page   page)
{
    int i;
    int j;

    HPDF_Page_BeginText (page);

    /* Draw all character from 0x20 to 0xFF to the canvas. */
    for (i = 1; i < 17; i++) {
        for (j = 1; j < 17; j++) {
            unsigned char buf[2];
            int y = PAGE_HEIGHT - 55 - ((i - 1) * CELL_HEIGHT);
            int x = j * CELL_WIDTH + 50;

            buf[1] = 0x00;

            buf[0] = (i - 1) * 16 + (j - 1);
            if (buf[0] >= 32) {
                double d;

                d  = x - HPDF_Page_TextWidth (page, (char*)buf) / 2;
                HPDF_Page_TextOut (page, d, y, (char*)buf);

            }
        }
    }

    HPDF_Page_EndText (page);
}
Beispiel #6
0
int main (int argc, char **argv)
{
    HPDF_Doc  pdf;
    HPDF_Font font;
    HPDF_Page page;
    char fname[256];
    HPDF_Destination dst;

    strcpy (fname, argv[0]);
    strcat (fname, ".pdf");

    pdf = HPDF_New (error_handler, NULL);
    if (!pdf) {
        printf ("error: cannot create PdfDoc object\n");
        return 1;
    }

    /* error-handler */
    if (setjmp(env)) {
        HPDF_Free (pdf);
        return 1;
    }

    HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);

    /* create default-font */
    font = HPDF_GetFont (pdf, "Helvetica", NULL);

    /* add a new page object. */
    page = HPDF_AddPage (pdf);

    HPDF_Page_SetWidth (page, 650);
    HPDF_Page_SetHeight (page, 500);

    dst = HPDF_Page_CreateDestination (page);
    HPDF_Destination_SetXYZ (dst, 0, HPDF_Page_GetHeight (page), 1);
    HPDF_SetOpenAction(pdf, dst);

    HPDF_Page_BeginText (page);
    HPDF_Page_SetFontAndSize (page, font, 20);
    HPDF_Page_MoveTextPos (page, 220, HPDF_Page_GetHeight (page) - 70);
    HPDF_Page_ShowText (page, "JpegDemo");
    HPDF_Page_EndText (page);

    HPDF_Page_SetFontAndSize (page, font, 12);

    draw_image (pdf, "rgb.jpg", 70, HPDF_Page_GetHeight (page) - 410,
                "24bit color image");
    draw_image (pdf, "gray.jpg", 340, HPDF_Page_GetHeight (page) - 410,
                "8bit grayscale image");

    /* save the document to a file */
    HPDF_SaveToFile (pdf, fname);

    /* clean up */
    HPDF_Free (pdf);

    return 0;
}
JNIEXPORT void JNICALL Java_org_libharu_Page_endText
  (JNIEnv *env, jobject obj)
{
  haru_setup_error_handler(env, __func__);
  HPDF_Page page = get_HPDF_Page(env, obj); 
  HPDF_Page_EndText (page);
  haru_clear_error_handler();
}
Beispiel #8
0
void echo2(HPDF_Page page, char *str1, int i, int j){

    HPDF_Page_EndText (page);

    HPDF_Page_Rectangle (page, 10 + (HPDF_Page_GetWidth(page)/100)*i, HPDF_Page_GetHeight(page)-25 - j*10, 200,
                20);
    HPDF_Page_Stroke (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, 12 + (HPDF_Page_GetWidth(page)/100)*i, HPDF_Page_GetHeight(page)-20 - j*10, str1);
};
Beispiel #9
0
/**
 * Enter/leave text mode and update PDF gstate for its clip, fill & stroke
 * colour, line width and dash pattern parameters.
 * \param selectTextMode true if text mode needs to be entered if required;
 * false otherwise.
 * \param fillCol Desired fill colour, use NS_TRANSPARENT if no update is
 * required.
 * \param strokeCol Desired stroke colour, use NS_TRANSPARENT if no update is
 * required.
 * \param lineWidth Desired line width. Only taken into account when strokeCol
 * is different from NS_TRANSPARENT.
 * \param dash Desired dash pattern. Only taken into account when strokeCol
 * is different from NS_TRANSPARENT.
 */
static void apply_clip_and_mode(bool selectTextMode, colour fillCol,
		colour strokeCol, float lineWidth, DashPattern_e dash)
{
	/* Leave text mode when
	 *  1) we're not setting text anymore
	 *  2) or we need to update the current clippath
	 *  3) or we need to update any fill/stroke colour, linewidth or dash.
	 * Note: the test on stroke parameters (stroke colour, line width and
	 * dash) is commented out as if these need updating we want to be
	 * outside the text mode anyway (i.e. selectTextMode is false).
	 */
	if (in_text_mode && (!selectTextMode || clip_update_needed
		|| (fillCol != NS_TRANSPARENT
			&& fillCol != pdfw_gs[pdfw_gs_level].fillColour)
		/* || (strokeCol != NS_TRANSPARENT
			&& (strokeCol != pdfw_gs[pdfw_gs_level].strokeColour
				|| lineWidth != pdfw_gs[pdfw_gs_level].lineWidth
				|| dash != pdfw_gs[pdfw_gs_level].dash)) */)) {
		HPDF_Page_EndText(pdf_page);
		in_text_mode = false;
	}

	if (clip_update_needed)
		pdfw_gs_restore(pdf_page);

	/* Update fill/stroke colour, linewidth and dash when needed.  */
	if (fillCol != NS_TRANSPARENT)
		pdfw_gs_fillcolour(pdf_page, fillCol);
	if (strokeCol != NS_TRANSPARENT) {
		pdfw_gs_strokecolour(pdf_page, strokeCol);
		pdfw_gs_linewidth(pdf_page, lineWidth);
		pdfw_gs_dash(pdf_page, dash);
	}

	if (clip_update_needed) {
		pdfw_gs_save(pdf_page);

		HPDF_Page_Rectangle(pdf_page, last_clip_x0,
				page_height - last_clip_y1,
				last_clip_x1 - last_clip_x0,
				last_clip_y1 - last_clip_y0);
		HPDF_Page_Clip(pdf_page);
		HPDF_Page_EndPath(pdf_page);

		clip_update_needed = false;
	}

	if (selectTextMode && !in_text_mode) {
		HPDF_Page_BeginText(pdf_page);
		in_text_mode = true;
	}
}
Beispiel #10
0
int CHaruPdf::EndText()
{_STT();

	// Sanity checks
	if ( !m_page )
		return 0;

	// End text
	if ( HPDF_OK != HPDF_Page_EndText( m_page ) )
		return 0;

	return 1;
}
Beispiel #11
0
void print_page_content(HPDF_Doc pdf, HPDF_Page page, LINE_INFO lines[], int n)
{
    HPDF_Font typewriter_font;
    RECT rcBox;
    int i, x, y;
    int font_size = CODE_FONT_SIZE;
    char buf[MAXSTRING];
    int content_height;
    int align;
    int line_num;

    /* rcBox is the bounding box of content area
     * get rid of the margin and padding */
    rcBox.left = page_margin.left + page_padding.left;
    rcBox.right = page_size.cx - page_margin.right - page_padding.right;
    rcBox.top = page_size.cy - page_margin.top - page_padding.top;
    rcBox.bottom = page_margin.bottom + page_padding.bottom;


    /* Try to position rcBox at the center of content area
     * If align turns out to be negative, then the rcBox is enlarged */
    content_height = LINES_PER_PAGE * font_size;
    align = (rcBox.top - rcBox.bottom - content_height) / 2;
    rcBox.top -= align;
    rcBox.bottom += align;
    
    typewriter_font = HPDF_GetFont (pdf, "Courier", NULL);
    HPDF_Page_SetFontAndSize (page, typewriter_font, font_size);
    HPDF_Page_BeginText(page);
    x = rcBox.left;
    y = rcBox.top - font_size;
    HPDF_Page_MoveTextPos(page, x, y);
    line_num = lines[0].line_num;
    for (i = 0; i < LINES_PER_PAGE; i++, line_num++)
    {
        if (no_line_number)
        {
            sprintf(buf, "  %s", i < n ? lines[i].line : "");
        }
        else
        {
            sprintf(buf, "%04d %s", line_num, i < n ? lines[i].line : "");
        }
        HPDF_Page_ShowText(page, buf);
        HPDF_Page_MoveTextPos(page, 0, -font_size);
    }
    HPDF_Page_EndText (page);
}
Beispiel #12
0
void print_page_header(HPDF_Doc pdf, HPDF_Page page, const char *header)
{
    HPDF_Font header_font;
    HPDF_REAL tw;
    HPDF_REAL width;
    header_font = HPDF_GetFont (pdf, default_font_name, NULL);
    HPDF_Page_SetFontAndSize (page, header_font, 12);
    tw = HPDF_Page_TextWidth (page, header);
    HPDF_Page_BeginText (page);

    width = page_size.cx - page_margin.left - page_margin.right,
    HPDF_Page_TextOut (page, 
                       page_margin.left + (width - tw) / 2, 
                       page_size.cy - page_margin.top + 6, 
                       header);
    HPDF_Page_EndText (page);
}
Beispiel #13
0
void
show_description  (HPDF_Page          page,
                   HPDF_REAL          x,
                   HPDF_REAL          y,
                   const char   *text)
{
    float fsize = HPDF_Page_GetCurrentFontSize (page);
    HPDF_Font font = HPDF_Page_GetCurrentFont (page);
    HPDF_RGBColor c = HPDF_Page_GetRGBFill (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_SetRGBFill (page, 0, 0, 0);
    HPDF_Page_SetTextRenderingMode (page, HPDF_FILL);
    HPDF_Page_SetFontAndSize (page, font, 10);
    HPDF_Page_TextOut (page, x, y - 12, text);
    HPDF_Page_EndText (page);

    HPDF_Page_SetFontAndSize (page, font, fsize);
    HPDF_Page_SetRGBFill (page, c.r, c.g, c.b);
}
Beispiel #14
0
void
draw_circles (HPDF_Page page, const char *description, HPDF_REAL x, HPDF_REAL y)
{
    HPDF_Page_SetLineWidth (page, 1.0f);
    HPDF_Page_SetRGBStroke (page, 0.0f, 0.0f, 0.0f);
    HPDF_Page_SetRGBFill (page, 1.0f, 0.0f, 0.0f);
    HPDF_Page_Circle (page, x + 40, y + 40, 40);
    HPDF_Page_ClosePathFillStroke (page);
    HPDF_Page_SetRGBFill (page, 0.0f, 1.0f, 0.0f);
    HPDF_Page_Circle (page, x + 100, y + 40, 40);
    HPDF_Page_ClosePathFillStroke (page);
    HPDF_Page_SetRGBFill (page, 0.0f, 0.0f, 1.0f);
    HPDF_Page_Circle (page, x + 70, y + 74.64, 40);
    HPDF_Page_ClosePathFillStroke (page);

    HPDF_Page_SetRGBFill (page, 0.0f, 0.0f, 0.0f);
    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, x + 0.0f, y + 130.0f, description);
    HPDF_Page_EndText (page);
}
Beispiel #15
0
void
print_page  (HPDF_Page page, HPDF_Font font, int page_num)
{
    char buf[50];

    HPDF_Page_SetWidth (page, 200);
    HPDF_Page_SetHeight (page, 200);

    HPDF_Page_SetFontAndSize (page, font, 20);

    HPDF_Page_BeginText (page);
    HPDF_Page_MoveTextPos (page, 50, 150);
#ifdef __WIN32__
    _snprintf(buf, 50, "Page:%d", page_num);
#else
    snprintf(buf, 50, "Page:%d", page_num);
#endif
    HPDF_Page_ShowText (page, buf);
    HPDF_Page_EndText (page);
}
Beispiel #16
0
void table(HPDF_Page page, HPDF_Font font, int row, int col, int X, int Y, int H,
        int *p, char**text){
    int width = HPDF_Page_GetWidth(page);
    //int height = HPDF_Page_GetHeight(page);
    int r=0, c=0, x, y, W = (width-20) / col;
    char tmp[130], tmp2[130];


    for (r = 0; r < row; r++)
    {
        x = 0; W = 0;
        for (c = 0; c < col; c++)
        {
            x = x + W;
            W = ((width-20)/100)*p[c];
            y = Y - (r * H);
            HPDF_Page_Rectangle (page, x +X , y , W, H);
            HPDF_Page_Stroke (page);

            HPDF_Page_BeginText (page);
            HPDF_Page_SetFontAndSize (page, font, 10);

            sprintf(tmp2, "%dx%d", r,c);
            sprintf(tmp,"[%s] %d %d %d %d | %d %d %d %d", tmp2, x , y, W, y, /*!*/ x+5 , y+10, x+W, y-10);
            sprintf(tmp,"[%s] %s", tmp2, text[(r*col)+c]);
            sprintf(tmp, "%s", text[(r*col)+c]);

            HPDF_Page_TextRect (page, x+2 +X+2 , y+15, x+W, y-10,
                    tmp, HPDF_TALIGN_LEFT, NULL);
            HPDF_Page_EndText (page);

            //HPDF_Page_TextRect (page, 10 , 600, 50, 550,
            //break;
        }
        //break;

    }
};
Beispiel #17
0
int main (int argc, char **argv)
{
    const char *page_title = "Font Demo";
    HPDF_Doc  pdf;
    char fname[256];
    HPDF_Page page;
    HPDF_Font def_font;
    HPDF_REAL tw;
    HPDF_REAL height;
    HPDF_REAL width;
    HPDF_UINT i;

    strcpy (fname, argv[0]);
    strcat (fname, ".pdf");

    pdf = HPDF_New (error_handler, NULL);
    if (!pdf) {
        printf ("error: cannot create PdfDoc object\n");
        return 1;
    }

    if (setjmp(env)) {
        HPDF_Free (pdf);
        return 1;
    }

    /* Add a new page object. */
    page = HPDF_AddPage (pdf);

    height = HPDF_Page_GetHeight (page);
    width = HPDF_Page_GetWidth (page);

    /* Print the lines of the page. */
    HPDF_Page_SetLineWidth (page, 1);
    HPDF_Page_Rectangle (page, 50, 50, width - 100, height - 110);
    HPDF_Page_Stroke (page);

    /* Print the title of the page (with positioning center). */
    def_font = HPDF_GetFont (pdf, "Helvetica", NULL);
    HPDF_Page_SetFontAndSize (page, def_font, 24);

    tw = HPDF_Page_TextWidth (page, page_title);
    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, (width - tw) / 2, height - 50, page_title);
    HPDF_Page_EndText (page);

    /* output subtitle. */
    HPDF_Page_BeginText (page);
    HPDF_Page_SetFontAndSize (page, def_font, 16);
    HPDF_Page_TextOut (page, 60, height - 80, "<Standerd Type1 fonts samples>");
    HPDF_Page_EndText (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_MoveTextPos (page, 60, height - 105);

    i = 0;
    while (font_list[i]) {
        const char* samp_text = "ÏðèâåòabcdefgABCDEFG12345!#$%&+-@?";
        HPDF_Font font = HPDF_GetFont (pdf, font_list[i], "CP1251");

        /* print a label of text */
        HPDF_Page_SetFontAndSize (page, def_font, 9);
        HPDF_Page_ShowText (page, font_list[i]);
        HPDF_Page_MoveTextPos (page, 0, -18);

        /* print a sample text. */
        HPDF_Page_SetFontAndSize (page, font, 20);
        HPDF_Page_ShowText (page, samp_text);
        HPDF_Page_MoveTextPos (page, 0, -20);

        i++;
    }

    HPDF_Page_EndText (page);

    HPDF_SaveToFile (pdf, fname);

    /* clean up */
    HPDF_Free (pdf);

    return 0;
}
Beispiel #18
0
int main(int argc, char **argv)
{
    HPDF_Doc  pdf;
    HPDF_Font font;
    HPDF_Page index_page;
    HPDF_Page page[9];
    HPDF_Destination dst;
    char fname[256];
    HPDF_Rect rect;
    HPDF_Point tp;
    HPDF_Annotation annot;
    HPDF_UINT i;
    const char *uri = "http://libharu.org";

    strcpy (fname, argv[0]);
    strcat (fname, ".pdf");

    pdf = HPDF_New (error_handler, NULL);
    if (!pdf) {
        printf ("error: cannot create PdfDoc object\n");
        return 1;
    }

    if (setjmp(env)) {
        HPDF_Free (pdf);
        return 1;
    }

    /* create default-font */
    font = HPDF_GetFont (pdf, "Helvetica", NULL);

    /* create index page */
    index_page = HPDF_AddPage (pdf);
    HPDF_Page_SetWidth (index_page, 300);
    HPDF_Page_SetHeight (index_page, 220);

    /* Add 7 pages to the document. */
    for (i = 0; i < 7; i++) {
        page[i] = HPDF_AddPage (pdf);
        print_page(page[i], font, i + 1);
    }

    HPDF_Page_BeginText (index_page);
    HPDF_Page_SetFontAndSize (index_page, font, 10);
    HPDF_Page_MoveTextPos (index_page, 15, 200);
    HPDF_Page_ShowText (index_page, "Link Annotation Demo");
    HPDF_Page_EndText (index_page);

    /*
     * Create Link-Annotation object on index page.
     */
    HPDF_Page_BeginText(index_page);
    HPDF_Page_SetFontAndSize (index_page, font, 8);
    HPDF_Page_MoveTextPos (index_page, 20, 180);
    HPDF_Page_SetTextLeading (index_page, 23);

    /* page1 (HPDF_ANNOT_NO_HIGHTLIGHT) */
    tp = HPDF_Page_GetCurrentTextPos (index_page);

    HPDF_Page_ShowText (index_page, "Jump to Page1 (HilightMode=HPDF_ANNOT_NO_HIGHTLIGHT)");
    rect.left = tp.x - 4;
    rect.bottom = tp.y - 4;
    rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4;
    rect.top = tp.y + 10;

    HPDF_Page_MoveToNextLine (index_page);

    dst = HPDF_Page_CreateDestination (page[0]);

    annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst);

    HPDF_LinkAnnot_SetHighlightMode (annot, HPDF_ANNOT_NO_HIGHTLIGHT);


    /* page2 (HPDF_ANNOT_INVERT_BOX) */
    tp = HPDF_Page_GetCurrentTextPos (index_page);

    HPDF_Page_ShowText (index_page, "Jump to Page2 (HilightMode=HPDF_ANNOT_INVERT_BOX)");
    rect.left = tp.x - 4;
    rect.bottom = tp.y - 4;
    rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4;
    rect.top = tp.y + 10;

    HPDF_Page_MoveToNextLine (index_page);

    dst = HPDF_Page_CreateDestination (page[1]);

    annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst);

    HPDF_LinkAnnot_SetHighlightMode (annot, HPDF_ANNOT_INVERT_BOX);


    /* page3 (HPDF_ANNOT_INVERT_BORDER) */
    tp = HPDF_Page_GetCurrentTextPos (index_page);

    HPDF_Page_ShowText (index_page, "Jump to Page3 (HilightMode=HPDF_ANNOT_INVERT_BORDER)");
    rect.left = tp.x - 4;
    rect.bottom = tp.y - 4;
    rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4;
    rect.top = tp.y + 10;

    HPDF_Page_MoveToNextLine (index_page);

    dst = HPDF_Page_CreateDestination (page[2]);

    annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst);

    HPDF_LinkAnnot_SetHighlightMode (annot, HPDF_ANNOT_INVERT_BORDER);


    /* page4 (HPDF_ANNOT_DOWN_APPEARANCE) */
    tp = HPDF_Page_GetCurrentTextPos (index_page);

    HPDF_Page_ShowText (index_page, "Jump to Page4 (HilightMode=HPDF_ANNOT_DOWN_APPEARANCE)");
    rect.left = tp.x - 4;
    rect.bottom = tp.y - 4;
    rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4;
    rect.top = tp.y + 10;

    HPDF_Page_MoveToNextLine (index_page);

    dst = HPDF_Page_CreateDestination (page[3]);

    annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst);

    HPDF_LinkAnnot_SetHighlightMode (annot, HPDF_ANNOT_DOWN_APPEARANCE);


    /* page5 (dash border) */
    tp = HPDF_Page_GetCurrentTextPos (index_page);

    HPDF_Page_ShowText (index_page, "Jump to Page5 (dash border)");
    rect.left = tp.x - 4;
    rect.bottom = tp.y - 4;
    rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4;
    rect.top = tp.y + 10;

    HPDF_Page_MoveToNextLine (index_page);

    dst = HPDF_Page_CreateDestination (page[4]);

    annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst);

    HPDF_LinkAnnot_SetBorderStyle (annot, 1, 3, 2);


    /* page6 (no border) */
    tp = HPDF_Page_GetCurrentTextPos (index_page);

    HPDF_Page_ShowText (index_page, "Jump to Page6 (no border)");
    rect.left = tp.x - 4;
    rect.bottom = tp.y - 4;
    rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4;
    rect.top = tp.y + 10;

    HPDF_Page_MoveToNextLine (index_page);

    dst = HPDF_Page_CreateDestination (page[5]);

    annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst);

    HPDF_LinkAnnot_SetBorderStyle (annot, 0, 0, 0);


    /* page7 (bold border) */
    tp = HPDF_Page_GetCurrentTextPos (index_page);

    HPDF_Page_ShowText (index_page, "Jump to Page7 (bold border)");
    rect.left = tp.x - 4;
    rect.bottom = tp.y - 4;
    rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4;
    rect.top = tp.y + 10;

    HPDF_Page_MoveToNextLine (index_page);

    dst = HPDF_Page_CreateDestination (page[6]);

    annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst);

    HPDF_LinkAnnot_SetBorderStyle (annot, 2, 0, 0);


    /* URI link */
    tp = HPDF_Page_GetCurrentTextPos (index_page);

    HPDF_Page_ShowText (index_page, "URI (");
    HPDF_Page_ShowText (index_page, uri);
    HPDF_Page_ShowText (index_page, ")");

    rect.left = tp.x - 4;
    rect.bottom = tp.y - 4;
    rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4;
    rect.top = tp.y + 10;

    HPDF_Page_CreateURILinkAnnot (index_page, rect, uri);

    HPDF_Page_EndText (index_page);

    /* save the document to a file */
    HPDF_SaveToFile (pdf, fname);

    /* clean up */
    HPDF_Free (pdf);

    return 0;
}
Beispiel #19
0
int
main (int argc, char **argv)
{
    HPDF_Doc  pdf;
    HPDF_Page page;
    char fname[256];
    HPDF_Font font;
    //float angle1;
    //float angle2;
    //float rad1;
    //float rad2;
    //HPDF_REAL page_height;
    HPDF_Rect rect;
    //int i;

    //const char* SAMP_TXT = "Дирк Мюллер: власть над миром принадлежит банкам";


    strcpy (fname, argv[0]);
    strcat (fname, ".pdf");

    pdf = HPDF_New (error_handler, NULL);
    if (!pdf) {
        printf ("error: cannot create PdfDoc object\n");
        return 1;
    }

    if (setjmp(env)) {
        HPDF_Free (pdf);
        return 1;
    }

    //printf("%s\n",HPDF_GetCurrentEncoder (pdf));

    /* add a new page object. */
    page = HPDF_AddPage (pdf);
    HPDF_Page_SetSize (page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_LANDSCAPE); // HPDF_PAGE_PORTRAIT

    //print_grid  (pdf, page);

    //page_height = HPDF_Page_GetHeight (page);

    //page_height += 0;

    font = HPDF_GetFont (pdf, "Courier", "CP1251");
    HPDF_Page_SetTextLeading (page, 20);

    /* text_rect method */

    /* HPDF_TALIGN_LEFT */
    rect.left = 25;
    rect.top = 545;
    rect.right = 200;
    rect.bottom = rect.top - 20;



    //~ HPDF_Page_Rectangle (page, 200 , 300 , 300, 100);
    //~ HPDF_Page_Stroke (page);

    //~ HPDF_Page_BeginText (page);
    //~ HPDF_Page_SetFontAndSize (page, font, 10);


    //~ int cnt =0;
    //~ HPDF_Page_TextRect (page, 10 , 600, 50, 550,
            //~ "123 45 6789 123 45 6789",
                    //~ HPDF_TALIGN_LEFT, &cnt);
    //~ printf("printed %d\n", cnt);
    //~ HPDF_Page_EndText (page);

    HPDF_Page_BeginText (page);



    HPDF_Page_SetFontAndSize (page, font, 11);
    //HPDF_Page_TextOut (page, rect.left, rect.top + 3, "Поставщик");

    echo1(page, "Поставщик", "ООО «РЕКО»", 0);
    echo1(page, "ИНН", "4345363002", 1);
    echo1(page, "КПП", "434501001", 2);
    echo1(page, "Телефон/факс", "62-38-67, 78-88-58", 3);
    echo1(page, "Расчетный счет", "40702810200220090271", 4);
    echo1(page, "Корр. счет", "30101810100000000711", 5);
    echo1(page, "Банк", "ОАО КБ «Хлынов» г. Киров", 6);
    echo1(page, "БИК", "043304711", 7);
    echo1(page, "", "Счет № / от ", 8);
    echo1(page, "Плательщик: КОГКУ «Государственный архив социально-политической истории Кировской области»", "", 10);
    echo1(page, "Юр. г. Киров, ул. Казанская, 16а,", "", 11);
    echo1(page, "Факс: (8332) 35-75-56,", "", 12);
    echo1(page, "ИНН: 4345057460 ", "", 13);

    HPDF_Page_SetFontAndSize (page, font, 12);
    HPDF_Page_EndText (page);

    int collum_size[] = {40, 7, 10, 7, 12, 12, 12};

    char* text[] = {"Наименование товара", "Ед.Изм.", "Количество", "Цена", "Сумма без НДС", "Сумма НДС", "Всего с НДС",
        "1. Оказание услуг хостинга с 01 апреля 2015г. по 30 июня 2015г.", "шт.", "1", "5100=00", "5100=00", "0", "5100=00",
        "Всего к оплате:", "", "", "", "5100=00", "0", "5100=00"
        };

    table(page, font, 3, 7, 10,  HPDF_Page_GetHeight(page)-20 - (17*10), 20, /*!*/
            collum_size, text);

    draw_image (pdf, "shtamp2.png", 100, 0 , "8bit alpha.");

    int collum_size2[] = {50, 50};
    char* text2[] = {"Итого: Пять тысяч сто рублей 00 копеек", "5100=00 ",
            "ООО «РЕКО» применяет упрощенную систему налогообложения", "",
            "Директор ООО «РЕКО» ______________ /Лажинцев П.В./ ", " Главный бухгалтер ______________/_________________/ "
        };
    table(page, font, 3, 2, 10,  HPDF_Page_GetHeight(page)-20 - (25*10), 20, /*!*/
            collum_size2, text2);




    /* HPDF_TALIGN_RIGTH */
    //~ rect.left = 220;
    //~ rect.right = 395;
//~
    //~ HPDF_Page_Rectangle (page, rect.left, rect.bottom, rect.right - rect.left,
                //~ rect.top - rect.bottom);
    //~ HPDF_Page_Stroke (page);
//~
    //~ HPDF_Page_BeginText (page);
//~
    //~ HPDF_Page_SetFontAndSize (page, font, 10);
    //~ HPDF_Page_TextOut (page, rect.left, rect.top + 3, "HPDF_TALIGN_RIGTH");
//~
    //~ HPDF_Page_SetFontAndSize (page, font, 13);
    //~ HPDF_Page_TextRect (page, rect.left, rect.top, rect.right, rect.bottom,
                //~ SAMP_TXT, HPDF_TALIGN_RIGHT, NULL);
//~
//~
    //~ HPDF_Page_EndText (page);

    //~ /* HPDF_TALIGN_CENTER */
    //~ rect.left = 25;
    //~ rect.top = 475;
    //~ rect.right = 200;
    //~ rect.bottom = rect.top - 40;
//~
    //~ HPDF_Page_Rectangle (page, rect.left, rect.bottom, rect.right - rect.left,
                //~ rect.top - rect.bottom);
    //~ HPDF_Page_Stroke (page);
//~
    //~ HPDF_Page_BeginText (page);
//~
    //~ HPDF_Page_SetFontAndSize (page, font, 10);
    //~ HPDF_Page_TextOut (page, rect.left, rect.top + 3, "HPDF_TALIGN_CENTER");
//~
    //~ HPDF_Page_SetFontAndSize (page, font, 13);
    //~ HPDF_Page_TextRect (page, rect.left, rect.top, rect.right, rect.bottom,
                //~ SAMP_TXT, HPDF_TALIGN_CENTER, NULL);
//~
    //~ HPDF_Page_EndText (page);
//~
    //~ /* HPDF_TALIGN_JUSTIFY */
    //~ rect.left = 220;
    //~ rect.right = 395;
//~
    //~ HPDF_Page_Rectangle (page, rect.left, rect.bottom, rect.right - rect.left,
                //~ rect.top - rect.bottom);
    //~ HPDF_Page_Stroke (page);
//~
    //~ HPDF_Page_BeginText (page);
//~
    //~ HPDF_Page_SetFontAndSize (page, font, 10);
    //~ HPDF_Page_TextOut (page, rect.left, rect.top + 3, "HPDF_TALIGN_JUSTIFY");
//~
    //~ HPDF_Page_SetFontAndSize (page, font, 13);
    //~ HPDF_Page_TextRect (page, rect.left, rect.top, rect.right, rect.bottom,
                //~ SAMP_TXT, HPDF_TALIGN_JUSTIFY, NULL);
//~
    //~ HPDF_Page_EndText (page);
//~
//~
//~
    //~ /* Skewed coordinate system */
    //~ HPDF_Page_GSave (page);
//~
    //~ angle1 = 5;
    //~ angle2 = 10;
    //~ rad1 = angle1 / 180 * 3.141592;
    //~ rad2 = angle2 / 180 * 3.141592;
//~
    //~ HPDF_Page_Concat (page, 1, tan(rad1), tan(rad2), 1, 25, 350);
    //~ rect.left = 0;
    //~ rect.top = 40;
    //~ rect.right = 175;
    //~ rect.bottom = 0;
//~
    //~ HPDF_Page_Rectangle (page, rect.left, rect.bottom, rect.right - rect.left,
                //~ rect.top - rect.bottom);
    //~ HPDF_Page_Stroke (page);
//~
    //~ HPDF_Page_BeginText (page);
//~
    //~ HPDF_Page_SetFontAndSize (page, font, 10);
    //~ HPDF_Page_TextOut (page, rect.left, rect.top + 3, "Skewed coordinate system");
//~
    //~ HPDF_Page_SetFontAndSize (page, font, 13);
    //~ HPDF_Page_TextRect (page, rect.left, rect.top, rect.right, rect.bottom,
                //~ SAMP_TXT, HPDF_TALIGN_LEFT, NULL);
//~
    //~ HPDF_Page_EndText (page);
//~
    //~ HPDF_Page_GRestore (page);
//~
//~
    //~ /* Rotated coordinate system */
    //~ HPDF_Page_GSave (page);
//~
    //~ angle1 = 5;
    //~ rad1 = angle1 / 180 * 3.141592;
//~
    //~ HPDF_Page_Concat (page, cos(rad1), sin(rad1), -sin(rad1), cos(rad1), 220, 350);
    //~ rect.left = 0;
    //~ rect.top = 40;
    //~ rect.right = 175;
    //~ rect.bottom = 0;
//~
    //~ HPDF_Page_Rectangle (page, rect.left, rect.bottom, rect.right - rect.left,
                //~ rect.top - rect.bottom);
    //~ HPDF_Page_Stroke (page);
//~
    //~ HPDF_Page_BeginText (page);
//~
    //~ HPDF_Page_SetFontAndSize (page, font, 10);
    //~ HPDF_Page_TextOut (page, rect.left, rect.top + 3, "Rotated coordinate system");
//~
    //~ HPDF_Page_SetFontAndSize (page, font, 13);
    //~ HPDF_Page_TextRect (page, rect.left, rect.top, rect.right, rect.bottom,
                //~ SAMP_TXT, HPDF_TALIGN_LEFT, NULL);
//~
    //~ HPDF_Page_EndText (page);
//~
    //~ HPDF_Page_GRestore (page);
//~
//~
    //~ /* text along a circle */
    //~ HPDF_Page_SetGrayStroke (page, 0);
    //~ HPDF_Page_Circle (page, 210, 190, 145);
    //~ HPDF_Page_Circle (page, 210, 190, 113);
    //~ HPDF_Page_Stroke (page);
//~
    //~ angle1 = 360 / (strlen (SAMP_TXT));
    //~ angle2 = 180;
//~
    //~ HPDF_Page_BeginText (page);
    //~ font = HPDF_GetFont (pdf, "Courier-Bold", NULL);
    //~ HPDF_Page_SetFontAndSize (page, font, 30);
//~
    //~ for (i = 0; i < strlen (SAMP_TXT); i++) {
        //~ char buf[2];
        //~ float x;
        //~ float y;
//~
        //~ rad1 = (angle2 - 90) / 180 * 3.141592;
        //~ rad2 = angle2 / 180 * 3.141592;
//~
        //~ x = 210 + cos(rad2) * 122;
        //~ y = 190 + sin(rad2) * 122;
//~
        //~ HPDF_Page_SetTextMatrix(page, cos(rad1), sin(rad1), -sin(rad1), cos(rad1), x, y);
//~
        //~ buf[0] = SAMP_TXT[i];
        //~ buf[1] = 0;
        //~ HPDF_Page_ShowText (page, buf);
        //~ angle2 -= angle1;
    //~ }
//~
    //~ HPDF_Page_EndText (page);

    /* save the document to a file */
    HPDF_SaveToFile (pdf, fname);

    /* clean up */
    HPDF_Free (pdf);

    return 0;
}
Beispiel #20
0
int main (int argc, char **argv)
{
    const char *page_title = "Text Demo";

    HPDF_Doc  pdf;
    HPDF_Font font;
    HPDF_Page page;
    char fname[256];

    const char* samp_text = "abcdefgABCDEFG123!#$%&+-@?";
    const char* samp_text2 = "The quick brown fox jumps over the lazy dog.";
    float tw;
    float fsize;
    int i;
    int len;

    float angle1;
    float angle2;
    float rad1;
    float rad2;

    float ypos;

    strcpy (fname, argv[0]);
    strcat (fname, ".pdf");

    pdf = HPDF_New (error_handler, NULL);
    if (!pdf) {
        printf ("error: cannot create PdfDoc object\n");
        return 1;
    }

    if (setjmp(env)) {
        HPDF_Free (pdf);
        return 1;
    }

    /* set compression mode */
    HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);

    /* create default-font */
    font = HPDF_GetFont (pdf, "Helvetica", NULL);

    /* add a new page object. */
    page = HPDF_AddPage (pdf);

    /* draw grid to the page */
    print_grid  (pdf, page);

    /* print the lines of the page.
    HPDF_Page_SetLineWidth (page, 1);
    HPDF_Page_Rectangle (page, 50, 50, HPDF_Page_GetWidth(page) - 100,
                HPDF_Page_GetHeight (page) - 110);
    HPDF_Page_Stroke (page);
    */

    /* print the title of the page (with positioning center). */
    HPDF_Page_SetFontAndSize (page, font, 24);
    tw = HPDF_Page_TextWidth (page, page_title);
    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, (HPDF_Page_GetWidth(page) - tw) / 2,
                HPDF_Page_GetHeight (page) - 50, page_title);
    HPDF_Page_EndText (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_MoveTextPos (page, 60, HPDF_Page_GetHeight(page) - 60);

    /*
     * font size
     */
    fsize = 8;
    while (fsize < 60) {
        char buf[50];
        int len;

        /* set style and size of font. */
        HPDF_Page_SetFontAndSize(page, font, fsize);

        /* set the position of the text. */
        HPDF_Page_MoveTextPos (page, 0, -5 - fsize);

        /* measure the number of characters which included in the page. */
        strcpy(buf, samp_text);
        len = HPDF_Page_MeasureText (page, samp_text,
                        HPDF_Page_GetWidth(page) - 120, HPDF_FALSE, NULL);

        /* truncate the text. */
        buf[len] = 0x00;

        HPDF_Page_ShowText (page, buf);

        /* print the description. */
        HPDF_Page_MoveTextPos (page, 0, -10);
        HPDF_Page_SetFontAndSize(page, font, 8);
        #ifdef __WIN32__
        _snprintf(buf, 50, "Fontsize=%.0f", fsize);
        #else
        snprintf(buf, 50, "Fontsize=%.0f", fsize);
        #endif
        HPDF_Page_ShowText (page, buf);

        fsize *= 1.5;
    }

    /*
     * font color
     */
    HPDF_Page_SetFontAndSize(page, font, 8);
    HPDF_Page_MoveTextPos (page, 0, -30);
    HPDF_Page_ShowText (page, "Font color");

    HPDF_Page_SetFontAndSize (page, font, 18);
    HPDF_Page_MoveTextPos (page, 0, -20);
    len = strlen (samp_text);
    for (i = 0; i < len; i++) {
        char buf[2];
        float r = (float)i / (float)len;
        float g = 1 - ((float)i / (float)len);
        buf[0] = samp_text[i];
        buf[1] = 0x00;

        HPDF_Page_SetRGBFill (page, r, g, 0.0);
        HPDF_Page_ShowText (page, buf);
    }
    HPDF_Page_MoveTextPos (page, 0, -25);

    for (i = 0; i < len; i++) {
        char buf[2];
        float r = (float)i / (float)len;
        float b = 1 - ((float)i / (float)len);
        buf[0] = samp_text[i];
        buf[1] = 0x00;

        HPDF_Page_SetRGBFill (page, r, 0.0, b);
        HPDF_Page_ShowText (page, buf);
    }
    HPDF_Page_MoveTextPos (page, 0, -25);

    for (i = 0; i < len; i++) {
        char buf[2];
        float b = (float)i / (float)len;
        float g = 1 - ((float)i / (float)len);
        buf[0] = samp_text[i];
        buf[1] = 0x00;

        HPDF_Page_SetRGBFill (page, 0.0, g, b);
        HPDF_Page_ShowText (page, buf);
    }

    HPDF_Page_EndText (page);

    ypos = 450;

    /*
     * Font rendering mode
     */
    HPDF_Page_SetFontAndSize(page, font, 32);
    HPDF_Page_SetRGBFill (page, 0.5, 0.5, 0.0);
    HPDF_Page_SetLineWidth (page, 1.5);

     /* PDF_FILL */
    show_description (page,  60, ypos,
                "RenderingMode=PDF_FILL");
    HPDF_Page_SetTextRenderingMode (page, HPDF_FILL);
    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, 60, ypos, "ABCabc123");
    HPDF_Page_EndText (page);

    /* PDF_STROKE */
    show_description (page, 60, ypos - 50,
                "RenderingMode=PDF_STROKE");
    HPDF_Page_SetTextRenderingMode (page, HPDF_STROKE);
    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, 60, ypos - 50, "ABCabc123");
    HPDF_Page_EndText (page);

    /* PDF_FILL_THEN_STROKE */
    show_description (page, 60, ypos - 100,
                "RenderingMode=PDF_FILL_THEN_STROKE");
    HPDF_Page_SetTextRenderingMode (page, HPDF_FILL_THEN_STROKE);
    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, 60, ypos - 100, "ABCabc123");
    HPDF_Page_EndText (page);

    /* PDF_FILL_CLIPPING */
    show_description (page, 60, ypos - 150,
                "RenderingMode=PDF_FILL_CLIPPING");
    HPDF_Page_GSave (page);
    HPDF_Page_SetTextRenderingMode (page, HPDF_FILL_CLIPPING);
    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, 60, ypos - 150, "ABCabc123");
    HPDF_Page_EndText (page);
    show_stripe_pattern (page, 60, ypos - 150);
    HPDF_Page_GRestore (page);

    /* PDF_STROKE_CLIPPING */
    show_description (page, 60, ypos - 200,
                "RenderingMode=PDF_STROKE_CLIPPING");
    HPDF_Page_GSave (page);
    HPDF_Page_SetTextRenderingMode (page, HPDF_STROKE_CLIPPING);
    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, 60, ypos - 200, "ABCabc123");
    HPDF_Page_EndText (page);
    show_stripe_pattern (page, 60, ypos - 200);
    HPDF_Page_GRestore (page);

    /* PDF_FILL_STROKE_CLIPPING */
    show_description (page, 60, ypos - 250,
                "RenderingMode=PDF_FILL_STROKE_CLIPPING");
    HPDF_Page_GSave (page);
    HPDF_Page_SetTextRenderingMode (page, HPDF_FILL_STROKE_CLIPPING);
    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, 60, ypos - 250, "ABCabc123");
    HPDF_Page_EndText (page);
    show_stripe_pattern (page, 60, ypos - 250);
    HPDF_Page_GRestore (page);

    /* Reset text attributes */
    HPDF_Page_SetTextRenderingMode (page, HPDF_FILL);
    HPDF_Page_SetRGBFill (page, 0, 0, 0);
    HPDF_Page_SetFontAndSize(page, font, 30);


    /*
     * Rotating text
     */
    angle1 = 30;                   /* A rotation of 30 degrees. */
    rad1 = angle1 / 180 * 3.141592; /* Calcurate the radian value. */

    show_description (page, 320, ypos - 60, "Rotating text");
    HPDF_Page_BeginText (page);
    HPDF_Page_SetTextMatrix (page, cos(rad1), sin(rad1), -sin(rad1), cos(rad1),
                330, ypos - 60);
    HPDF_Page_ShowText (page, "ABCabc123");
    HPDF_Page_EndText (page);


    /*
     * Skewing text.
     */
    show_description (page, 320, ypos - 120, "Skewing text");
    HPDF_Page_BeginText (page);

    angle1 = 10;
    angle2 = 20;
    rad1 = angle1 / 180 * 3.141592;
    rad2 = angle2 / 180 * 3.141592;

    HPDF_Page_SetTextMatrix (page, 1, tan(rad1), tan(rad2), 1, 320, ypos - 120);
    HPDF_Page_ShowText (page, "ABCabc123");
    HPDF_Page_EndText (page);


    /*
     * scaling text (X direction)
     */
    show_description (page, 320, ypos - 175, "Scaling text (X direction)");
    HPDF_Page_BeginText (page);
    HPDF_Page_SetTextMatrix (page, 1.5, 0, 0, 1, 320, ypos - 175);
    HPDF_Page_ShowText (page, "ABCabc12");
    HPDF_Page_EndText (page);


    /*
     * scaling text (Y direction)
     */
    show_description (page, 320, ypos - 250, "Scaling text (Y direction)");
    HPDF_Page_BeginText (page);
    HPDF_Page_SetTextMatrix (page, 1, 0, 0, 2, 320, ypos - 250);
    HPDF_Page_ShowText (page, "ABCabc123");
    HPDF_Page_EndText (page);


    /*
     * char spacing, word spacing
     */

    show_description (page, 60, 140, "char-spacing 0");
    show_description (page, 60, 100, "char-spacing 1.5");
    show_description (page, 60, 60, "char-spacing 1.5, word-spacing 2.5");

    HPDF_Page_SetFontAndSize (page, font, 20);
    HPDF_Page_SetRGBFill (page, 0.1, 0.3, 0.1);

    /* char-spacing 0 */
    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, 60, 140, samp_text2);
    HPDF_Page_EndText (page);

    /* char-spacing 1.5 */
    HPDF_Page_SetCharSpace (page, 1.5);

    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, 60, 100, samp_text2);
    HPDF_Page_EndText (page);

    /* char-spacing 1.5, word-spacing 3.5 */
    HPDF_Page_SetWordSpace (page, 2.5);

    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, 60, 60, samp_text2);
    HPDF_Page_EndText (page);

    /* save the document to a file */
    HPDF_SaveToFile (pdf, fname);

    /* clean up */
    HPDF_Free (pdf);

    return 0;
}
Beispiel #21
0
int main (int argc, char **argv)
{
    HPDF_Doc  pdf;
    char fname[256];
    HPDF_Font font;
    const char *font_name;
    int i = 0;
    HPDF_Outline root;

    const char *encodings[] = {
            "StandardEncoding",
            "MacRomanEncoding",
            "WinAnsiEncoding",
            "ISO8859-2",
            "ISO8859-3",
            "ISO8859-4",
            "ISO8859-5",
            "ISO8859-9",
            "ISO8859-10",
            "ISO8859-13",
            "ISO8859-14",
            "ISO8859-15",
            "ISO8859-16",
            "CP1250",
            "CP1251",
            "CP1252",
            "CP1254",
            "CP1257",
            "KOI8-R",
            "Symbol-Set",
            "ZapfDingbats-Set",
            NULL
    };

    pdf = HPDF_NewEx (error_handler, NULL, NULL, 0, NULL);
    if (!pdf) {
        printf ("error: cannot create PdfDoc object\n");
        return 1;
    }

    if (setjmp(env)) {
        HPDF_Free (pdf);
        return 1;
    }

    strcpy (fname, argv[0]);
    strcat (fname, ".pdf");

    /* set compression mode */
    HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);

    /* Set page mode to use outlines. */
    HPDF_SetPageMode(pdf, HPDF_PAGE_MODE_USE_OUTLINE);

    /* get default font */
    font = HPDF_GetFont (pdf, "Helvetica", NULL);

    /* load font object */
    #ifdef __WIN32__
    font_name = HPDF_LoadType1FontFromFile (pdf, "type1\\a010013l.afm",
            "type1\\a010013l.pfb");
    #else
    font_name = HPDF_LoadType1FontFromFile (pdf, "type1/a010013l.afm",
            "type1/a010013l.pfb");
    #endif

    /* create outline root. */
    root = HPDF_CreateOutline (pdf, NULL, "Encoding list", NULL);
    HPDF_Outline_SetOpened (root, HPDF_TRUE);

    while (encodings[i]) {
        HPDF_Page page = HPDF_AddPage (pdf);
        HPDF_Outline outline;
        HPDF_Destination dst;
        HPDF_Font font2;

        HPDF_Page_SetWidth (page, PAGE_WIDTH);
        HPDF_Page_SetHeight (page, PAGE_HEIGHT);

        outline = HPDF_CreateOutline (pdf, root, encodings[i], NULL);
        dst = HPDF_Page_CreateDestination (page);
        HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page), 1);
        /* HPDF_Destination_SetFitB(dst); */
        HPDF_Outline_SetDestination(outline, dst);

        HPDF_Page_SetFontAndSize (page, font, 15);
        draw_graph (page);

        HPDF_Page_BeginText (page);
        HPDF_Page_SetFontAndSize (page, font, 20);
        HPDF_Page_MoveTextPos (page, 40, PAGE_HEIGHT - 50);
        HPDF_Page_ShowText (page, encodings[i]);
        HPDF_Page_ShowText (page, " Encoding");
        HPDF_Page_EndText (page);

        if (strcmp (encodings[i], "Symbol-Set") == 0)
            font2 = HPDF_GetFont (pdf, "Symbol", NULL);
        else if (strcmp (encodings[i], "ZapfDingbats-Set") == 0)
            font2 = HPDF_GetFont (pdf, "ZapfDingbats", NULL);
        else
            font2 = HPDF_GetFont (pdf, font_name, encodings[i]);

        HPDF_Page_SetFontAndSize (page, font2, 14);
        draw_fonts (page);

        i++;
    }

    /* save the document to a file */
    HPDF_SaveToFile (pdf, fname);

    /* clean up */
    HPDF_Free (pdf);

    return 0;
}
Beispiel #22
0
void WPdfImage::drawText(const WRectF& rect, 
			 WFlags<AlignmentFlag> flags,
			 TextFlag textFlag,
			 const WString& text,
			 const WPointF *clipPoint)
{
  // FIXME: textFlag
  
  if (clipPoint && painter() && !painter()->clipPath().isEmpty()) {
    if (!painter()->clipPathTransform().map(painter()->clipPath())
	  .isPointInPath(painter()->worldTransform().map(*clipPoint)))
      return;
  }

  if (trueTypeFont_ && !trueTypeFonts_->busy())
    trueTypeFonts_->drawText(painter()->font(), rect, flags, text);
  else {
    HPDF_REAL left, top, right, bottom;
    HPDF_TextAlignment alignment = HPDF_TALIGN_LEFT;

    AlignmentFlag horizontalAlign = flags & AlignHorizontalMask;
    AlignmentFlag verticalAlign = flags & AlignVerticalMask;

    switch (horizontalAlign) {
    default:
      // should never happen
    case AlignmentFlag::Left:
      left = rect.left();
      right = left + 10000;
      alignment = HPDF_TALIGN_LEFT;
      break;
    case AlignmentFlag::Right:
      right = rect.right();
      left = right - 10000;
      alignment = HPDF_TALIGN_RIGHT;
      break;
    case AlignmentFlag::Center:
      {
	float center = rect.center().x();
	left = center - 5000;
	right = center + 5000;
	alignment = HPDF_TALIGN_CENTER;
	break;
      }
    }

    switch (verticalAlign) {
    default:
      // fall-through ; should never happen
    case AlignmentFlag::Top:
      top = rect.top(); break;
    case AlignmentFlag::Middle:
      // FIXME: use font metrics to center middle of ascent !
      top = rect.center().y() - 0.60 * fontSize_; break;
    case AlignmentFlag::Bottom:
      top = rect.bottom() - fontSize_; break;
    }

    bottom = top + fontSize_;

    if (trueTypeFonts_->busy())
      setChanged(PainterChangeFlag::Font);

    HPDF_Page_GSave(page_);

    // Undo the global inversion
    HPDF_Page_Concat(page_, 1, 0, 0, -1, 0, bottom);

    HPDF_Page_BeginText(page_);

    // Need to fill text using pen color
    const WColor& penColor = painter()->pen().color();
    HPDF_Page_SetRGBFill(page_,
			 penColor.red() / 255.,
			 penColor.green() / 255.,
			 penColor.blue() / 255.);

    std::string s = trueTypeFont_ ? text.toUTF8() : text.narrow();

    HPDF_Page_TextRect(page_, left, fontSize_, right, 0, s.c_str(),
		       alignment, nullptr);

    HPDF_Page_EndText(page_);

    HPDF_Page_GRestore(page_);
  }
}
Beispiel #23
0
void hpdf_doc::add_text(et_datachunk &dc)
{
	et_type datatype = dc.type;
	wstring &out_string = dc.w_string;

	char *line = new char[4096];
	memset(line, 0, 4096);
	_locale_t loceng;
	size_t size = 0;

	loceng = _create_locale(LC_ALL, "en-US");

	int len = out_string.length(); // count of space
	int n_TX = (et_cp.TX > 0) ? et_cp.TX : et_cp.T,
		n_TY = (et_cp.TY > 0) ? et_cp.TY : et_cp.T;

	HPDF_REAL f_xpos = dc.rect.left, f_ypos = dc.rect.bottom;
	HPDF_REAL f_advance = 0.0;
	HPDF_REAL f_width = MMTEXT2PTX(et_cp.W * n_TX / 2);
	HPDF_REAL f_gap = MMTEXT2PTX(et_cp.X/2);
	HPDF_REAL f_space = MMTEXT2PTY((et_cp.Z * n_TY) + et_cp.L);

	HPDF_Page_BeginText(h_current_page);

	select_datatype_font(datatype);

	f_space = HPDF_Page_GetCurrentFontSize(h_current_page);

	if (f_space > f_linespace)
		f_linespace = f_space;


	switch (datatype) {
	case ET_LATAN:
		
		/*
		size = _wcstombs_l(line, out_string.c_str(), 4096, loceng);
		if (size == 0) goto END_PROC;

		HPDF_Page_TextOut(h_current_page, f_xpos, f_ypos - f_linespace, line);
		f_advance = HPDF_Page_TextWidth(h_current_page, line); 
		*/
		if (et_cp.CorE == 'C') f_width = f_width * 2;
		text_out_eng(f_xpos, f_ypos, out_string, f_advance, f_width, f_gap, f_space, loceng);
		break;
	case ET_SPACE:
		f_advance += ((f_width + f_gap) * len);
		break;

	case ET_CJK:
	case ET_CJKFORM:
	case ET_BOXDRAW:

		if (et_cp.VorH == 'H' || datatype != ET_CJK)
			horizontal(f_xpos, f_ypos);
		else
			vertical(f_xpos, f_ypos);

		if (datatype == ET_BOXDRAW) resize_font_boxdraw();
		/*
		size = wchar_to_utf8(out_string.c_str(), out_string.length(), line, 4096, NULL);
		if (size == 0) goto END_PROC;
		
		HPDF_Page_TextOut(h_current_page, f_xpos, f_ypos - f_linespace, line);
		//if (datatype == ET_BOXDRAW)
		//	f_advance += (len * ((f_width + f_gap) * 2));
		//else
			f_advance += HPDF_Page_TextWidth(h_current_page, line); //(len * ((f_width + f_gap) * 2));
			*/
		text_out_cjk(f_xpos, f_ypos, out_string, f_advance, f_width, f_gap, f_space);

		break;
	}
	HPDF_Page_EndText(h_current_page);
	
	if (et_cp.U > 0)
	{
		HPDF_Page_SetLineWidth(h_current_page, 0.5);
		HPDF_Page_MoveTo(h_current_page, f_xpos, f_ypos - f_linespace);
		HPDF_Page_LineTo(h_current_page, f_xpos, f_ypos);
		HPDF_Page_Stroke(h_current_page);
	}
	
	f_xpos += f_advance;

	delete [] line; // free buffer

	_free_locale(loceng);
}
Beispiel #24
0
void WPdfImage::drawText(const WRectF& rect, 
			 WFlags<AlignmentFlag> flags,
			 TextFlag textFlag,
			 const WString& text)
{
  // FIXME: textFlag

  if (trueTypeFont_ && !trueTypeFonts_->busy())
    trueTypeFonts_->drawText(painter()->font(), rect, flags, text);
  else {
    HPDF_REAL left, top, right, bottom;
    HPDF_TextAlignment alignment;

    AlignmentFlag horizontalAlign = flags & AlignHorizontalMask;
    AlignmentFlag verticalAlign = flags & AlignVerticalMask;

    switch (horizontalAlign) {
    case AlignLeft:
      left = rect.left();
      right = left + 1000;
      alignment = HPDF_TALIGN_LEFT;
      break;
    case AlignRight:
      right = rect.right();
      left = right - 1000;
      alignment = HPDF_TALIGN_RIGHT;
      break;
    case AlignCenter:
      {
	float center = rect.center().x();
	left = center - 500;
	right = center + 500;
	alignment = HPDF_TALIGN_CENTER;
	break;
      }
    default:
      break;
    }

    switch (verticalAlign) {
    case AlignTop:
      top = rect.top(); break;
    case AlignMiddle:
      // FIXME: use font metrics to center middle of ascent !
      top = rect.center().y() - 0.60 * fontSize_; break;
    case AlignBottom:
      top = rect.bottom() - fontSize_; break;
    default:
      break;
    }

    bottom = top + fontSize_;

    if (trueTypeFonts_->busy())
      setChanged(Font);

    HPDF_Page_GSave(page_);

    // Undo the global inversion
    HPDF_Page_Concat(page_, 1, 0, 0, -1, 0, bottom);

    HPDF_Page_BeginText(page_);

    // Need to fill text using pen color
    const WColor& penColor = painter()->pen().color();
    HPDF_Page_SetRGBFill(page_,
			 penColor.red() / 255.,
			 penColor.green() / 255.,
			 penColor.blue() / 255.);

    std::string s = trueTypeFont_ ? text.toUTF8() : text.narrow();

    HPDF_Page_TextRect(page_, left, fontSize_, right, 0, s.c_str(),
		       alignment, 0);

    HPDF_Page_EndText(page_);

    HPDF_Page_GRestore(page_);
  }
}
int main (int argc, char **argv)
{
    HPDF_Doc  pdf;
    HPDF_Font font;
    HPDF_Page page;
    char fname[256];
    HPDF_Image image;
	char *png_image_data;
	FILE *fp;

    HPDF_REAL x, y;

    strcpy (fname, argv[0]);
    strcat (fname, ".pdf");

    pdf = HPDF_New (error_handler, NULL);
    if (!pdf) {
        printf ("error: cannot create PdfDoc object\n");
        return 1;
    }

    /* error-handler */
    if (setjmp(env)) {
        HPDF_Free (pdf);
        return 1;
    }

    HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);

    /* create default-font */
    font = HPDF_GetFont (pdf, "Helvetica", NULL);

    /* add a new page object. */
    page = HPDF_AddPage (pdf);

    HPDF_Page_BeginText (page);
    HPDF_Page_SetFontAndSize (page, font, 20);
    HPDF_Page_MoveTextPos (page, 220, HPDF_Page_GetHeight (page) - 70);
    HPDF_Page_ShowText (page, "RawImageDemo");
    HPDF_Page_EndText (page);

	int n;

	fp = fopen("2.png", "r");
	png_image_data = malloc(1024*1024);
	n = fread(png_image_data, 1, 1024*1024, fp);
	fclose(fp);

    /* load GrayScale raw-image (1bit) file from memory. */
    image = HPDF_LoadPngImageFromMem (pdf, png_image_data, n);

    /* Draw image to the canvas. (normal-mode with actual size.)*/
    HPDF_Page_DrawImage (page, image, 20, 20, 1024, 768);

	free(png_image_data);

    /* save the document to a file */
    HPDF_SaveToFile (pdf, fname);

    /* clean up */
    HPDF_Free (pdf);

    return 0;
}
Beispiel #26
0
int main (int /* argc */, char **argv)
{
    const char *page_title = "Font Demo";
    HPDF_Doc  pdf;
    char fname[256];
    HPDF_Page page;
    HPDF_Font def_font;
    HPDF_REAL tw;
    HPDF_REAL height;
    HPDF_REAL width;
    HPDF_UINT i;
    HPDF_Image image;
    double x;
    double y;
    double iw;
    double ih;
    HPDF_Stream stream;
    
    strcpy (fname, argv[0]);
    strcat (fname, ".pdf");

    pdf = HPDF_New (error_handler, NULL);
    if (!pdf) {
        printf ("error: cannot create PdfDoc object\n");
        return 1;
    }

    if (setjmp(env)) {
        HPDF_Free (pdf);
        return 1;
    }

    /* Add a new page object. */
    page = HPDF_AddPage (pdf);

    height = HPDF_Page_GetHeight (page);
    width = HPDF_Page_GetWidth (page);

    /* Print the lines of the page. */
    HPDF_Page_SetLineWidth (page, 1);
    HPDF_Page_Rectangle (page, 50, 50, width - 100, height - 110);
    HPDF_Page_Stroke (page);

    /* Print the title of the page (with positioning center). */
    def_font = HPDF_GetFont (pdf, "Helvetica", NULL);
    HPDF_Page_SetFontAndSize (page, def_font, 24);

    tw = HPDF_Page_TextWidth (page, page_title);
    HPDF_Page_BeginText (page);
    HPDF_Page_TextOut (page, (width - tw) / 2, height - 50, page_title);
    HPDF_Page_EndText (page);

    /* output subtitle. */
    HPDF_Page_BeginText (page);
    HPDF_Page_SetFontAndSize (page, def_font, 16);
    HPDF_Page_TextOut (page, 60, height - 80, "<Standerd Type1 fonts samples>");
    HPDF_Page_EndText (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_MoveTextPos (page, 60, height - 105);

    i = 0;
    while (font_list[i]) {
        const char* samp_text = "abcdefgABCDEFG12345!#$%&+-@?";
        HPDF_Font font = HPDF_GetFont (pdf, font_list[i], NULL);

        /* print a label of text */
        HPDF_Page_SetFontAndSize (page, def_font, 9);
        HPDF_Page_ShowText (page, font_list[i]);
        HPDF_Page_MoveTextPos (page, 0, -18);

        /* print a sample text. */
        HPDF_Page_SetFontAndSize (page, font, 20);
        HPDF_Page_ShowText (page, samp_text);
        HPDF_Page_MoveTextPos (page, 0, -20);

        i++;
    }

    HPDF_Page_EndText (page);

    /* Add a new page object. */
    page = HPDF_AddPage (pdf);

    height = HPDF_Page_GetHeight (page);
    width = HPDF_Page_GetWidth (page);
    
    /* load image file. */
    image = HPDF_LoadPngImageFromFile (pdf, "test.png");

    x = 100;
    y = 100;
    iw = HPDF_Image_GetWidth (image);
    ih = HPDF_Image_GetHeight (image);
    
    /* Draw image to the canvas. (normal-mode with actual size.)*/
    HPDF_Page_DrawImage (page, image, x, y, iw, ih);
    
    HPDF_SaveToFile (pdf, fname);
    
    /* write something via zlib */
    stream = HPDF_FileWriter_New( pdf->mmgr, "test2.raw" );    
    HPDF_Stream_WriteToStream( image->stream, stream, HPDF_STREAM_FILTER_FLATE_DECODE, NULL );
    HPDF_Stream_Free (stream);
    
    /* clean up */
    HPDF_Free (pdf);

    return 0;
}
Beispiel #27
0
		int fileWriter(HPDF_Doc  pdf,
			HPDF_Outline root,
			HPDF_Font font,
			const std::string curFile,
			const std::vector< std::string> vec) {

			auto func_footbar = [](std::string fileName)->std::string {
				std::ostringstream buffer;
				buffer << "  File:" << fileName.c_str() << "   Autor:XCL ";
				return buffer.str();
			};

			auto func_pageOutline = [&](HPDF_Page page, std::string curFile) {
				HPDF_Outline outline;
				HPDF_Destination dst;
				outline = HPDF_CreateOutline(pdf, root, curFile.c_str(), NULL);
				dst = HPDF_Page_CreateDestination(page);
				HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page), 1);// 1 = 默认百分比100
				HPDF_Outline_SetDestination(outline, dst);
			};
			
			auto func_drawRow = [](HPDF_Page page,std::string rid,std::string row,int y ) {
				HPDF_Page_BeginText(page);
				HPDF_Page_MoveTextPos(page, config::ROWID_WIDTH, y - 2);
				HPDF_Page_ShowText(page, rid.c_str());
				HPDF_Page_ShowText(page, row.c_str());
				HPDF_Page_EndText(page);
			};

			HPDF_Page page = nullptr;			
			HPDF_REAL width,height;		
			HPDF_UINT y = 0;		//  x =0,
			int currID = 0, pageID = 0, currRowCount;
			std::string ss, rid;
	
			for (int i = 0; i < vec.size(); i++) {							
				if (i == 0 || currRowCount >  config::PAGE_ROWNUM) {
					//////////////////////////////////////////////
					page = HPDF_AddPage(pdf);

					width = HPDF_Page_GetWidth(page);
					height = HPDF_Page_GetHeight(page);
//					x = 0;
					y = height - config::ROW_HEIGHT;

					func_pageOutline(page, curFile);
					HPDF_Page_SetSize(page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT);															

					{
						HPDF_RGBColor c = HPDF_Page_GetRGBFill(page);
						HPDF_Page_SetRGBStroke(page, 0.0, 0.5, 0);
						HPDF_Page_SetFontAndSize(page, font, config::FOOTBAR_FONT_SIZE);
						HPDF_Page_SetLineWidth(page, 0.5);
						HPDF_Page_MoveTo(page, 0, 13);
						HPDF_Page_LineTo(page, width, 16);
						HPDF_Page_Stroke(page);

						HPDF_Page_SetRGBFill(page, 0.0, 0, 0.5);
						HPDF_Page_BeginText(page);
						HPDF_Page_MoveTextPos(page, 40, config::FOOTBAR_FONT_SIZE - 5);
						HPDF_Page_ShowText(page, func_footbar(curFile).c_str());
						HPDF_Page_EndText(page);
						HPDF_Page_SetRGBFill(page, c.r, c.g, c.b);
					};
					
					y = height - config::ROW_HEIGHT * 2;
					HPDF_Page_SetFontAndSize(page, font, config::PAGE_FONT_SIZE);
					pageID++;
					currRowCount = 1;
					//////////////////////////////////////////////
				}
												
				///////////////////////////////////////////			
				 ss = vec[i];
				 HPDF_REAL wrid = HPDF_Page_TextWidth(page, rid.c_str());
			 NEWROW:			
				 HPDF_REAL wss = HPDF_Page_TextWidth(page, ss.c_str());			
				 rid = util::rowidWidth(currRowCount );
				 if (wrid + wss >  width) {
					 //简单处理:超过页宽,直接分成两行.足以应付大部份情况.
					 int center = ss.length() / 2;		 
					 func_drawRow(page, rid,ss.substr(0, center),y);
					 y -= config::ROW_HEIGHT;
					 currRowCount++;
					 ss = ss.substr(center);
					 goto NEWROW;
				 }
				 else {			
					func_drawRow(page, rid, ss,y);				
					y -= config::ROW_HEIGHT;		
					currRowCount++;
				 }
				//////////////////////////////////////////
			}
			return 0;
		} //end func
Beispiel #28
0
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;
    HPDF_Annotation annot;

    strcpy (fname, argv[0]);
    strcat (fname, ".pdf");

    pdf = HPDF_New (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_BeginText (page);
    HPDF_Page_SetFontAndSize (page, font, 16);
    HPDF_Page_MoveTextPos (page, 130, 450);
    HPDF_Page_ShowText (page, "Annotation Demo");
    HPDF_Page_EndText (page);


    annot = HPDF_Page_CreateTextAnnot (page, rect1, "Annotation with Comment "
                "Icon. \n This annotation set to be opened initially.",
                NULL);

    HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_COMMENT);
    HPDF_TextAnnot_SetOpened (annot, HPDF_TRUE);

    annot = HPDF_Page_CreateTextAnnot (page, rect2,
                "Annotation with Key Icon", NULL);
    HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_PARAGRAPH);

    annot = HPDF_Page_CreateTextAnnot (page, rect3,
                "Annotation with Note Icon", NULL);
    HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_NOTE);

    annot = HPDF_Page_CreateTextAnnot (page, rect4,
                "Annotation with Help Icon", NULL);
    HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_HELP);

    annot = HPDF_Page_CreateTextAnnot (page, rect5,
                "Annotation with NewParagraph Icon", NULL);
    HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_NEW_PARAGRAPH);

    annot = HPDF_Page_CreateTextAnnot (page, rect6,
                "Annotation with Paragraph Icon", NULL);
    HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_PARAGRAPH);

    annot = HPDF_Page_CreateTextAnnot (page, rect7,
                "Annotation with Insert Icon", NULL);
    HPDF_TextAnnot_SetIcon (annot, HPDF_ANNOT_ICON_INSERT);

    encoding = HPDF_GetEncoder (pdf, "ISO8859-2");

    HPDF_Page_CreateTextAnnot (page, rect8,
                "Annotation with ISO8859 text гдежзий", encoding);

    HPDF_Page_SetFontAndSize (page, font, 11);

    HPDF_Page_BeginText (page);
    HPDF_Page_MoveTextPos (page, rect1.left + 35, rect1.top - 20);
    HPDF_Page_ShowText (page, "Comment Icon.");
    HPDF_Page_EndText (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_MoveTextPos (page, rect2.left + 35, rect2.top - 20);
    HPDF_Page_ShowText (page, "Key Icon");
    HPDF_Page_EndText (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_MoveTextPos (page, rect3.left + 35, rect3.top - 20);
    HPDF_Page_ShowText (page, "Note Icon.");
    HPDF_Page_EndText (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_MoveTextPos (page, rect4.left + 35, rect4.top - 20);
    HPDF_Page_ShowText (page, "Help Icon");
    HPDF_Page_EndText (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_MoveTextPos (page, rect5.left + 35, rect5.top - 20);
    HPDF_Page_ShowText (page, "NewParagraph Icon");
    HPDF_Page_EndText (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_MoveTextPos (page, rect6.left + 35, rect6.top - 20);
    HPDF_Page_ShowText (page, "Paragraph Icon");
    HPDF_Page_EndText (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_MoveTextPos (page, rect7.left + 35, rect7.top - 20);
    HPDF_Page_ShowText (page, "Insert Icon");
    HPDF_Page_EndText (page);

    HPDF_Page_BeginText (page);
    HPDF_Page_MoveTextPos (page, rect8.left + 35, rect8.top - 20);
    HPDF_Page_ShowText (page, "Text Icon(ISO8859-2 text)");
    HPDF_Page_EndText (page);


    /* save the document to a file */
    HPDF_SaveToFile (pdf, fname);

    /* clean up */
    HPDF_Free (pdf);

    return 0;
}
Beispiel #29
0
int main (int argc, char **argv)
{
    HPDF_Doc  pdf;
    HPDF_Font font;
    HPDF_Page page;
    char fname[256];
    HPDF_Image image;

    HPDF_REAL x, y;

    strcpy (fname, argv[0]);
    strcat (fname, ".pdf");

    pdf = HPDF_New (error_handler, NULL);
    if (!pdf) {
        printf ("error: cannot create PdfDoc object\n");
        return 1;
    }

    /* error-handler */
    if (setjmp(env)) {
        HPDF_Free (pdf);
        return 1;
    }

    HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);

    /* create default-font */
    font = HPDF_GetFont (pdf, "Helvetica", NULL);

    /* add a new page object. */
    page = HPDF_AddPage (pdf);

    HPDF_Page_SetWidth (page, 172);
    HPDF_Page_SetHeight (page, 80);

    HPDF_Page_BeginText (page);
    HPDF_Page_SetFontAndSize (page, font, 20);
    HPDF_Page_MoveTextPos (page, 220, HPDF_Page_GetHeight (page) - 70);
    HPDF_Page_ShowText (page, "RawImageDemo");
    HPDF_Page_EndText (page);

    /* load RGB raw-image file. */
    #ifndef __WIN32__
    image = HPDF_LoadRawImageFromFile (pdf, "rawimage/32_32_rgb.dat",
            32, 32, HPDF_CS_DEVICE_RGB);
    #else
    image = HPDF_LoadRawImageFromFile (pdf, "rawimage\\32_32_rgb.dat",
            32, 32, HPDF_CS_DEVICE_RGB);
    #endif

    x = 20;
    y = 20;

    /* Draw image to the canvas. (normal-mode with actual size.)*/
    HPDF_Page_DrawImage (page, image, x, y, 32, 32);

    /* load GrayScale raw-image file. */
    #ifndef __WIN32__
    image = HPDF_LoadRawImageFromFile (pdf, "rawimage/32_32_gray.dat",
            32, 32, HPDF_CS_DEVICE_GRAY);
    #else
    image = HPDF_LoadRawImageFromFile (pdf, "rawimage\\32_32_gray.dat",
            32, 32, HPDF_CS_DEVICE_GRAY);
    #endif

    x = 70;
    y = 20;

    /* Draw image to the canvas. (normal-mode with actual size.)*/
    HPDF_Page_DrawImage (page, image, x, y, 32, 32);

    /* load GrayScale raw-image (1bit) file from memory. */
    image = HPDF_LoadRawImageFromMem (pdf, RAW_IMAGE_DATA, 32, 32,
                HPDF_CS_DEVICE_GRAY, 1);

    x = 120;
    y = 20;

    /* Draw image to the canvas. (normal-mode with actual size.)*/
    HPDF_Page_DrawImage (page, image, x, y, 32, 32);

    /* save the document to a file */
    HPDF_SaveToFile (pdf, fname);

    /* clean up */
    HPDF_Free (pdf);

    return 0;
}
Beispiel #30
0
void
generate_pdf (const char *outname, const char *tmpdirname, int num_fonts,
	      int num_input_files, const JBDATA * data,
	      const struct mapping *maps, int debug_draw_borders)
{
  int i, j;
  /* Create the pdf document */
  l_int32 ncomp = numaGetCount (data->naclass);
  HPDF_Doc pdf = HPDF_New (pdf_error_handler, NULL);

  HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);
  HPDF_Font *fonts = malloc_guarded (num_fonts * (sizeof (HPDF_Font)));

  int dirlen = strlen (tmpdirname);

  /* Load the fonts */
  for (i = 0; i < num_fonts; i++)
    {
      /* 1 for '/', 8 for %08d, 4 for '.ttf' */
      int fontlen = dirlen + 1 + 8 + 4;
      char *font_tfname = malloc_guarded (fontlen + 1);
      sprintf (font_tfname, "%s/%08d.ttf", tmpdirname, i);

      const char *font_name =
	HPDF_LoadTTFontFromFile (pdf, font_tfname, HPDF_TRUE);
      fonts[i] = HPDF_GetFont (pdf, font_name, "KOI8-R");
      free (font_tfname);
    }

  for (j = 0; j < num_input_files; j++)
    {
      /* Add page to document */
      HPDF_Page pg = HPDF_AddPage (pdf);

      HPDF_Page_SetWidth (pg, data->w);
      HPDF_Page_SetHeight (pg, data->h);

      /* TODO: Boost efficiency by making startcomp go to the next page on the next iteration */
      int start_comp = 0;

      for (i = start_comp; i < ncomp; i++)
	{
	  l_int32 ipage;
	  l_int32 iclass;
	  l_int32 x;
	  l_int32 y;

	  numaGetIValue (data->napage, i, &ipage);

	  if (ipage != j)
	    continue;

	  numaGetIValue (data->naclass, i, &iclass);
	  ptaGetIPt (data->ptaul, i, &x, &y);

	  /*double left = x;
	     double top = data->h - y;
	     double right = x + data->latticew;
	     double bottom = data->h - (y + data->latticeh); */

	  char text[2];
	  text[0] = maps[iclass].code_point;
	  text[1] = '\0';

	  HPDF_Font font = fonts[maps[iclass].font_num];

	  HPDF_Page_BeginText (pg);
	  double fontsize = 100;

	  if (fontsize > 300)
	    {
	      error_quit ("This is a known bug.\n"
			  "libharu can't handle fontsizes bigger than 300, which is what is being requested here.\n"
			  "Please report this bug, and the file that produced this error");
	    }

	  HPDF_Page_SetFontAndSize (pg, font, 100);

	  HPDF_Page_MoveTextPos (pg, x, (data->h - y) - data->latticeh);
	  HPDF_Page_ShowText (pg, text);

	  HPDF_Page_EndText (pg);

	  if (debug_draw_borders)
	    {
	      HPDF_Page_SetRGBStroke (pg, 1, 0, 0);
	      /* In this, x, y is the LOWER LEFT, not UPPER LEFT */
	      HPDF_Page_Rectangle (pg, x, (data->h - y) - data->latticeh,
				   data->latticew, data->latticeh);
	      HPDF_Page_Stroke (pg);
	    }
	}
    }

  /* Output */
  HPDF_SaveToFile (pdf, outname);

  /* Cleanup */
  HPDF_Free (pdf);
  free (fonts);
}