LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-08-2011, 05:23 AM   #1
surwassu
LQ Newbie
 
Registered: May 2011
Posts: 18

Rep: Reputation: Disabled
Read contents of PDF file


Hi guys,
I am searching for a API which will help me to print pdf file.Is there any way?
or is there any API to read content of PDF file & store it in buffer??
Please help me guys.
 
Old 06-08-2011, 05:28 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
What language are you using? From the word "buffer", C/C++ suggests itself to me... In which case you probably want to be looking at using CUPS API
 
Old 06-08-2011, 05:31 AM   #3
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,363

Rep: Reputation: 135Reputation: 135
You can use pdf2txt utility to and store the content in the textfile and read from that.
 
1 members found this post helpful.
Old 06-08-2011, 05:36 AM   #4
surwassu
LQ Newbie
 
Registered: May 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Snark1994 View Post
What language are you using? From the word "buffer", C/C++ suggests itself to me... In which case you probably want to be looking at using CUPS API
thanks for reply...
I am using unix & I want to write a script which will print pdf file.Otherwise read the contents from pdf file stored in textfile coz printing with text file is working properly. Is there any way?I searched CUPS Doc ,but can't got any thing.Do U know ???
Regards,
Sumit
 
Old 06-08-2011, 05:39 AM   #5
surwassu
LQ Newbie
 
Registered: May 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by divyashree View Post
You can use pdf2txt utility to and store the content in the textfile and read from that.
Thanks for reply.
I am writing a script so this command can't help me .Do you know any cups API for this??
Thanks regards,
Sumit
 
Old 06-08-2011, 06:01 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
What do you want to do Sumit? Use a (shell?) script to print a PDF via CUPS?

If so, the words API and buffer are not applicable because shell scripts:
  • Mostly use commands, the same ones you can use at a command prompt, not API's.
  • Don't provde buffers although they can use variables and pipelines to do a similar job. EDIT: and files so you could use something like pdf2txt which probably can write down a pipeline in which case the intermediate file would not be required.

Last edited by catkin; 06-08-2011 at 06:03 AM.
 
Old 06-08-2011, 06:16 AM   #7
surwassu
LQ Newbie
 
Registered: May 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by catkin View Post
What do you want to do Sumit? Use a (shell?) script to print a PDF via CUPS?

If so, the words API and buffer are not applicable because shell scripts:
  • Mostly use commands, the same ones you can use at a command prompt, not API's.
  • Don't provde buffers although they can use variables and pipelines to do a similar job. EDIT: and files so you could use something like pdf2txt which probably can write down a pipeline in which case the intermediate file would not be required.
I have gone through print commands I know it can be done much easier way ,But we are developing a code for printing a pdf file ,[Requriement: CUPS Programming ].
Do you have any idea about CUPs API for reading PDF file data .

Thanks Regards,
Sumit
 
Old 06-08-2011, 07:57 AM   #8
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Quote:
Originally Posted by surwassu View Post
I have gone through print commands I know it can be done much easier way ,But we are developing a code for printing a pdf file ,[Requriement: CUPS Programming ].
Do you have any idea about CUPs API for reading PDF file data .

Thanks Regards,
Sumit
We're still not quite sure what you want to do.

Do you want to use a language like C/C++ ?

Or do you want to use a language like bash (ie. write a shell script) ?
 
Old 06-08-2011, 08:44 AM   #9
surwassu
LQ Newbie
 
Registered: May 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Snark1994 View Post
We're still not quite sure what you want to do.

Do you want to use a language like C/C++ ?

Or do you want to use a language like bash (ie. write a shell script) ?
hi,

Its a c++ lauguage.

thanks regards
Sumit
 
Old 06-08-2011, 11:15 AM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by surwassu View Post
hi,

Its a c++ lauguage.

thanks regards
Sumit
Then the conventionally it is not a script, it is a program. Wikipedia says about scripts: "Scripts are often interpreted from source code or bytecode, whereas the application is typically first compiled to native machine code".
 
1 members found this post helpful.
Old 06-09-2011, 04:44 AM   #11
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
In that case, I think you should look at links like these:

http://www.cups.org/documentation.php/api-overview.html
http://www.cups.org/documentation.php/api-cups.html
http://www.cups.org/doc-1.1/spm.html#3_2_2 *** this one especially, it has example code for printing a file:
Code:
#include <cups/cups.h>
int jobid = cupsPrintFile("printername", "filename", "titleOfPrintJob", 0, NULL);
You will obviously have to look through the rest of the documentation I've posted to be able to FIND the printers, etc. I haven't tested the code, either, it was provided in the documentation. But good luck I just searched for "c++ cups api tutorial", and related terms, in order to find those links.

Hope this helps,
 
1 members found this post helpful.
Old 06-09-2011, 05:27 AM   #12
surwassu
LQ Newbie
 
Registered: May 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Snark1994 View Post
In that case, I think you should look at links like these:

http://www.cups.org/documentation.php/api-overview.html
http://www.cups.org/documentation.php/api-cups.html
http://www.cups.org/doc-1.1/spm.html#3_2_2 *** this one especially, it has example code for printing a file:
Code:
#include <cups/cups.h>
int jobid = cupsPrintFile("printername", "filename", "titleOfPrintJob", 0, NULL);
You will obviously have to look through the rest of the documentation I've posted to be able to FIND the printers, etc. I haven't tested the code, either, it was provided in the documentation. But good luck I just searched for "c++ cups api tutorial", and related terms, in order to find those links.

Hope this helps,
Hi,
Thanks for reply its really appreciated u r investing time for problem ...
I have already searched these files ,but m not getting what i wanted,Do you know about pdftops filter how it is used ? any example?
Thanks Regards,
Sumit
 
Old 06-09-2011, 05:31 AM   #13
surwassu
LQ Newbie
 
Registered: May 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by divyashree View Post
You can use pdf2txt utility to and store the content in the textfile and read from that.
Hey ,
Do you know how to use this utility in c++?I want to write a code in CUPS.
I am able to convert file by using command line.
Do you know anything about pdftops filter?
Thanks regards,
Sumit
 
Old 06-10-2011, 05:00 AM   #14
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
When you talk about 'pdf2txt' and 'pdftops', you're talking about bash scripts NOT C++. If you want to craft a solution with bash, then that may well be easier, but it is definitely not C++.

Anyway, I have no printers on my system so I have no idea if this works (it compiles, and prints the correct output for me; "No printers found.")
Try it and see:

Code:
#include <stdio.h>
#include <cups/cups.h>

int main(void){
    int i;
    cups_dest_t *dests, *dest;
    int num_dests = cupsGetDests(&dests);
    char* file = "filename.pdf";

    for (i = num_dests, dest = dests; i > 0; i --, dest ++) {
        if (dest->instance) {
            printf("Trying to print to: %s/%s\n", dest->name, dest->instance);
        } else {
            printf("Trying to print to: %s\n",dest->name);
        }
        int jobid = cupsPrintFile(dest->name,file,"MyPdfPrintJob",0,NULL);
        if(jobid == 0){
            fprintf(stderr,"Error printing %s to %s\n",file,dest->name);
        } else {
            break;
        }
    }
    if(num_dests == 0) printf("No printers found.\n");
    return (0);
}
Compile with:
Code:
gcc printer.c -o printer `cups-config --cflags` `cups-config --libs` -Wall
Hope this helps,
 
Old 06-12-2011, 10:09 AM   #15
surwassu
LQ Newbie
 
Registered: May 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Snark1994 View Post
When you talk about 'pdf2txt' and 'pdftops', you're talking about bash scripts NOT C++. If you want to craft a solution with bash, then that may well be easier, but it is definitely not C++.

Anyway, I have no printers on my system so I have no idea if this works (it compiles, and prints the correct output for me; "No printers found.")
Try it and see:

Code:
#include <stdio.h>
#include <cups/cups.h>

int main(void){
    int i;
    cups_dest_t *dests, *dest;
    int num_dests = cupsGetDests(&dests);
    char* file = "filename.pdf";

    for (i = num_dests, dest = dests; i > 0; i --, dest ++) {
        if (dest->instance) {
            printf("Trying to print to: %s/%s\n", dest->name, dest->instance);
        } else {
            printf("Trying to print to: %s\n",dest->name);
        }
        int jobid = cupsPrintFile(dest->name,file,"MyPdfPrintJob",0,NULL);
        if(jobid == 0){
            fprintf(stderr,"Error printing %s to %s\n",file,dest->name);
        } else {
            break;
        }
    }
    if(num_dests == 0) printf("No printers found.\n");
    return (0);
}
Compile with:
Code:
gcc printer.c -o printer `cups-config --cflags` `cups-config --libs` -Wall
Hope this helps,

hi buddy,
Thanks for reply
I have already tried this code but it didn't work.it prints Nothing ,other case is ,When i give print command from command line to print pdf file ,It prints but the content is "Memory should be greater than 128Mb ".
Is there any way????what is problem ??The code is working fine for text and ps file.
Thanks & regards,
Sumit
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trying to read the contents of a file tarken Programming 8 01-11-2010 06:22 PM
How to extract a .exe file to read its contents BobNutfield Slackware 13 07-30-2008 08:07 PM
howto: pdf file renaming according to contents tacca Linux - Software 1 05-28-2007 02:40 PM
How to read and change the contents of a text file? Bassam Linux - General 11 02-26-2004 05:08 AM
Read contents of file and execute command cosiek Programming 3 09-30-2003 12:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:03 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration