Exemple #1
0
static bool haru_nsfont_init(HPDF_Doc *pdf, HPDF_Page *page,
		const char *string, char **string_nt, int length)
{

	*pdf = HPDF_New(error_handler, NULL);

	if (*pdf == NULL)
		return false;

	*page = HPDF_AddPage(*pdf);

	if (*page == NULL) {
		HPDF_Free(*pdf);
		return false;
	}

	*string_nt = malloc((length + 1) * sizeof(char));
	if (*string_nt == NULL) {
		HPDF_Free(*pdf);
		return false;
	}

	memcpy(*string_nt, string, length);
	(*string_nt)[length] = '\0';
	return true;
}
Exemple #2
0
/**
 * Measure the width of a string.
 *
 * \param  fstyle  style for this text
 * \param  string  string to measure (no UTF-8 currently)
 * \param  length  length of string
 * \param  width   updated to width of string[0..length]
 * \return  true on success, false on error and error reported
 */
bool haru_nsfont_width(const plot_font_style_t *fstyle,
		const char *string, size_t length,
	 	int *width)
{
	HPDF_Doc pdf;
	HPDF_Page page;
	char *string_nt;
	HPDF_REAL width_real;

	*width = 0;

	if (length == 0)
		return true;

	if (!haru_nsfont_init(&pdf, &page, string, &string_nt, length))
		return false;

	if (!haru_nsfont_apply_style(fstyle, pdf, page, NULL, NULL)) {
		free(string_nt);
		HPDF_Free(pdf);
		return false;
	}

	width_real = HPDF_Page_TextWidth(page, string_nt);
	*width = width_real;

#ifdef FONT_HARU_DEBUG
	LOG("Measuring string: %s ; Calculated width: %f %i", string_nt, width_real, *width);
#endif
	free(string_nt);
	HPDF_Free(pdf);

	return true;
}
Exemple #3
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;
}
Exemple #4
0
int main (int argc, char **argv)
{
    HPDF_Doc  pdf;
    HPDF_Image image;
    HPDF_Stream stream;

    HPDF_UINT iw;
    HPDF_UINT ih;
    HPDF_UINT bits_per_comp;
    const char *cs;

    if (argc < 2) {
        printf ("usage: make_rawimage <in-file-name> <out-file-name>\n");
        return 1;
    }

    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;
    }

    /* load image file. */
    image = HPDF_LoadPngImageFromFile (pdf, argv[1]);

    iw = HPDF_Image_GetWidth (image);
    ih = HPDF_Image_GetHeight (image);
    bits_per_comp = HPDF_Image_GetBitsPerComponent (image);
    cs = HPDF_Image_GetColorSpace (image);

    printf ("width=%u\n", iw);
    printf ("height=%u\n", ih);
    printf ("bits_per_comp=%u\n", bits_per_comp);
    printf ("color_space=%s\n", cs);

    /* save raw-data to file */
    stream = HPDF_FileWriter_New (pdf->mmgr, argv[2]);
    if (!stream)
        printf ("cannot open %s\n", argv[2]);
    else
        HPDF_Stream_WriteToStream(image->stream, stream, 0, NULL);

    HPDF_Stream_Free (stream);

    /* clean up */
    HPDF_Free (pdf);

    return 0;
}
Exemple #5
0
/**
 * Begin pdf plotting - initialize a new document
 * \param path Output file path
 * \param pg_width page width
 * \param pg_height page height
 */
bool pdf_begin(struct print_settings *print_settings)
{
	pdfw_gs_init();

	if (pdf_doc != NULL)
		HPDF_Free(pdf_doc);
	pdf_doc = HPDF_New(error_handler, NULL);
	if (!pdf_doc) {
		NSLOG(netsurf, INFO, "Error creating pdf_doc");
		return false;
	}

	settings = print_settings;

	page_width = settings->page_width -
			FIXTOFLT(FSUB(settings->margins[MARGINLEFT],
			settings->margins[MARGINRIGHT]));

	page_height = settings->page_height -
			FIXTOFLT(settings->margins[MARGINTOP]);


#ifndef PDF_DEBUG
	if (option_enable_PDF_compression)
		HPDF_SetCompressionMode(pdf_doc, HPDF_COMP_ALL); /*Compression on*/
#endif
	HPDF_SetInfoAttr(pdf_doc, HPDF_INFO_CREATOR, user_agent_string());

	pdf_page = NULL;

#ifdef PDF_DEBUG
	NSLOG(netsurf, INFO, "pdf_begin finishes");
#endif
	return true;
}
// Stroke the generated PDF to a fil
static void
stroke_page_tofile(void) {
    if( HPDF_OK != HPDF_SaveToFile (pdf_doc, OUTPUT_FILE) ) {
        fprintf(stderr,"ERROR: Cannot save to file!");
    }
    HPDF_Free (pdf_doc);
}
/*
 * Class:     org_libharu_PdfDocument
 * Method:    free
 * Signature: ()V
 */
JNIEXPORT void JNICALL
Java_org_libharu_PdfDocument_free(JNIEnv *env, jobject obj) {
    jint pdf;
    /* Get mHPDFDocPointer */
    pdf = (*env)->GetIntField(env, obj, mHPDFDocPointer);
    /* Free the document */
    HPDF_Free((HPDF_Doc) pdf);
}
Exemple #8
0
	bool run(std::vector<std::string> const& jpgfiles, char const* outname) {
	    HPDF_Doc  	pdf = HPDF_New (&Jpg2Pdf::errorHandlerForHaru, NULL);
	    if (!pdf) {
	        printf ("error: cannot create PdfDoc object\n");
	        return false;
	    }
	    if (setjmp(s_jmp_buf_env)) {
	        HPDF_Free (pdf);
	        return false;
	    }
	    HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);
		for (size_t i = 0; i < jpgfiles.size(); ++i)
			addJpgPage(pdf, jpgfiles[i].c_str());
	    HPDF_SaveToFile (pdf, outname);
	    HPDF_Free (pdf);
	    return 0;
	}
JNIEXPORT void JNICALL Java_org_libharu_Document_destruct
  (JNIEnv *env, jobject obj)
{
  haru_setup_error_handler(env, __func__);
  HPDF_Doc pdf = get_HPDF_Doc(env, obj);
  HPDF_Free(pdf);
  haru_clear_error_handler();
}
extern void AP_savePdfAndCleanUp(char *path,HPDF_Doc pdf)
{
    HPDF_SaveToFile(pdf, path);
    printf("[libharu] Freeing PDF object ");
    if (HPDF_HasDoc(pdf)) {
        HPDF_Free(pdf);
    }
    printf("[libharu] PDF Creation END");
}
Exemple #11
0
WPdfImage::~WPdfImage()
{
  beingDeleted();

  if (myPdf_)
    HPDF_Free(pdf_);

  delete trueTypeFonts_;
}
Exemple #12
0
bool haru_nsfont_position_in_string(const plot_font_style_t *fstyle,
		const char *string, size_t length,
		int x, size_t *char_offset, int *actual_x)
{
	HPDF_Doc pdf;
	HPDF_Page page;
	char *string_nt;
	HPDF_UINT offset;
	HPDF_REAL real_width;

	if (!haru_nsfont_init(&pdf, &page, string, &string_nt, length))
		return false;

	if (HPDF_Page_SetWidth(page, x) != HPDF_OK
			|| !haru_nsfont_apply_style(fstyle, pdf, page, NULL, NULL)) {
		free(string_nt);
		HPDF_Free(pdf);
		return false;
	}


	offset = HPDF_Page_MeasureText(page, string_nt, x,
			HPDF_FALSE, &real_width);


	if (real_width < x)
		*char_offset = offset;
	else {
		assert(fabs(real_width - x) < FLT_EPSILON);
		assert(offset > 0);
		*char_offset = offset - 1;
	}

	/*TODO: this is only the right edge of the character*/
	*actual_x = real_width;

#ifdef FONT_HARU_DEBUG
	LOG("Position in string: %s at x: %i; Calculated position: %i", string_nt, x, *char_offset);
#endif
	free(string_nt);
	HPDF_Free(pdf);

	return true;
}
Exemple #13
0
void CHaruPdf::Destroy()
{_STT();

	if ( m_pdf )
		HPDF_Free( m_pdf );
		
	m_sLastError = oexT( "" );
	m_pdf = oexNULL;
	m_page = oexNULL;
	m_font = oexNULL;
}
Exemple #14
0
HPDF_NewEx  (HPDF_Error_Handler    user_error_fn,
             HPDF_Alloc_Func       user_alloc_fn,
             HPDF_Free_Func        user_free_fn,
             HPDF_UINT             mem_pool_buf_size,
             void                 *user_data)
{
    HPDF_Doc pdf;
    HPDF_MMgr mmgr;
    HPDF_Error_Rec tmp_error;

    HPDF_PTRACE ((" HPDF_NewEx\n"));

    /* initialize temporary-error object */
    HPDF_Error_Init (&tmp_error, user_data);

    /* create memory-manager object */
    mmgr = HPDF_MMgr_New (&tmp_error, mem_pool_buf_size, user_alloc_fn,
            user_free_fn);
    if (!mmgr) {
        HPDF_CheckError (&tmp_error);
        return NULL;
    }

    /* now create pdf_doc object */
    pdf = HPDF_GetMem (mmgr, sizeof (HPDF_Doc_Rec));
    if (!pdf) {
        HPDF_MMgr_Free (mmgr);
        HPDF_CheckError (&tmp_error);
        return NULL;
    }

    HPDF_MemSet (pdf, 0, sizeof (HPDF_Doc_Rec));
    pdf->sig_bytes = HPDF_SIG_BYTES;
    pdf->mmgr = mmgr;
    pdf->pdf_version = HPDF_VER_13;
    pdf->compression_mode = HPDF_COMP_NONE;

    /* copy the data of temporary-error object to the one which is
       included in pdf_doc object */
    pdf->error = tmp_error;

    /* switch the error-object of memory-manager */
    mmgr->error = &pdf->error;

    if (HPDF_NewDoc (pdf) != HPDF_OK) {
        HPDF_Free (pdf);
        HPDF_CheckError (&tmp_error);
        return NULL;
    }

    pdf->error.error_fn = user_error_fn;

    return pdf;
}
Exemple #15
0
bool haru_nsfont_split(const plot_font_style_t *fstyle,
		const char *string, size_t length,
		int x, size_t *char_offset, int *actual_x)
{
	HPDF_Doc pdf;
	HPDF_Page page;
	char *string_nt;
	HPDF_REAL real_width;
	HPDF_UINT offset;


	if (!haru_nsfont_init(&pdf, &page, string, &string_nt, length))
		return false;

	if (HPDF_Page_SetWidth(page, x) != HPDF_OK
		    || !haru_nsfont_apply_style(fstyle, pdf, page, NULL, NULL)) {
		free(string_nt);
		HPDF_Free(pdf);
		return false;
	}

	offset = HPDF_Page_MeasureText(page, string_nt, x,
			HPDF_TRUE, &real_width);

#ifdef FONT_HARU_DEBUG
	LOG("Splitting string: %s for width: %i ; Calculated position: %i Calculated real_width: %f", string_nt, x, *char_offset, real_width);
#endif
	*char_offset = offset - 1;

	/*TODO: this is only the right edge of the character*/
	*actual_x = real_width;

	free(string_nt);
	HPDF_Free(pdf);

	return true;
}
Exemple #16
0
WPdfImage::~WPdfImage()
{
  beingDeleted();

  if (myPdf_) {
    // clear graphics state stack to avoid leaking memory in libharu
    // see bug #3979
    HPDF_Page page = HPDF_GetCurrentPage(pdf_);
    if (page)
      while (HPDF_Page_GetGStateDepth(page) > 1)
        HPDF_Page_GRestore(page);
    HPDF_Free(pdf_);
  }

  delete trueTypeFonts_;
}
Exemple #17
0
  virtual void handleRequest(const Wt::Http::Request& request,
                             Wt::Http::Response& response)
  {
    response.setMimeType("application/pdf");

    HPDF_Doc pdf = HPDF_New(error_handler, 0);
    HPDF_UseUTFEncodings(pdf);

    renderReport(pdf);

    HPDF_SaveToStream(pdf);
    unsigned int size = HPDF_GetStreamSize(pdf);
    HPDF_BYTE *buf = new HPDF_BYTE[size];
    HPDF_ReadFromStream (pdf, buf, &size);
    HPDF_Free(pdf);
    response.out().write((char*)buf, size);
    delete[] buf;
  }
Exemple #18
0
/** saves the pdf with optional encryption */
nserror save_pdf(const char *path)
{
	nserror res = NSERROR_OK;

	if (option_enable_PDF_password && owner_pass != NULL ) {
		HPDF_SetPassword(pdf_doc, owner_pass, user_pass);
		HPDF_SetEncryptionMode(pdf_doc, HPDF_ENCRYPT_R3, 16);
		free(owner_pass);
		free(user_pass);
	}

	if (path != NULL) {
		if (HPDF_SaveToFile(pdf_doc, path) != HPDF_OK) {
			remove(path);
			res = NSERROR_SAVE_FAILED;
		}
	}

	HPDF_Free(pdf_doc);
	pdf_doc = NULL;

	return res;
}
Exemple #19
0
/** saves the pdf optionally encrypting it before*/
void save_pdf(const char *path)
{
	bool success = false;

	if (option_enable_PDF_password && owner_pass != NULL ) {
		HPDF_SetPassword(pdf_doc, owner_pass, user_pass);
		HPDF_SetEncryptionMode(pdf_doc, HPDF_ENCRYPT_R3, 16);
		free(owner_pass);
		free(user_pass);
	}

	if (path != NULL) {
		if (HPDF_SaveToFile(pdf_doc, path) != HPDF_OK)
			remove(path);
		else
			success = true;
	}

	if (!success)
		warn_user("Unable to save PDF file.", 0);

	HPDF_Free(pdf_doc);
	pdf_doc = NULL;
}
int
main(int argc, char** argv) {

    t_func_tbl_stroke examples[] = {ex_tbl1, ex_tbl2, ex_tbl3, ex_tbl4, ex_tbl5};
    const size_t num_examples = sizeof(examples)/sizeof(t_func_tbl_stroke);

    printf("Stroking %ld examples.\n",num_examples);

    // Setup fake exception handling
    if (setjmp(env)) {
        HPDF_Free (pdf_doc);
        return EXIT_FAILURE;
    }

    // Get some dummy data to fill the table§
    setup_dummy_data();

    // Setup the basic PDF document
    pdf_doc = HPDF_New(error_handler, NULL);
    HPDF_SetCompressionMode(pdf_doc, HPDF_COMP_ALL);


    for( size_t i=0; i < num_examples; i++ ) {
      add_a4page();
#if !(defined _WIN32 || defined __WIN32__)
      example_page_header();
#endif
      (*examples[i])();
    }

    printf("Sending to file \"%s\" ...\n",OUTPUT_FILE);
    stroke_page_tofile();
    printf("Done.\n");

    return (EXIT_SUCCESS);
}
Exemple #21
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;
}
Exemple #22
0
int
main (int argc, char **argv)
{
    HPDF_Doc  pdf;
    HPDF_Page page;
    char fname[256];
    HPDF_Font hfont;
    HPDF_ExtGState gstate;
    const HPDF_REAL PAGE_WIDTH = 600;
    const HPDF_REAL PAGE_HEIGHT = 900;

    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;
    }

    hfont = HPDF_GetFont (pdf, "Helvetica-Bold", NULL);

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

    HPDF_Page_SetFontAndSize (page, hfont, 10);

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

    /* normal */
    HPDF_Page_GSave (page);
    draw_circles (page, "normal", 40.0f, PAGE_HEIGHT - 170);
    HPDF_Page_GRestore (page);

    /* transparency (0.8) */
    HPDF_Page_GSave (page);
    gstate = HPDF_CreateExtGState (pdf);
    HPDF_ExtGState_SetAlphaFill (gstate, 0.8);
    HPDF_ExtGState_SetAlphaStroke (gstate, 0.8);
    HPDF_Page_SetExtGState (page, gstate);
    draw_circles (page, "alpha fill = 0.8", 230.0f, PAGE_HEIGHT - 170);
    HPDF_Page_GRestore (page);

    /* transparency (0.4) */
    HPDF_Page_GSave (page);
    gstate = HPDF_CreateExtGState (pdf);
    HPDF_ExtGState_SetAlphaFill (gstate, 0.4);
    HPDF_Page_SetExtGState (page, gstate);
    draw_circles (page, "alpha fill = 0.4", 420.0f, PAGE_HEIGHT - 170);
    HPDF_Page_GRestore (page);

    /* blend-mode=HPDF_BM_MULTIPLY */
    HPDF_Page_GSave (page);
    gstate = HPDF_CreateExtGState (pdf);
    HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_MULTIPLY);
    HPDF_Page_SetExtGState (page, gstate);
    draw_circles (page, "HPDF_BM_MULTIPLY", 40.0f, PAGE_HEIGHT - 340);
    HPDF_Page_GRestore (page);

    /* blend-mode=HPDF_BM_SCREEN */
    HPDF_Page_GSave (page);
    gstate = HPDF_CreateExtGState (pdf);
    HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_SCREEN);
    HPDF_Page_SetExtGState (page, gstate);
    draw_circles (page, "HPDF_BM_SCREEN", 230.0f, PAGE_HEIGHT - 340);
    HPDF_Page_GRestore (page);

    /* blend-mode=HPDF_BM_OVERLAY */
    HPDF_Page_GSave (page);
    gstate = HPDF_CreateExtGState (pdf);
    HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_OVERLAY);
    HPDF_Page_SetExtGState (page, gstate);
    draw_circles (page, "HPDF_BM_OVERLAY", 420.0f, PAGE_HEIGHT - 340);
    HPDF_Page_GRestore (page);

    /* blend-mode=HPDF_BM_DARKEN */
    HPDF_Page_GSave (page);
    gstate = HPDF_CreateExtGState (pdf);
    HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_DARKEN);
    HPDF_Page_SetExtGState (page, gstate);
    draw_circles (page, "HPDF_BM_DARKEN", 40.0f, PAGE_HEIGHT - 510);
    HPDF_Page_GRestore (page);

    /* blend-mode=HPDF_BM_LIGHTEN */
    HPDF_Page_GSave (page);
    gstate = HPDF_CreateExtGState (pdf);
    HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_LIGHTEN);
    HPDF_Page_SetExtGState (page, gstate);
    draw_circles (page, "HPDF_BM_LIGHTEN", 230.0f, PAGE_HEIGHT - 510);
    HPDF_Page_GRestore (page);

    /* blend-mode=HPDF_BM_COLOR_DODGE */
    HPDF_Page_GSave (page);
    gstate = HPDF_CreateExtGState (pdf);
    HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_COLOR_DODGE);
    HPDF_Page_SetExtGState (page, gstate);
    draw_circles (page, "HPDF_BM_COLOR_DODGE", 420.0f, PAGE_HEIGHT - 510);
    HPDF_Page_GRestore (page);


    /* blend-mode=HPDF_BM_COLOR_BUM */
    HPDF_Page_GSave (page);
    gstate = HPDF_CreateExtGState (pdf);
    HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_COLOR_BUM);
    HPDF_Page_SetExtGState (page, gstate);
    draw_circles (page, "HPDF_BM_COLOR_BUM", 40.0f, PAGE_HEIGHT - 680);
    HPDF_Page_GRestore (page);

    /* blend-mode=HPDF_BM_HARD_LIGHT */
    HPDF_Page_GSave (page);
    gstate = HPDF_CreateExtGState (pdf);
    HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_HARD_LIGHT);
    HPDF_Page_SetExtGState (page, gstate);
    draw_circles (page, "HPDF_BM_HARD_LIGHT", 230.0f, PAGE_HEIGHT - 680);
    HPDF_Page_GRestore (page);

    /* blend-mode=HPDF_BM_SOFT_LIGHT */
    HPDF_Page_GSave (page);
    gstate = HPDF_CreateExtGState (pdf);
    HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_SOFT_LIGHT);
    HPDF_Page_SetExtGState (page, gstate);
    draw_circles (page, "HPDF_BM_SOFT_LIGHT", 420.0f, PAGE_HEIGHT - 680);
    HPDF_Page_GRestore (page);

    /* blend-mode=HPDF_BM_DIFFERENCE */
    HPDF_Page_GSave (page);
    gstate = HPDF_CreateExtGState (pdf);
    HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_DIFFERENCE);
    HPDF_Page_SetExtGState (page, gstate);
    draw_circles (page, "HPDF_BM_DIFFERENCE", 40.0f, PAGE_HEIGHT - 850);
    HPDF_Page_GRestore (page);


    /* blend-mode=HPDF_BM_EXCLUSHON */
    HPDF_Page_GSave (page);
    gstate = HPDF_CreateExtGState (pdf);
    HPDF_ExtGState_SetBlendMode (gstate, HPDF_BM_EXCLUSHON);
    HPDF_Page_SetExtGState (page, gstate);
    draw_circles (page, "HPDF_BM_EXCLUSHON", 230.0f, PAGE_HEIGHT - 850);
    HPDF_Page_GRestore (page);


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

    /* clean up */
    HPDF_Free (pdf);

    return 0;
}
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;
}
Exemple #24
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;
}
Exemple #25
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;
}
Exemple #26
0
bool Pdf3d::createAdvancedPdf( const char *filepdf, const char *fileprc, const char *filejs, bool bUseCenter, float cenx, float ceny, float cenz )
{
    HPDF_Rect rect = {_rcleft, _rctop, _rcwidth, _rcheight};
  
    HPDF_Doc  pdf;
    HPDF_Page page;
    HPDF_Annotation annot;
    HPDF_U3D u3d;
  
    pdf = HPDF_New (NULL, NULL);
    if (!pdf) 
    {
        printf ("error: cannot create PdfDoc object\n");
        return false;
    }

    // set up some error handling
    if (setjmp(g_env)) 
    {
        HPDF_Free (pdf);
        return false;
    }

    page = HPDF_AddPage (pdf);
  
    HPDF_Page_SetWidth (page, _rcwidth);
    HPDF_Page_SetHeight (page, _rcheight);

    //HPDF_Dict js = NULL;  SALVA
    //js = HPDF_DictStream_New (pdf->mmgr, pdf->xref);
    //js->header.obj_class |= HPDF_OSUBCLASS_XOBJECT;
    //js->filter = HPDF_STREAM_FILTER_NONE;
    //js = HPDF_LoadJSFromFile  (pdf, filejs);
    u3d = HPDF_LoadU3DFromFile (pdf, fileprc);

    // add javeascript  action
    //HPDF_Dict_Add (u3d, "OnInstantiate", js);  SALVA

#define NS2VIEWS 7
    HPDF_Dict views[NS2VIEWS+1];
    const char *view_names[] = {"Front perspective ('1','H')",
                  "Back perspective ('2')",
                  "Right perspective ('3')",
                  "Left perspective ('4')",
                  "Bottom perspective ('5')", 
                  "Top perspective ('6')",
                  "Oblique perspective ('7')"};
    const float view_c2c[][3] = {{0., 0., 1.},
                   {0., 0., -1.},
                   {-1., 0., 0.},
                   {1., 0., 0.},
                   {0., 1., 0.},
                   {0., -1., 0.},
                   {-1., 1., -1.}};
    const float view_roll[] = {0., 180., 90., -90., 0., 0., 60.};
  
    // query camera point to rotate about - sometimes not the same as focus point
    XYZ pr;
    pr.x = 0; 
    pr.y = 0; 
    pr.z = 0;

    // camera focus point
    //XYZ focus;
    //focus.x = 0;
    //focus.y = 0;
    //focus.z = 0;

    if (bUseCenter)
    {
        pr.x = cenx;
        pr.y = ceny;
        pr.z = cenz;
    }

    float camrot = 5.0;

    // create views
    for (int iv = 0; iv < NS2VIEWS; iv++) 
    {
        views[iv] = HPDF_Create3DView(u3d->mmgr, view_names[iv]);
        HPDF_3DView_SetCamera(views[iv], pr.x, pr.y, pr.z, 
              view_c2c[iv][0], view_c2c[iv][1], view_c2c[iv][2],
              camrot, view_roll[iv]);
        HPDF_3DView_SetPerspectiveProjection(views[iv], 45.0);
        HPDF_3DView_SetBackgroundColor(views[iv], _bgr, _bgg, _bgb);
        HPDF_3DView_SetLighting(views[iv], "White");

        HPDF_U3D_Add3DView(u3d, views[iv]);
    }

    // add a psuedo-orthographic for slicing (actually perspective with point at infinity)
    views[NS2VIEWS] = HPDF_Create3DView(u3d->mmgr, "Orthgraphic slicing view");
    HPDF_3DView_SetCamera(views[NS2VIEWS], pr.x, pr.y, pr.z, 
            view_c2c[0][0], view_c2c[0][1], view_c2c[0][2],
            camrot*82.70f, view_roll[0]);
    HPDF_3DView_SetPerspectiveProjection(views[NS2VIEWS], 0.3333f);
    //HPDF_3DView_SetOrthogonalProjection(views[NS2VIEWS], 45.0/1000.0);
    HPDF_3DView_SetBackgroundColor(views[NS2VIEWS], _bgr,  _bgg, _bgb);
    HPDF_3DView_SetLighting(views[NS2VIEWS], "White");
    HPDF_U3D_Add3DView(u3d, views[NS2VIEWS]);


    HPDF_U3D_SetDefault3DView(u3d, "Front perspective");

    //  Create annotation
    annot = HPDF_Page_Create3DAnnot (page, rect, HPDF_TRUE, HPDF_FALSE, u3d, NULL);
  
    // make the toolbar appear by default
  
   // HPDF_Dict action = (HPDF_Dict)HPDF_Dict_GetItem (annot, "3DA", HPDF_OCLASS_DICT);
   // HPDF_Dict_AddBoolean (action, "TB", HPDF_TRUE);
  

    // save the document to a file 
    HPDF_SaveToFile (pdf, filepdf);
  
    // clean up
    HPDF_Free (pdf);

    return true;
}
Exemple #27
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;
}
Exemple #28
0
		void FileCreator(const std::string path,
						const std::string destFileName,
						const std::string outline ) {
			std::vector<std::string> files = util::listDir(path);
			if (files.size() <= 0)return;
			std::sort(std::begin(files), std::end(files));
			///////////////////////////
			HPDF_Doc  pdf;
			pdf = HPDF_New(error_handler, NULL);
			if (!pdf) {
				std::cout<<"error: cannot create PdfDoc object"<<std::endl;
				return;
			}

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

			/*
			const char *font_name1;
			const char *font_name2;
			const char *font_name3;
			font_name1 = HPDF_LoadTTFontFromFile(pdf, "C:\\Windows\\Fonts\\Arial.ttf", HPDF_TRUE);
			font_name2 = HPDF_LoadTTFontFromFile(pdf, R"(C:\Windows\Fonts\simsunb.ttf)", HPDF_TRUE);
			font_name3 = HPDF_LoadTTFontFromFile2(pdf, "C:\\Windows\\Fonts\\simsun.ttc", 1, HPDF_TRUE);
			*/

			HPDF_Outline root;
			root = HPDF_CreateOutline(pdf, NULL, outline.c_str(), NULL);
			HPDF_Outline_SetOpened(root, HPDF_TRUE);
			HPDF_SetInfoAttr(pdf, HPDF_INFO_AUTHOR, config::AUTHOR);
			HPDF_SetInfoAttr(pdf, HPDF_INFO_TITLE, path.c_str());

			HPDF_Font font;
			switch (config::LANG_TYPE)
			{
			case pdf::config::CN:
				HPDF_UseCNSFonts(pdf);
				HPDF_UseCNSEncodings(pdf);
				font = HPDF_GetFont(pdf, "SimHei", "GB-EUC-H");  // SimSun  SimHei
				break;
			case pdf::config::TW:
				HPDF_UseCNTFonts(pdf);
				HPDF_UseCNTEncodings(pdf);
				font = HPDF_GetFont(pdf, "MingLiU", "ETen-B5-H");
				break;
			default:
				font = HPDF_GetFont(pdf, "Helvetica", NULL);
				break;
			}

			///////////////////////////			
			std::string contents;
			std::vector<std::string> vec;
			for (std::string file : files) {
				contents = util::getFileContents(file);
				vec = util::split(contents, '\n');
				fileWriter(pdf, root, font, file.substr(path.length()), vec);
			}
			///////////////////////////			
			std::string destFile(path);
			destFile.append("/");
			destFile.append(destFileName);
			HPDF_SaveToFile(pdf, destFile.c_str());
			HPDF_Free(pdf);
		}//end FileCreator()
int main (int argc, char **argv)
{
    HPDF_Doc  pdf;
    HPDF_Page page;
    HPDF_Font def_font;
    HPDF_REAL height;
    HPDF_REAL width;
    HPDF_UINT i;
    int page_num = 1;
    int done = 0;
    char page_number[MAXSTRING];
    int line_num = 1;
    FILE *input_file = NULL;
    for (i = 1; i < argc; i++)
    {
        if (strcmp(argv[i], "-t") == 0)
        {
            strcpy(page_title, argv[++i]);
        }
        else if (strcmp(argv[i], "-o") == 0)
        {
            strcpy(fname, argv[++i]);
        }
        else if (strcmp(argv[i], "-k") == 0)
        {
            page_margin_odd = page_margin_kindle;
            page_margin_even = page_margin_kindle;
        }
        else if (strcmp(argv[i], "-n") == 0)
        {
            no_line_number = 1;
        }
        else if (strcmp(argv[i], "-h")==0)
        {
            usage();
        }
        else if (strcmp(argv[i], "-l") == 0)
        {
            use_landscape = 1;
            page_margin_odd = page_margin_odd_landscape;
            page_margin_even = page_margin_even_landscape;
            LINES_PER_PAGE=50;
        }
        else if (strcmp(argv[i], "-")==0)
        {
            input_file = stdin;
        }
        else
        {
            input_file = fopen(argv[i], "r");
        }
    }

    if (input_file == NULL)
    {
        printf("error: no input specified\n");
        usage();
    }

    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;
    }
    while (!done)
    {
        int n = 0;
        char buf[1000];
        char *p;

        while ((p = fgets(buf, 999, input_file)) && n < LINES_PER_PAGE)
        {
            if (buf[0] == '@')
            {
                if (strncmp(buf, "@title ", 7)==0)
                {
                    strcpy(page_title, buf+7);
                }
                else if (strncmp(buf, "@newpage", 8)==0)
                {
                    if (n != 0 && n != LINES_PER_PAGE-1)
                    {
                        line_num += LINES_PER_PAGE;
                        line_num -= line_num % LINES_PER_PAGE;
                        line_num ++;
                        break;
                    }
                }
                continue;
            }
            lines[n].line_num = line_num++;
            strcpy(lines[n].line, buf);
            n++;
        }

        /* If no more input in future, this is the last page,
         * flag as done.
         */
        if (p == NULL)
            done = 1;

        /* If no lines are read, we are done. */
        if (n == 0)
            break;

        /* Add a new page object. */
        page = HPDF_AddPage (pdf);
        HPDF_Page_SetSize (page, HPDF_PAGE_SIZE_A4, use_landscape?HPDF_PAGE_LANDSCAPE:HPDF_PAGE_PORTRAIT); 
        HPDF_Page_SetRGBFill(page, 0, 0, 0);
        
        height = HPDF_Page_GetHeight (page);
        width = HPDF_Page_GetWidth (page);

        page_margin = EVENPAGE(page_num) ? page_margin_even : page_margin_odd;
        page_size.cx = (int)width;
        page_size.cy = (int)height;

        def_font = HPDF_GetFont (pdf, default_font_name, NULL);
        HPDF_Page_SetFontAndSize (page, def_font, 16);
        print_page_header(pdf, page, page_title);
        print_page_content(pdf, page, lines, n);
        sprintf(page_number, "%d", page_num);
        print_page_footer(pdf, page, page_number);
        page_num++;
    }
    if (page_num > 1)
    {
        HPDF_SaveToFile (pdf, fname);
        printf("Output written to %s\n", fname);
    }
    else
    {
        printf("No output\n");
    }
    
    if (input_file != stdin && input_file != NULL)
        fclose(input_file);

    /* clean up */
    HPDF_Free (pdf);
    return 0;
}
Exemple #30
0
hpdf_doc::~hpdf_doc()
{ 
	HPDF_Free(h_pdf);

}