void PDFGenerator::pdfDoc_AddPage(mlPDF::PAGE_SIZES pageSize, mlPDF::PAGE_DIRECTIONS pageDirection)
{
  if (pdfDocument)
  {
    HPDF_Page newPage = HPDF_AddPage(pdfDocument);

    if (newPage)
    {
      pdfDocCurrentPage = newPage;
      pdfDocPages.push_back(newPage);

      if (pageSize == mlPDF::PAGESIZE_USER) // It is illegal to set this value manually...
      {
        pageSize = mlPDF::PAGESIZE_A4; // ... therefore set it to default value.
      }

      HPDF_Page_SetSize(newPage, (HPDF_PageSizes)pageSize, (HPDF_PageDirection)pageDirection);
      _currentPageSize = pageSize;

      HPDF_Page_SetFontAndSize(pdfDocCurrentPage, _currentFontSettings.font, _currentFontSettings.fontSize);

      HPDF_Page_SetLineWidth(pdfDocCurrentPage, 1);
      pdfDoc_SetStrokeColor(0, 0, 0);
      pdfDoc_SetFillColor(0, 0, 0);

      pdfDoc_CurrentXPos = 0;
      pdfDoc_CurrentYPos = 0;
    }
    else
    {
      _handleError("pdfDoc_AddPage(mlPDF::PAGE_SIZES pageSize, mlPDF::PAGE_DIRECTIONS pageDirection)");
    }
  }
}
Beispiel #2
0
extern void AP_AddPage()
{
    HPDF_Page page = HPDF_AddPage(AP_getCurrentPdfDoc());
    HPDF_Page_SetSize(page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_LANDSCAPE);
    //TODO change this-1000
    HPDF_Page_SetHeight(page, 1000);
}
JNIEXPORT void JNICALL Java_com_draekko_libharu_PdfPage_setSize
    (JNIEnv *env, jobject obj, jobject sizeEnum, jobject directionEnum) {

    haru_setup_error_handler(env, __func__);

    jclass PageSize = env->FindClass("com/draekko/libharu/PdfPage$PageSize");
    jmethodID PageSize_getNameMethod = env->GetMethodID(PageSize, "name", "()Ljava/lang/String;");
    jstring size_value = (jstring)env->CallObjectMethod(sizeEnum, PageSize_getNameMethod);
    const char* size_str = env->GetStringUTFChars(size_value, 0);

    jclass PageDirection = env->FindClass("com/draekko/libharu/PdfPage$PageDirection");
    jmethodID PageDirection_getNameMethod = env->GetMethodID(PageDirection, "name", "()Ljava/lang/String;");
    jstring direction_value = (jstring)env->CallObjectMethod(directionEnum, PageDirection_getNameMethod);
    const char* direction_str = env->GetStringUTFChars(direction_value, 0);

    HPDF_PageSizes size;
    if (strcmp(size_str, "LETTER") == 0) {
        size = HPDF_PAGE_SIZE_LETTER;
    } else if (strcmp(size_str, "LEGAL") == 0) {
        size = HPDF_PAGE_SIZE_LEGAL;
    } else if (strcmp(size_str, "A3") == 0) {
        size = HPDF_PAGE_SIZE_A3;
    } else if (strcmp(size_str, "A4") == 0) {
        size = HPDF_PAGE_SIZE_A4;
    } else if (strcmp(size_str, "A5") == 0) {
        size = HPDF_PAGE_SIZE_A5;
    } else if (strcmp(size_str, "B4") == 0) {
        size = HPDF_PAGE_SIZE_B4;
    } else if (strcmp(size_str, "B5") == 0) {
        size = HPDF_PAGE_SIZE_B5;
    } else if (strcmp(size_str, "EXECUTIVE") == 0) {
        size = HPDF_PAGE_SIZE_EXECUTIVE;
    } else if (strcmp(size_str, "US4x6") == 0) {
        size = HPDF_PAGE_SIZE_US4x6;
    } else if (strcmp(size_str, "US4x8") == 0) {
        size = HPDF_PAGE_SIZE_US4x8;
    } else if (strcmp(size_str, "US5x7") == 0) {
        size = HPDF_PAGE_SIZE_US5x7;
    } else if (strcmp(size_str, "COMM10") == 0) {
        size = HPDF_PAGE_SIZE_COMM10;
    } else {
        haru_throw_exception("Unsupported page size.");
    }

    HPDF_PageDirection direction;
    if (strcmp(direction_str, "PORTRAIT") == 0) {
        direction = HPDF_PAGE_PORTRAIT;
    } else if (strcmp(direction_str, "LANDSCAPE") == 0) {
        direction = HPDF_PAGE_LANDSCAPE;
    } else {
        haru_throw_exception("Unsupported orientation.");
    }

    HPDF_Page page = get_HPDF_Page(env, obj); 
    HPDF_Page_SetSize(page, size, direction);

    env->ReleaseStringUTFChars(size_value, size_str);
    env->ReleaseStringUTFChars(direction_value, direction_str);
    haru_clear_error_handler();
}
/*
 * Class:     org_libharu_PdfPage
 * Method:    setSize
 * Signature: (II)V
 */
JNIEXPORT void JNICALL
Java_org_libharu_PdfPage_setSize(JNIEnv *env, jobject obj, jint size, jint direction) {
    jint page;
    /* Get mHPDFPagePointer */
    page = (*env)->GetIntField(env, obj, mHPDFPagePointer);
    /* Set page size */
    HPDF_Page_SetSize((HPDF_Page) page, getHPDFPageSize(size), getHPDFPageDirection(direction));
}
Beispiel #5
0
  void renderPdf(const Wt::WString& html, HPDF_Doc pdf)
  {
    HPDF_Page page = HPDF_AddPage(pdf);
    HPDF_Page_SetSize(page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT);

    Wt::Render::WPdfRenderer renderer(pdf, page);
    renderer.setMargin(2.54);
    renderer.setDpi(96);
    renderer.render(html);
  }
Beispiel #6
0
void hpdf_doc::protrait()
{
	if (h_direction == HPDF_PAGE_PORTRAIT)
		return;

	h_direction = HPDF_PAGE_LANDSCAPE;
	HPDF_Page_SetSize(h_current_page, HPDF_PAGE_SIZE_A4, h_direction);

	f_width = INCH2PT(f_page_width); 
	f_length = INCH2PT(f_page_length); 

	HPDF_Page_SetHeight(h_current_page, f_length);
	HPDF_Page_SetWidth(h_current_page, f_width);

}
Beispiel #7
0
void hpdf_doc::new_page()
{
	//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;

	h_current_page = HPDF_AddPage(h_pdf);

	HPDF_Page_SetSize(h_current_page, HPDF_PAGE_SIZE_A4, h_direction);

	f_width = INCH2PT(f_page_width); // HPDF_Page_GetWidth(h_current_page);
	f_length = INCH2PT(f_page_length); // HPDF_Page_GetHeight(h_current_page);

	f_xpos = f_margin_x = INCH2PT(f_margin_left);
	f_margin_y = INCH2PT(f_margin_top);
	f_ypos = f_margin_y; // f_length - f_margin_y;

	HPDF_Page_SetHeight(h_current_page, f_length);
	HPDF_Page_SetWidth(h_current_page, f_width);

	f_linespace = 0;
}
Beispiel #8
0
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;
}
Beispiel #9
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
// Setup a PDF document with one page
static void
add_a4page(void) {
    pdf_page = HPDF_AddPage (pdf_doc);
    HPDF_Page_SetSize (pdf_page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT);
}
Beispiel #11
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 #12
0
int write_pdf(int argc, char ** argv, FILE * pipe_in, FILE * pipe_out, FILE * pipe_err)
{
  char * filename = argc > 1 ? argv[1] : "output.pdf";
  if (argc == 1)
  {
    fprintf(stderr, "no filename specified, using '%s'\n", filename);
  }
  
  float b[3][2] = {
    {FLT_MAX, -FLT_MAX},
    {FLT_MAX, -FLT_MAX},
    {FLT_MAX, -FLT_MAX}
  };
  
  HPDF_Doc pdf;
  
  pdf = HPDF_New(NULL, NULL); 
  if (!pdf)
  {
    fprintf(stderr, "ERROR: cannot create pdf object.\n");
    return 1;
  }
  
  HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);
  HPDF_SetPageMode (pdf, HPDF_PAGE_MODE_USE_OUTLINE);
  
  int num_shapes = 0;
  struct Shape ** shapes = NULL;
  
  HPDF_Page page;
  page = HPDF_AddPage (pdf);
  
  HPDF_Page_SetSize (page, HPDF_PAGE_SIZE_LETTER, HPDF_PAGE_PORTRAIT);
  
  long i = 0;
  struct Shape * shape = NULL;
  while ((shape = read_shape(pipe_in)))
  {
    num_shapes++;
    shapes = (struct Shape **)realloc(shapes, sizeof(struct Shape*)*num_shapes);
    if (shapes == NULL) { fprintf(stderr, "realloc for shapes failed :(\n"); exit(0); }
    shapes[num_shapes-1] = shape;
    
    long j;
    for (j = 0 ; j < shape->num_vertexs ; j++)
    {
      float * v = get_vertex(shape, 0, j);
      if (v[0] < b[0][0]) b[0][0] = v[0]; if (v[0] > b[0][1]) b[0][1] = v[0];
      if (v[1] < b[1][0]) b[1][0] = v[1]; if (v[1] > b[1][1]) b[1][1] = v[1];
    }
  }
  
  float dx = b[0][1] - b[0][0];
  float dy = b[1][1] - b[1][0];
  float ratio = dy / dx;
  
  HPDF_Page_SetWidth(page, 2000);
  HPDF_Page_SetHeight(page, 2000.0 * ratio);
  
  for (i = 0 ; i < num_shapes ; i++)
  {
    shape = shapes[i];
    //if (shape->vertex_arrays[0].num_dimensions < 2) { fprintf(stderr, "\n"); continue; }
    
    long j;
    for (j = 0 ; j < shape->num_vertexs ; j++)
    {
      float * v = get_vertex(shape, 0, j);
      if (j == 0)
        HPDF_Page_MoveTo(page, (v[0] - b[0][0]) / dx * 2000.0, (v[1] - b[1][0]) / dy * (2000.0 * ratio));
      else
        HPDF_Page_LineTo(page, (float)(v[0] - b[0][0]) / dx * 2000.0, (float)(v[1] - b[1][0]) / dy * (2000.0 * ratio));
    }
    
    if (shape->gl_type == GL_LINE_LOOP)
    {
      float * v = get_vertex(shape, 0, 0);
      HPDF_Page_LineTo(page, (float)(v[0] - b[0][0]) / dx * 2000.0, (float)(v[1] - b[1][0]) / dy * (2000.0 * ratio));
    }
    
    HPDF_Page_Stroke(page);
    free_shape(shape);
  }
  free(shapes);
  
  HPDF_SaveToFile (pdf, filename);
  
  HPDF_Free(pdf);
}