Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Count the number of pages in a PCL file.

Count the number of pages in a PCL file.

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    raf sp
    wrote on last edited by
    #1

    The code below, would must to show the count the number of pages in a PCL file. But, don´t show. Why?? What is wrong?? //---------------------------------- #include "stdio.h" #include "stdlib.h" #include "string.h" int main (int argc, char **argv) { FILE *InputFile; char ch, EndTag, tag[2], *InputFileName; int n, BlockSize, Pages, Copies, Quiet; unsigned long FileSize, FilePos; BlockSize =0; Pages =0; FileSize =0; FilePos =0; Copies =0; Quiet =1; InputFileName = NULL; // Parse command line parameters for(n = 1; n <= argc - 1; n++) { if(! memcmp(argv[n], "-h", 2)) { printf("Error"); exit(0); } else if(! memcmp(argv[n], "-v", 2)) Quiet = 0; else if(argv[n][0] == '-') { fprintf(stderr, "-- Parameter incorrect: '%s'.\n", argv[n]); exit(1); } else InputFileName = argv[n]; } if(InputFileName == NULL) { fprintf(stderr, "-- Must enter a file name.\n \" Use 'pclcount -h' to get help.\n"); exit(1); } // Try to open the input file if(! (InputFile = fopen(InputFileName, "r"))) { fprintf(stderr, "--Error opening file: %s\n", argv[1]); exit(-1); }; // Get the file size, to show statistics if '-v' is passed if(! Quiet) { fseek(InputFile, 0, SEEK_END); FileSize = ftell(InputFile); fseek(InputFile, 0, SEEK_SET); } while(fread(&ch, 1, 1, InputFile)) { switch(ch) { case 12: // Found FormFeed: increments page counter Pages ++; break; case 27: // Found fread(tag, 2, 1, InputFile); if(! (memcmp(tag, "*b", 2) && memcmp(tag, "(s", 2) && memcmp(tag, ")s", 2) && memcmp(tag, "&p", 2))) { /* Detect the operators: *b###W -> Start of Binary Block (s###W -> Start of Characters Description Block )s###W -> Start of Fonts Description Block &p###X -> Start of non-printable Characters Block In these operators, '###' is the size of respective block. */ // Define the block end-character EndTag = memcm

    D 1 Reply Last reply
    0
    • R raf sp

      The code below, would must to show the count the number of pages in a PCL file. But, don´t show. Why?? What is wrong?? //---------------------------------- #include "stdio.h" #include "stdlib.h" #include "string.h" int main (int argc, char **argv) { FILE *InputFile; char ch, EndTag, tag[2], *InputFileName; int n, BlockSize, Pages, Copies, Quiet; unsigned long FileSize, FilePos; BlockSize =0; Pages =0; FileSize =0; FilePos =0; Copies =0; Quiet =1; InputFileName = NULL; // Parse command line parameters for(n = 1; n <= argc - 1; n++) { if(! memcmp(argv[n], "-h", 2)) { printf("Error"); exit(0); } else if(! memcmp(argv[n], "-v", 2)) Quiet = 0; else if(argv[n][0] == '-') { fprintf(stderr, "-- Parameter incorrect: '%s'.\n", argv[n]); exit(1); } else InputFileName = argv[n]; } if(InputFileName == NULL) { fprintf(stderr, "-- Must enter a file name.\n \" Use 'pclcount -h' to get help.\n"); exit(1); } // Try to open the input file if(! (InputFile = fopen(InputFileName, "r"))) { fprintf(stderr, "--Error opening file: %s\n", argv[1]); exit(-1); }; // Get the file size, to show statistics if '-v' is passed if(! Quiet) { fseek(InputFile, 0, SEEK_END); FileSize = ftell(InputFile); fseek(InputFile, 0, SEEK_SET); } while(fread(&ch, 1, 1, InputFile)) { switch(ch) { case 12: // Found FormFeed: increments page counter Pages ++; break; case 27: // Found fread(tag, 2, 1, InputFile); if(! (memcmp(tag, "*b", 2) && memcmp(tag, "(s", 2) && memcmp(tag, ")s", 2) && memcmp(tag, "&p", 2))) { /* Detect the operators: *b###W -> Start of Binary Block (s###W -> Start of Characters Description Block )s###W -> Start of Fonts Description Block &p###X -> Start of non-printable Characters Block In these operators, '###' is the size of respective block. */ // Define the block end-character EndTag = memcm

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      raf-sp wrote: But, don´t show. Why?? What is wrong?? So what does it show? Is it off by one? Does the while loop not find any ASCII 12 characters? Remember that "page eject" in PCL can be any of the following commands: RESET (EcE) PAGE SIZE (Ec&l#A) PAGE LENGTH (Ec&l#P) ORIENTATION CHANGE (Ec&l#0) PAPER SOURCE CONTROL SEQUENCE (Ec&l0H) with a value of zero PAPER SOURCE (Ec&l#H)


      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      R 1 Reply Last reply
      0
      • D David Crow

        raf-sp wrote: But, don´t show. Why?? What is wrong?? So what does it show? Is it off by one? Does the while loop not find any ASCII 12 characters? Remember that "page eject" in PCL can be any of the following commands: RESET (EcE) PAGE SIZE (Ec&l#A) PAGE LENGTH (Ec&l#P) ORIENTATION CHANGE (Ec&l#0) PAPER SOURCE CONTROL SEQUENCE (Ec&l0H) with a value of zero PAPER SOURCE (Ec&l#H)


        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        R Offline
        R Offline
        raf sp
        wrote on last edited by
        #3

        This program should to show the number of pages a file it be printed in format HP-PCL. Does the while loop not find any ASCII 12 characters? No, no finds. raf-sp

        D 1 Reply Last reply
        0
        • R raf sp

          This program should to show the number of pages a file it be printed in format HP-PCL. Does the while loop not find any ASCII 12 characters? No, no finds. raf-sp

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          How about using fopen(InputFileName, "r**b**") instead?


          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          R 1 Reply Last reply
          0
          • D David Crow

            How about using fopen(InputFileName, "r**b**") instead?


            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            R Offline
            R Offline
            raf sp
            wrote on last edited by
            #5

            I tried but, did not function. Thank you! raf-sp

            D 1 Reply Last reply
            0
            • R raf sp

              I tried but, did not function. Thank you! raf-sp

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              If you could provide me with a link to a .pcl file, I can provide you with a code snippet to do what you require. - DC


              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              R 1 Reply Last reply
              0
              • D David Crow

                If you could provide me with a link to a .pcl file, I can provide you with a code snippet to do what you require. - DC


                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                R Offline
                R Offline
                raf sp
                wrote on last edited by
                #7

                Ok, Thank´s!! I write a text file in "Notepad" and send to print to file in a PCL5 Printer Driver. Then, I execute the program for count pages pcl and it does not work.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups