Unidriver OEMTextOut, wrong output characters

Posted on 2008-11-19
Last Modified: 2013-12-04
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

Question by:headsy
    LVL 49

    Accepted 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).
    LVL 49

    Expert Comment

    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

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
    What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now