Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
pdf_page *page;
error=pdf_load_page(&page,xref,0);

I want to draw on view, what should I do?
Posted
Comments
Richard MacCutchan 1-Mar-12 8:46am    
This question is not very clear, please edit your submission and explain your problem in more detail.
chp845 1-Mar-12 23:14pm    
I have exlpained my proble,can you helpe me

1 solution

C++
pdfapp_t *app=new pdfapp_t;
	memset(app, 0, sizeof(pdfapp_t));
	app->scrw = 640;
	app->scrh = 480;
	app->resolution = 72;
	fz_error error;
	fz_stream *file;
	fz_obj *obj;
	fz_obj *info;
	file=fz_open_fd(0);
	int fd = _wopen(L"1.pdf", O_BINARY | O_RDONLY, 0666);
	if(fd<0)
		MessageBox("not exists file");
	file=fz_open_fd(fd);
	error=pdf_open_xref_with_stream(&app->xref,file,NULL);
	if(error)
		MessageBox("not exists file");
	fz_close(file);
	app->outline=pdf_load_outline(app->xref);
	info=fz_dict_gets(app->xref->trailer,"info");
	if(info)
	{
		obj=fz_dict_gets(info,"Title");
		if(obj)
			app->doctitle=pdf_to_utf8(obj);
	}
	error=pdf_load_page_tree(app->xref);
	if(error)
		MessageBox("not exists file");
	app->pagecount=pdf_count_pages(app->xref);
	CString s;
	fz_obj *infos=fz_dict_gets(app->xref->trailer,"Info");
	if(!infos)
		return ;
	if ((obj = fz_dict_gets(infos, "ModDate")));
	app->cache = fz_new_glyph_cache();
	//unsigned short * ucs;
	//ucs = pdf_to_ucs2(obj);
	//MessageBox((LPCTSTR)ucs);
	//fz_free(ucs);
	pdf_page *page;
	fz_device *mdev;
	app->pageno=1;
	error=pdf_load_page(&page,app->xref,app->pageno-1);
	if(error)
		MessageBox("加载pdf失败");
	HDC hdc=::GetDC(m_hWnd);
	fz_matrix ctm;
	fz_bbox bbox1;
	fz_pixmap *image=NULL;
	double zoomreal=1/100.0;
	ctm=viewctm(page, zoomreal, 0);


	//bbox1=page->mediabox;
	fz_colorspace *colorspace = fz_device_bgr;
	image = fz_new_pixmap_with_rect(colorspace, bbox1);
	//fz_clear_pixmap_with_color(image, 255);

	ConvertPixmapForWindows(image);
	int bmpDx = image->w;
	int bmpDy = image->h;
	int bmpRowSize = ((image->w * 3 + 3) / 4) * 4;
	BITMAPINFOHEADER bmih;
	bmih.biSize = sizeof(bmih);
	bmih.biHeight = -bmpDy;
	bmih.biWidth = bmpDx;
	bmih.biPlanes = 1;
	bmih.biBitCount = 24;
	bmih.biCompression = BI_RGB;
	bmih.biSizeImage = bmpDy * bmpRowSize;;
	bmih.biXPelsPerMeter = bmih.biYPelsPerMeter = 0;
	bmih.biClrUsed = bmih.biClrImportant = 0;
	unsigned char* bmpData = image->samples;
	::StretchDIBits(hdc,
		// destination rectangle
		0,0, 100, 100,
		// source rectangle
		0, 0, bmpDx, bmpDy,
		bmpData,
		(BITMAPINFO *)&bmih ,
		DIB_RGB_COLORS,
		SRCCOPY);

i want to show pdf on hdc of mfc dialog,but i failed,can you help me!or so,can you tell me some project based on mupdf using mfc
 
Share this answer
 
Comments
Richard MacCutchan 2-Mar-12 2:36am    
Sorry, I don't know mupdf so I cannot offer any suggestions.
cariolihome 3-Mar-12 16:38pm    
What result was returned by StretchDIBits function ?
chp845 16-Mar-12 4:04am    
i have finished it on hdc,thank you!
Jørd 17-Sep-12 7:00am    
You got some working code for integration of mupdf in a MFC-based project? I'd be grateful!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900