Unidriver OEMTextOut, wrong output characters

I'm developing a windows printer driver, based on unidriver. One of the capabilities of the driver is to hook all text that is printed and send it directly to a file. This capability works ok with some printed documents, but with other documents (some pdf's, or printing from Firefox browser) I get scrambled text that doesn't make any sense. In attachment I will attach one pdf where I cannot get correct printed text.

I need to know how to get the right text, i.e., I want to have an string that's exactly what we can read when we open the pdf.

The attached code snippet works ok when printing the Print Test Page from Windows. All text output is readable.

Attached is one PDF that give the problem, and a output file that shows the text that DrvtextOut is getting.
BOOL APIENTRY OEMTextOut(SURFOBJ* pso, STROBJ* pstro, FONTOBJ* pfo, CLIPOBJ* pco, RECTL* prclExtra, RECTL* prclOpaque, BRUSHOBJ* pboFore, BRUSHOBJ* pboOpaque, POINTL* pptlOrg, MIX mix )
	write_log( 3, _T("OEMTextOut"), _T(""));
	ULONG	ulTextSize	;
	char*	AnsiText	;
	BOOL	iRes		= TRUE;
	if (pso == NULL || pstro == NULL || pfo == NULL)
		OEMDBG(DBG_VERBOSE, L"\tInvalid parameters.");
		return FALSE;
	PDEVOBJ		ppdev	= (PDEVOBJ)pso->dhpdev;
	DWORD dwResult = 0;
	if (ppdev && pstro->pwszOrg != NULL)
		//dwResult = ppdev->pDrvProcs->DrvWriteSpoolBuf(ppdev, (LPBYTE)"TextOut\r\n", 9);
		AnsiText = (char*)EngAllocMem(FL_ZERO_MEMORY, pstro->cGlyphs + 1, DRIVER_ID);
		if (AnsiText)
			EngUnicodeToMultiByteN(AnsiText, stro->cGlyphs, &ulTextSize, pstro->pwszOrg, pstro->cGlyphs * sizeof(WCHAR));
			DWORD dwBufOffset = OemPDEV->textProc.dwBufSize;
			// Increase the buffer by the size of the current band
			if (!bGrowTextBuffer(pOemPDEV, strlen(AnsiText) + 2))
				write_log( 1, _T("OEMTextOut"), _T(""));
				return E_FAIL;
			CopyMemory((pOemPDEV->textProc.pBufStart + dwBufOffset), (LPBYTE)AnsiText, strlen(AnsiText));
			CopyMemory((pOemPDEV->textProc.pBufStart + dwBufOffset + strlen(AnsiText)), (LPBYTE)"\r\n", 2);
			write_log( 3, _T("OEMTextOut"), _T("%s"), pstro->pwszOrg);
	// Punt call back to UNIDRV.
	return (pOemPDEV->m_pfnDrvTextOut)(pso, pstro, pfo, pco, prclExtra, prclOpaque, pboFore, pboOpaque, pptlOrg, mix);

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I've run into the same problem, working from a different direction. I installed the printer driver named "Generic Text/Only" and set it to print "To File" with the idea of capturing the text from a PDF file. It's no go -- though it works for many other applications. I assume that the Acrobat Reader program is outputing image data rather than textual data.
I believe that the easiest way to obtain the text from a PDF file is to Edit/Select All (or Ctrl+A) , then Copy (Ctrl+C), then open a text file with notepad and paste (Ctrl+V).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
For what it's worth: The output recorded in 3dprinter.txt does map to regular text. For instance, the PDF shows Allan and the output shows %PPER

PDF hex drv hex
A   41   %  25   
l   6c   P  50
l   6c   P  50
a   61   E  45
n   6e   R  52
Note that if you add 0x1c (25 decimal)to each drv output byte, 
you get the ASCII value of the original PDF text.

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.