コード例 #1
0
ファイル: jpeg_demo.c プロジェクト: AKKF/libharu
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);
}
コード例 #2
0
ファイル: make_rawimage.c プロジェクト: AKKF/libharu
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;
}
コード例 #3
0
JNIEXPORT jint JNICALL Java_com_draekko_libharu_PdfImage_getHeight
  (JNIEnv *env, jobject obj) {
  
    haru_setup_error_handler(env, __func__);
    HPDF_UINT value;
    HPDF_Image image = get_HPDF_Image(env, obj); 
    value = HPDF_Image_GetHeight(image);
    haru_clear_error_handler();

    return value;
}
コード例 #4
0
ファイル: smp_jpg2pdf.cpp プロジェクト: tenk-a/bld_lib_bat
	bool addJpgPage(HPDF_Doc pdf, char const* jpgname) {
	    HPDF_Page 	page = HPDF_AddPage (pdf);
		if (!page)
			return false;
	    HPDF_Image	image	= HPDF_LoadJpegImageFromFile (pdf, jpgname);
		if (!image) {
			printf("load error %s\n", jpgname);
			return false;
		}
		HPDF_REAL img_w = HPDF_REAL(HPDF_Image_GetWidth(image));
		HPDF_REAL img_h = HPDF_REAL(HPDF_Image_GetHeight(image));
	    HPDF_Page_SetWidth (page, img_w);
	    HPDF_Page_SetHeight(page, img_h);
	    HPDF_Page_DrawImage (page, image, 0, 0, img_w, img_h);
		return true;
	}
コード例 #5
0
ファイル: PDFImageService.cpp プロジェクト: Tisseo/synthese
		ParametersMap PDFImageService::run(
			std::ostream& stream,
			const Request& request
		) const {

			// Get the pdf
			PDF& pdf(PDFCMSModule::GetRequestPDF(request));

			// Get or create image
			HPDF_Image image(pdf.getImage(_key));
			if(!image)
			{
				string content(_image->get<WebpageContent>().getCMSScript().eval());
				image = pdf.embedPNGImage(_key, content);
			}

			// Width and Height
			float width(_width);
			float height(_height);
			if(!width && height)
			{
				HPDF_Point siz(HPDF_Image_GetSize(image));
				width = _height * (siz.x / siz.y);
			}
			else if(!height && width)
			{
				HPDF_Point siz(HPDF_Image_GetSize(image));
				height = _width * (siz.y / siz.x);
			}

			// Draw the image
			pdf.drawImage(
				image,
				PDF::GetPixelsFromMM(_x),
				PDF::GetPixelsFromMM(_y),
				width ? PDF::GetPixelsFromMM(width) : HPDF_Image_GetWidth(image),
				height ? PDF::GetPixelsFromMM(height) : HPDF_Image_GetHeight(image)
			);

			// Return nothing
			ParametersMap map;
			return map;
		}
コード例 #6
0
ファイル: image.cpp プロジェクト: Klaim/falcon
FALCON_FUNC Image::getHeight( VMachine* vm )
{
  Mod::hpdf::Dict* self = dyncast<Mod::hpdf::Dict*>( vm->self().asObject() );
  HPDF_REAL ret = HPDF_Image_GetHeight( self->handle() );
  vm->retval(ret);
}
コード例 #7
0
ファイル: testlibhpdf.cpp プロジェクト: ProjectTegano/Tegano
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;
}