send data to printer and print on paper

This is a discussion on send data to printer and print on paper within the C Programming forums, part of the General Programming Boards category; I want to ask about how to send data to printer and print on paper. My data is not text ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    Lightbulb send data to printer and print on paper

    I want to ask about how to send data to printer and print on paper. My data is not text file but it is barcode pictrue in pbm format. This format is simple. 1 is solid black character 0 is solid white like this

    111001100111100111001100
    111001100111100111001100
    111001100111100111001100
    111001100111100111001100

    Can you tell me how to send this data to printer and print in solid black and white character.I see the past post. There is code to print text file below.Do you know how to edit this below code to print barcode ? Thank you for your answer.

    (I use Window ME and Visual C++ 6.0)



    code:--------------------------------------------------------------------------------
    #include <stdio.h>
    #include <stdlib.h>

    int main(void)
    {
    FILE *printer = fopen("LPT1","w");
    FILE *fp;
    char str[256];
    char buf[BUFSIZ];
    printf("File name? ");
    scanf("%s",str);
    fp = fopen(str,"r");
    if(!fp)
    {
    printf("File does not exist\n");
    return -1;
    }
    fgets(buf,BUFSIZ,fp);
    while(buf[0])
    {
    fprintf(printer,"%s",buf);
    fgets(buf,BUFSIZ,fp);
    }
    fprintf(printer,"\f");
    return 0;
    }
    --------------------------------------------------------------------------------

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    First off, your loop control is incorrect:
    >fgets(buf, BUFSIZ, fp);
    >while (buf[0])
    You should do it this way
    Code:
    while (fgets(buf, BUFSIZ, fp) != NULL)
    {
        fprintf(printer, "%s", buf);
    }
    Now, how to print characters that represent a barcode.... Well, I suppose you could review the ASCII chart and find the appropriate characters, but I'm not sure they exist. Don't you require specific thickness of line and pitch?

    Anyway, you could try something like this:
    Code:
    #define BAR_FOR_ZERO ' '  /* Space */
    #define BAR_FOR_ONE  '|'  /* v-bar */
    
    while ((c = fgetc(fp)) != EOF)
    {
    	switch (c)
    	{
    		case '0': fputc(BAR_FOR_ZERO, printer); break;
    		case '1': fputc(BAR_FOR_ONE, printer); break;
    		default: /* Handle other chars here */ break;
    	}
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Set Printer Prior To Loading Print Dialog Box
    By Beaner in forum Windows Programming
    Replies: 3
    Last Post: 10-10-2008, 02:02 PM
  2. To generate bar code from a number
    By darkducke in forum C Programming
    Replies: 18
    Last Post: 01-16-2008, 06:33 AM
  3. print out to a printer, need help
    By IXxAlnxXI in forum C++ Programming
    Replies: 1
    Last Post: 03-25-2007, 02:24 AM
  4. how do you make a program send data to the printer?
    By Sintu in forum C++ Programming
    Replies: 19
    Last Post: 10-20-2005, 08:22 PM
  5. How to print out the data throw printer.Attn Salem
    By Jason in forum C Programming
    Replies: 2
    Last Post: 09-23-2001, 06:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21