Esempio n. 1
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);
}
Esempio n. 2
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