Thread: Printing with printer

  1. #1
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476

    Printing with printer

    Hi, I've made a program to print in Linux. The steps are:
    1. Open a new temporary LaTeX file
    2. Insert the strings to be printed in LaTeX
    3. Close and save the temporary LaTeX file
    4. Convert the temporary LaTeX file to DVI file in the shell
    5. Convert the DVI file to PS file in the shell
    6. Print the PS file with CUPS
    7. Delete all the temporary files

    The code is like this:
    Code:
        //Print to file
        fstream filestr;
        //Insert LaTeX code and strings to be printed here
        ..........
        filestr.close();
    
        //Print this!!!!!
      int jobid;
      int num_dests;
      cups_dest_t *dests;
    
      // Get printer destinations
      num_dests = cupsGetDests(&dests);
    
      cups_dest_t *mydest;
    
    
      // Get the default printer
      mydest = cupsGetDest(NULL, NULL, num_dests, dests);
    
      //Convert to DVI
      system("latex ./temp-print.tex");
      
      //Convert to PS
      system("dvips temp-print -t landscape -o temp-print.ps");
    
      //Print to default printer
      jobid = cupsPrintFile(mydest->name, "./temp-print.ps", "tes", 0, NULL);
      
      if (jobid == 0)
        puts(ippErrorString(cupsLastError()));
      else
        {
        	SDL_Delay(20000); //Delay to make sure the printing job finished
        	int status;
        	status = cupsCancelJob(mydest->name, jobid);
            system("rm -f ./temp-print.*"); //Delete all temporary files
        }
    The code works fine. But the problem is, when I executed the code, my program is kind of lagging. I suspected it's because I used 3 calls to sh ( system("latex ./temp-print.tex"); , system("dvips temp-print -t landscape -o temp-print.ps"); , system("rm -f ./temp-print.*"); ). How can I make my program run smoothly?

    Thanks in advance.

    PS: I see that the board has been maintenanced recently because I couldn't find my previous messages prior to August 2006.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > my program is kind of lagging
    SDL_Delay(20000);
    Got it yet?

    > PS: I see that the board has been maintenanced recently because I couldn't find my previous messages prior to August 2006
    I can see all posts for user quite happily.
    The main forum list is usually limited by "Display Options" (bottom left)
    Pick a bigger date range, or find all posts you posted from looking at your own profile.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    The delay didn't have anything to do with the lagging. FYI, I'm using SDL to make some animation and the printing code is in a diferent thread with the animation thread. The delay is only used to make sure the printing job has been done and canceled the job, because for some reason the job gets stuck even if it was already done with its printing. The one that's lagged was the animation thread. It gets kind of halted for a few milisecond when the printing thread called sh.

    Thanks.
    Last edited by g4j31a5; 09-13-2006 at 07:41 PM.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Well, system() is known to be slow. There's not much you can do about it, except maybe try exec*() or the equivalent Win32 function.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I doubt he can use Win32 functions under linux.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You're probably right. But [s]he can most likely use exec* or (most likely, if you want to function to return) spawn*.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Printing Problem
    By silverlight001 in forum C# Programming
    Replies: 0
    Last Post: 03-23-2009, 01:13 AM
  2. Printing Debug Without Printer :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 10-15-2002, 02:18 PM
  3. Printing to a printer....I already did a search :)
    By fastmonkey in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2002, 01:51 AM
  4. Printing to Printer via Device Driver
    By JamMan in forum C++ Programming
    Replies: 1
    Last Post: 11-19-2001, 05:20 PM
  5. printing on network printer
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2001, 02:10 PM