• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1124
  • Last Modified:

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

  • 2
1 Solution
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).
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


Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now