Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

printing

Posted on 1999-07-11
5
Medium Priority
?
210 Views
Last Modified: 2010-04-15
how to call a printer in c ?
0
Comment
Question by:eddyhalim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 10

Expert Comment

by:rbr
ID: 1263504
Which OS? What to you mean with "call"?
0
 
LVL 3

Expert Comment

by:Norbert
ID: 1263505
If you are using dos - and if I remember right unix is nearly the same - there is a already opened stream named stdprn.
so you can print like writing to a file:
fprintf(stdprn,YourFormatString,...);
fwrite(stdprn,YourData,...);
...
this works fine for simple text.
If you have to print something other than simple text and you have a OS without printer support you have to know the printer control commands (for example for switching from text to grapic mode) the control commands may be different for each printer type. These comands must be send to the printer before (for init) you start to print and often also while you print (print mode changing, print position,...)

If you have an OS that supports printing - like Windows - things are much easier:
Drivers for the supported printers are already installed.
You print like you would draw on the screen regardless what kind of printer is used.

0
 
LVL 6

Accepted Solution

by:
Triskelion earned 20 total points
ID: 1263506
You can also use fopen if it is LPT1, LPT2 or any other printing device.

{
   FILE * hPrinter;
   hPrinter=fopen("LPT1", "wb");
   fprintf(...);
   fclose(hPrinter);
}
0
 

Author Comment

by:eddyhalim
ID: 1263507
how aboout in graphic mode?please list the source for me?
0
 
LVL 3

Expert Comment

by:Norbert
ID: 1263508
You should!!!! tell wich operating system
DOS: Hard, no OS support, you have to do it for each printer type by yourself.
Select all the printers you want to support.
Buy them to test your printer output.
Read the command table of each printer.
select the commands you need for your printings.
build the output(mix between printer command and data to print)
and at last
printIt(char* WhatYouHaveToPint,long SizeOfWhatYouHaveToPint)
{
   FILE * hPrinter;
   hPrinter=fopen("LPT1", "wb");
   fwrite(hPribter,WhatYouHaveToPint,SizeOfWhatYouHaveToPint);
   fclose(hPrinter);
}
Windows: Much easier
PrintIt(HDC PrinterDeviceContect)
{
    DoYourDrawings_like_you_did_on_Screen();
}
If it works for one printer it should work for all printers windows has device drivers installed.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

721 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