LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-02-2011, 05:21 AM   #1
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 807

Rep: Reputation: 40
Printing to a [Zebra] CUPS printer from my Qt application


I have written a Qt4 app and need to print to my barcode printer. I can create a valid barcode file and if I use cutecom to copy this file via the printer's serial port it prints the label, so I know I am producing the correct information.

I am having problems with CUPS though. Test pages print blank for a start. At first if I called the cups API with this kind of thing:

Code:
	jobId = cupsCreateJob( CUPS_HTTP_DEFAULT, printer_name, job_name, 0, NULL );

	if ( jobId > 0 )
	        {
		const char* format = CUPS_FORMAT_TEXT;  // CUPS_FORMAT_POSTSCRIPT;

		cupsStartDocument( CUPS_HTTP_DEFAULT, printer_name, jobId, text, format, true );
// text is the ASCII string sent that can be sent via the serial port and works
		cupsWriteRequestData( CUPS_HTTP_DEFAULT, text, strlen( text ) ); 

		cupsFinishDocument( CUPS_HTTP_DEFAULT, printer_name );
	        }
It would print text rather than the barcode. Now I can't get anything out of it. I think I should be able to do something like:

lp -d S4M zebra.zpl

To send the file to the printer and, indeed, you can see the printer receives data but prints nothing out.

Is there something different/extra I need to do when using CUPS rather than the serial port for getting a printer to actually print out?

Thanks!
 
Old 10-02-2011, 07:34 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
I've worked with the CUPS library before, however when I printed, the text came from a file. I do not know if that makes a difference. Do you know if your specialized printer requires text-formatted data, or does it accept postscript-formatted only? You seem to be certain that it is text only.

Here's some code I played with in the past (written in C++); it is very similar to yours in a lot of respects:
Code:
int
PrintUtility::print(std::istream& is, const char* filename)
{
   int jobId = 0;

   if (is.good() && !myPrinterName.empty())
   {
      collectOptions();

      jobId = cupsCreateJob(CUPS_HTTP_DEFAULT, myPrinterName.c_str(), filename,
                            myNumOptions, myOptions);

      if (jobId > 0)
      {
         const char* format = (std::string(filename).find(".ps") != std::string::npos ?
                               CUPS_FORMAT_POSTSCRIPT : CUPS_FORMAT_TEXT);

         char buffer[4096] = {0};
         snprintf(buffer, sizeof(buffer) - 1, "%s", filename);

         cupsStartDocument(CUPS_HTTP_DEFAULT, myPrinterName.c_str(), jobId, buffer, format, true);

         while (is.good())
         {
            is.read(buffer, sizeof(buffer));

            if (is.gcount() > 0)
            {
               cupsWriteRequestData(CUPS_HTTP_DEFAULT, buffer, is.gcount());
            }
         }

         cupsFinishDocument(CUPS_HTTP_DEFAULT, myPrinterName.c_str());
      }

      releaseOptions();
   }

   return jobId;
}

Last edited by dwhitney67; 10-02-2011 at 10:11 AM.
 
Old 10-02-2011, 08:05 AM   #3
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 807

Original Poster
Rep: Reputation: 40
Well, I am pretty sure it's just a text thing. If I copy a text file to its serial port it prints out fine, and the ZPL language datasheet just goes on about ASCII characters.

Yours does indeed look very similar to mine. I've seen lots of people say this is doable, and I am sure I'm just missing something basic that would make it spring in to life! Just can't suss it though.
 
Old 10-03-2011, 11:46 AM   #4
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 807

Original Poster
Rep: Reputation: 40
OK, just in case this helps someone else, forget about it being a Zebra printer, set it up as a raw stream.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing to a Zebra printer using a php aplication web khriz Programming 6 02-22-2012 11:36 PM
problem in printing from cups to zebra s4m printer mdahai20 Linux - Newbie 2 03-03-2011 04:54 AM
Printing Bar-code Labels on Zebra Printer supanatral Linux - Software 2 05-20-2010 10:11 AM
cups to cups printing through network on usb printer checkmate3001 Linux - Server 2 02-16-2009 12:12 PM
CUPS: Can't get Zebra LP 2844 label printer to work! Oskare100 Linux - Hardware 0 10-05-2007 01:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration