Article View: borland.public.cppbuilder.nativeapi
Article #14694Re: how to print a string directly to a printer using "fprintf" or "printf" ?
From: Bob Gonder
Date: Wed, 06 Aug 2003 21:50
Date: Wed, 06 Aug 2003 21:50
62 lines
2910 bytes
2910 bytes
Richard Yu wrote: >My printer is a network printer, I tried this code, > >char *PortName="IP_192.168.0.55 "; > FILE *Printer=fopen(PortName,"wb"); > fprintf(Printer,"Text:\r\n\n","test string "); > >it didn't do any thing , don't know why. Is it a Page printer? (Laserjet/multifunction type) Try adding fprintf(Printer,"\f"); fclose(Printer); I use one of 3 methods to print (depending on the type of printer), all Win32 API. 1) Essentially "DOS" mode CreateFile WriteFile CloseHandle Usually write a form-feed(12) before closing the handle. 2) Simple "raw" mode OpenPrinter StartDocPrinter StartPagePrinter WritePrinter EndPagePrinter EndDocPrinter ClosePrinter I think EndPagePrinter causes a form-feed. But I always take care of it myself. 3) Full Windows DC mode OpenPrinter num_bytes=DocumentProperties(NULL,printerHandle,&printerfile_port,NULL,NULL,0); // allocate the memory DevMode=(DEVMODE*)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,num_bytes); // call DocumentProperties() again, to get the devmode. DocumentProperties(NULL,printerHandle,&printerfile_port,DevMode,NULL,DM_OUT_BUFFER); printerDC = CreateDC( NULL, &printerfile_port, NULL, DevMode); GlobalFree(DevMode); printerJob=StartDoc(printerDC,&lpdi); StartPage(printerDC); SetTextAlign(printerDC,TA_LEFT+TA_TOP+TA_NOUPDATECP); SetBkMode (printerDC, TRANSPARENT); ExtTextOut(printerDC,printerDx*x,printerDy*y, 0, // text-output options (RECT*)NULL, // optional clipping and/or opaquing str, // points to string z, // number of characters in string (INT *)NULL ); // pointer to array of intercharacter EndPage(printerDC); EndDoc(printerDC); DeleteDC(printerDC); ClosePrinter(printerHandle);
Technical Details
Message-ID:
<4ms2jvgakhv47j1giukpjalfbinm5e1m5n@4ax.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f314de8@newsgroups.borland.com> <3f315101$1@newsgroups.borland.com> <3f316dd1$3@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ff83352b6b456ff2 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-06 15:10:44 PST From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: how to print a string directly to a printer using "fprintf" or "printf" ? Date: Wed, 06 Aug 2003 14:50:08 -0700 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <4ms2jvgakhv47j1giukpjalfbinm5e1m5n@4ax.com> References: <3f314de8@newsgroups.borland.com> <3f315101$1@newsgroups.borland.com> <3f316dd1$3@newsgroups.borland.com> X-Newsreader: Forte Agent 1.91/32.564 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 67.31.164.232 X-Trace: newsgroups.borland.com 1060206566 67.31.164.232 (6 Aug 2003 14:49:26 -0700) Lines: 64 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail