Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.apps > #767
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Subject | Re: Printing from a C program in linux |
| Newsgroups | comp.os.linux.development.apps |
| References | <B79FD1EF.4922%jenco@wol.be> <fab8e3f2-b94b-484b-8d42-303c6ef86b23@googlegroups.com> |
| Organization | The Pitcher Digital Freehold |
| Message-ID | <49Ssw.285980$_R5.273222@fx28.iad> (permalink) |
| Date | 2015-01-12 10:56 -0500 |
On Monday January 12 2015 08:48, in
comp.os.linux.development.apps, "mtkhusro92@gmail.com"
<mtkhusro92@gmail.com> wrote:
> On Tuesday, 14 August 2001 22:14:45 UTC-7, Jenco wrote:
>> Hi,
>>
>> I'm making a program in C for linux but an important thing i can't find
>> in my books is how to print from your C program
>>
>>
>> any hint,link or tutorial is welcome
>>
>>
>>
>> thaaaaaaaaaaaaaaaaanx Marco
>
>
>
> any help?
>
/*
print_test_1.c
Sample program to illustrate how to spool a plain text
report to the Linux print system.
*/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *spool;
int line_no;
if ((spool = popen("lpr -J \"Plain text print test\"","w")) == NULL)
{
fprintf(stderr,"Failed to connect to print spooler\n");
return EXIT_FAILURE;
}
fprintf(spool,"Plain text spool test\n");
for (line_no = 0; line_no < 20; ++line_no)
fprintf(spool,"Line %d - test test test test test\n",line_no);
if (pclose(spool) == -1)
fprintf(stderr,"Failed to correctly release spooled print\n");
else
printf("Report spooled successfully\n");
return EXIT_SUCCESS;
}
##########################################################################
/*
print_test_2.c
Sample program to illustrate how to spool a Postscript
report to the Linux print system.
*/
#include <stdio.h>
#include <stdlib.h>
char *postscript[] = { /* example postscript commands */
"%!",
"% Sample of printing text",
"/Times-Roman findfont % Get the basic font",
"20 scalefont % Scale the font to 20 points",
"setfont % Make it the current font",
"newpath % Start a new path",
"72 72 moveto % Lower left corner of text at (72, 72)",
"(Hello, world!) show % Typeset 'Hello, world!',
"showpage"
};
int main(void)
{
FILE *spool;
int line_no;
if ((spool = popen("lpr -J \"Postscript print test\"","w")) == NULL)
{
fprintf(stderr,"Failed to connect to print spooler\n");
return EXIT_FAILURE;
}
for (line_no = 0;
line_no < (sizeof postscript / sizeof postscript[0]);
++line_no)
fprintf(spool,"%s\n",postscript[line_no]);
if (pclose(spool) == -1)
fprintf(stderr,"Failed to correctly release spooled print\n");
else
printf("Report spooled successfully\n");
return EXIT_SUCCESS;
}
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Back to comp.os.linux.development.apps | Previous | Next — Previous in thread | Next in thread | Find similar
Re: Printing from a C program in linux mtkhusro92@gmail.com - 2015-01-12 05:48 -0800
Re: Printing from a C program in linux Jan Panteltje <panteltje@yahoo.com> - 2015-01-12 14:33 +0000
Re: Printing from a C program in linux floyd@apaflo.com (Floyd L. Davidson) - 2015-01-12 05:34 -0900
Re: Printing from a C program in linux Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-01-12 10:56 -0500
Re: Printing from a C program in linux Jasen Betts <jasen@xnet.co.nz> - 2015-01-13 06:38 +0000
Re: Printing from a C program in linux Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2015-01-13 17:28 +0200
csiph-web