Printing from Juce


#1

I need to print, as in a paper printer, from Juce. Specifically, is there a way I can draw into a juce graphic like you can a MFC Graphics Context, then output it to a printer, like in MFC? Through a quick look in the api I could barely find the word “print” two times… This will be windows only, at least for now, it may be ported to linux.


#2

yeah, this is something I’ve yet to look at at all… will do as soon as I can get the chance. Hopefully it’s not something that’ll be too tricky to add, but I don’t think I’ve ever written any printing code before, so don’t know.


#3

Unknown how it is on other systems, I’ve only done it on windows. Just basically paint an image the size of the page, and send it to the printer, pretty easy in mfc…


#4

I do apologize for the double-post but it has been a few days.

Does anyone have experience on printing from Juce so I can save a good bit of time?


#5

hello folks,

I am new to JUCE, but i have got the API solution here, works fine:

[code]#include <windows.h>

/*

  1. call the func, the first time, like:
    HDC printDC = toPaper(START_PRINTER);

  2. now make a loop for each page, like:
    int p;
    for (p=0; p<numPages; p++)
    {
    StartPage(printDC);
    // DT_WORDBREAK is a collecting constant, recommended for multiLine output
    DrawText(printDC, “once upon a time…”, 19, &rt, DT_WORDBREAK);
    LineTo(printDC, 300, 300);
    EndPage(printDC);
    }

  3. when you ar done, call the func a second time like:
    HDC printDC = toPaper(END_PRINTER);

/////////// Dev-C++: to use the WIN_API stuff at the console, you will need
// the “libgdi32.a”.
*/

HDC toPaper(int toDo)
{
static PRINTDLG pd;

switch (toDo)
	{
	case START_PRINTER:
		memset(&pd, 0, sizeof(PRINTDLG));
		pd.lStructSize = sizeof(PRINTDLG);
		pd.hwndOwner = 0; // hWnd;
		pd.Flags     = PD_RETURNDC;

		if (PrintDlg(&pd)) 
			{
			DOCINFO di;

			memset(&di, 0, sizeof(DOCINFO));
			di.cbSize	= sizeof(DOCINFO);
			di.lpszDocName	= "dosDrucker";

			StartDoc(pd.hDC, &di);
			return pd.hDC;
			}
		else {error("PrintDlg(&pd) hat Fehler ret.");}
		break;
	case END_PRINTER:
		EndDoc(pd.hDC);  // Dokument wird geschlossen
		DeleteDC(pd.hDC);
		
		if (pd.hDevMode != NULL) GlobalFree(pd.hDevMode);
		if (pd.hDevNames != NULL) GlobalFree(pd.hDevNames);
		return 0;
	default:
		break;
	}

return 0;
}

[/code]

the original can be found here:
http://willemer.de/informatik/windows/windruck.htm
i have only wrapped it to the func.

greetz
Amando


#6

mmmh :roll: boost is not in here, you better delete the post :roll:


#7

???
What do you mean with “boost”? I’m not a native english speaker.
Do you mind the API stuff, or what?
Is that the “thanks” for people who want to do you a favor?

Amando


#8

I think he’s being funny :wink: some boost obsessives at the moment :slight_smile:


#9

Back on the topic of printing… I actually added a class LowLevelGraphicsPostScriptRenderer a few versions back, which is a graphics context that churns out postscript.

It’s not quite finished, but the idea was that you’d draw to a postscript context, then dump the output to a printer - I’ve not had chance to figure out all the platform-specific printer bits yet, but if anyone’s messing around with trying to print in juce, that’s a good place to start.


#10