Printing from application code

I have been trying to write C code that would print lines and text to an HP
laser printer.

I have read the “Printing” section in the Photon programmers guide to get me
started. I
have tried the following sequence with no real success.

  • used PpCreatePC() to create a print context
  • used PtPrintSelection(…) to initialize the Print Context
  • used PpSetPC(…) to set the Pp_PC_SOURCE_SIZE
  • used PPstartJob() and PpContinueJob()
  • used PgDrawLine() and PgFlush() to write horizontal lines on the page
  • used PpSuspendJob() and PpEndJob() to close the print context

RESULT: File is sent to the printer,but the lines do not cover the whole
page.
They stop around the middle of the page.
Page size seems to be 640x4080 but was set at 800x1000

What am I doing wrong ?

Jacques

Hi Jacques,

Could you post a sample of the code you are using to do the printing?

Thanks
Brenda

Jacques Gagné wrote:

I have been trying to write C code that would print lines and text to an HP
laser printer.

I have read the “Printing” section in the Photon programmers guide to get me
started. I
have tried the following sequence with no real success.

  • used PpCreatePC() to create a print context
  • used PtPrintSelection(…) to initialize the Print Context
  • used PpSetPC(…) to set the Pp_PC_SOURCE_SIZE
  • used PPstartJob() and PpContinueJob()
  • used PgDrawLine() and PgFlush() to write horizontal lines on the page
  • used PpSuspendJob() and PpEndJob() to close the print context

RESULT: File is sent to the printer,but the lines do not cover the whole
page.
They stop around the middle of the page.
Page size seems to be 640x4080 but was set at 800x1000

What am I doing wrong ?

Jacques

Here is the code that I have been trying to get to work:

(I have removed portions of the code that are of no interest)

int Imprimerfichier( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
*cbinfo )
{
PpPrintContext_t *pPrintContext;
long *lpNumLignes, lNumLignes,lHauteurLigne,lLignePage,lNbrPages,i,j;
PhRect_t FontRect;
PhPoint_t Position,PositionLigne;

PhRect_t *rect;
PhDim_t *dim,size,size_ret;

/* eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

if( (pPrintContext = PpCreatePC()) != NULL)
{
switch(PtPrintSelection(ABW_frmJackEdit,NULL,“Impression”,
pPrintContext,Pt_PRINTSEL_DFLT_LOOK))
{
case Pt_PRINTSEL_PRINT:

PpStartJob(pPrintContext);
if(PpContinueJob(pPrintContext))
{

PpGetPC(pPrintContext,Pp_PC_NONPRINT_MARGINS,&rect);

PpGetPC(pPrintContext,Pp_PC_PAPER_SIZE,&dim);
size.w = (dim->w - (rect->ul.x +
rect->lr.x))/10;
size.h = (dim->h - (rect->ul.y +
rect->lr.y))/10;

PpSetPC(pPrintContext,Pp_PC_SOURCE_SIZE,&size,0); // Sixe is about 800 X
1000

PgSetStrokeColor(Pg_BLACK);
PgSetStrokeWidth(1);

for(i=0,j=10;i<15;i++,j+=10)
{
PgDrawILine(10, j, 200,j);
PgFlush();
}

PpSuspendJob(pPrintContext);
PpEndJob(pPrintContext);
}
break;

case Pt_PRINTSEL_PREVIEW:
break;

case Pt_PRINTSEL_CANCEL:
break;
}
PpReleasePC(pPrintContext);
}

return( Pt_CONTINUE );

}

Thanks for your interest

Hi Jacques,

I added your code to an application and made the following changes that
I show below, once these changes were made I was able to print the
entire page with lines. The problem is that the PpStartJob() and
PpContinueJob() calls are originally made before changing the setting of
the source size. So the source size doesn’t take effect for this print
context. In the docs for printing, these setting would only take effect
after a call to PpPrintNewPage() would be made unless the setting are
changed before calling PpStartJob() and PpContinueJob().

Hope this helps
Regards
Brenda

Jacques Gagné wrote:

Here is the code that I have been trying to get to work:

(I have removed portions of the code that are of no interest)

int Imprimerfichier( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t
*cbinfo )
{
PpPrintContext_t *pPrintContext;
long *lpNumLignes, iNumLignes,lHauteurLigne,lLignePage,lNbrPages,i,j;
PhRect_t FontRect;
PhPoint_t Position,PositionLigne;

PhRect_t *rect;
PhDim_t *dim,size,size_ret;

/* eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

if( (pPrintContext = PpCreatePC()) != NULL)
{
switch(PtPrintSelection(ABW_frmJackEdit,NULL,“Impression”,
pPrintContext,Pt_PRINTSEL_DFLT_LOOK))
{
case Pt_PRINTSEL_PRINT:

/* Moved the next two calls to after the PpSetPc () is called */

// PpStartJob(pPrintContext);
// if(PpContinueJob(pPrintContext))
// {

PpGetPC(pPrintContext,Pp_PC_NONPRINT_MARGINS,&rect);

PpGetPC(pPrintContext,Pp_PC_PAPER_SIZE,&dim);
size.w = (dim->w - (rect->ul.x +
rect->lr.x))/10;
size.h = (dim->h - (rect->ul.y +
rect->lr.y))/10;

PpSetPC(pPrintContext,Pp_PC_SOURCE_SIZE,&size,0); // Sixe is about 800 X
1000

/* Insert the PpStartJob() and PpContinueJob() here /
/
After the PC_SOURCE_SIZE has been set */
PpStartJob(pPrintContext);
PpContinueJob(pPrintContext);

PgSetStrokeColor(Pg_BLACK);
PgSetStrokeWidth(1);

for(i=0,j=10;i<65;i++,j+=15)
{
/* Increased the number of loops to 65 */

/* to fill the page, also set the size.w /
/
to fill across the page */

PgDrawILine(10, j, 200,j);

}
/* Added the flush after the loop */

/* only need to flush the printer context once*/
/* all the drawing is done */
PgFlush();

PpSuspendJob(pPrintContext);
PpEndJob(pPrintContext);
// }
break;

case Pt_PRINTSEL_PREVIEW:
break;

case Pt_PRINTSEL_CANCEL:
break;
}
PpReleasePC(pPrintContext);
}

return( Pt_CONTINUE );

}

Thanks for your interest

GUI Group wrote:

Hi Jacques,

I added your code to an application and made the following changes that
I show below, once these changes were made I was able to print the
entire page with lines. The problem is that the PpStartJob() and
PpContinueJob() calls are originally made before changing the setting of
the source size. So the source size doesn’t take effect for this print
context. In the docs for printing, these setting would only take effect
after a call to PpPrintNewPage() would be made unless the setting are
changed before calling PpStartJob() and PpContinueJob().

Hope this helps
Regards
Brenda

Jacques Gagné wrote:

Here is the code that I have been trying to get to work:

(I have removed portions of the code that are of no interest)

int Imprimerfichier( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t
*cbinfo )
{
PpPrintContext_t *pPrintContext;
long *lpNumLignes,
iNumLignes,lHauteurLigne,lLignePage,lNbrPages,i,j;
PhRect_t FontRect;
PhPoint_t Position,PositionLigne;

PhRect_t *rect;
PhDim_t *dim,size,size_ret;

/* eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

if( (pPrintContext = PpCreatePC()) != NULL)
{
switch(PtPrintSelection(ABW_frmJackEdit,NULL,“Impression”,
pPrintContext,Pt_PRINTSEL_DFLT_LOOK))
{
case Pt_PRINTSEL_PRINT:

/* Moved the next two calls to after the PpSetPc () is called */
// PpStartJob(pPrintContext);
// if(PpContinueJob(pPrintContext))
// {


PpGetPC(pPrintContext,Pp_PC_NONPRINT_MARGINS,&rect);

PpGetPC(pPrintContext,Pp_PC_PAPER_SIZE,&dim);
size.w = (dim->w - (rect->ul.x +
rect->lr.x))/10;
size.h = (dim->h - (rect->ul.y +
rect->lr.y))/10;

PpSetPC(pPrintContext,Pp_PC_SOURCE_SIZE,&size,0); // Sixe is about
800 X
1000


/* Insert the PpStartJob() and PpContinueJob() here /
/
After the PC_SOURCE_SIZE has been set */
PpStartJob(pPrintContext);
PpContinueJob(pPrintContext);


PgSetStrokeColor(Pg_BLACK);
PgSetStrokeWidth(1);

for(i=0,j=10;i<65;i++,j+=15)
{

/* Increased the number of loops to 65 /
/
to fill the page, also set the size.w /
/
to fill across the page /


/
Forgot to make the change to this line */

/* in previous post */
PgDrawILine(10, j, size.w,j);

}

/* Added the flush after the loop /
/
only need to flush the printer context once*/
/* all the drawing is done */
PgFlush();


PpSuspendJob(pPrintContext);
PpEndJob(pPrintContext);

// }

break;

case Pt_PRINTSEL_PREVIEW:
break;

case Pt_PRINTSEL_CANCEL:
break;
}
PpReleasePC(pPrintContext);
}

return( Pt_CONTINUE );

}

Thanks for your interest
\

Thanks, now it works fine !

Jacques