In My c++ application (dll) i am printing bitmaps without using print dialogue i.e. from back end code without prompting user to select file. This functionality is working fine. Now i trying to implement another method that will print already existing pdf file on printer. Exisiting function is specific to bitmaps, i am confused that how i can send pdf file to printer. Following is the working code
DOCINFO diDocInfo = {0};
diDocInfo.cbSize = sizeof( DOCINFO );
diDocInfo.lpszDocName = L"printTest";
if( StartDoc( memDC.GetSafeHdc(), &diDocInfo ) > 0 )
{
if( StartPage( memDC.GetSafeHdc() ) > 0 )
{
CBitmap bitmap;
CImage frontImage;
frontImage.Load(_T("C:Test.bmp"));
bitmap.Attach(frontImage.Detach());
BITMAP bm;
bitmap.GetBitmap(&bm);
int w = bm.bmWidth;
int h = bm.bmHeight;
// create memory device context
CDC tempDC;
tempDC.CreateCompatibleDC(&memDC);
CBitmap *pBmp = tempDC.SelectObject(&bitmap);
tempDC.SetMapMode(memDC.GetMapMode());
memDC.SetStretchBltMode(HALFTONE);
memDC.StretchBlt(0, 0, 994, 624, &tempDC, 0, 0, 994, 624, 13369376);
EndPage(memDC.GetSafeHdc());
}
}
I am unable to find some way to pass pdf file instead of bitmap to DC
A bitmap is raw data immediately accessible to the operating system. PDF files are quite complicated beasts that must be parsed (difficult) and rendered (hard) if written from scratch.
Your best course of action would be using some existing PDF access library (like MuPDF) to do the heavy lifting for you. With that you should either produce a rasterization of the PDF, or vector drawing commands sent to the GDI to print. Fortunately PDF (-1/A) does not do things that can't be mapped to GDI; the hardest part would be processing embedded fonts; if you don't want to rasterize them you'll have to upload glyph data into the GDI context used for printing.