LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Read contents of PDF file (https://www.linuxquestions.org/questions/linux-newbie-8/read-contents-of-pdf-file-885147/)

surwassu 06-08-2011 04:23 AM

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.

Snark1994 06-08-2011 04:28 AM

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

divyashree 06-08-2011 04:31 AM

You can use pdf2txt utility to and store the content in the textfile and read from that.

surwassu 06-08-2011 04:36 AM

Quote:

Originally Posted by Snark1994 (Post 4379625)
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

surwassu 06-08-2011 04:39 AM

Quote:

Originally Posted by divyashree (Post 4379628)
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

catkin 06-08-2011 05:01 AM

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.

surwassu 06-08-2011 05:16 AM

Quote:

Originally Posted by catkin (Post 4379649)
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

Snark1994 06-08-2011 06:57 AM

Quote:

Originally Posted by surwassu (Post 4379662)
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) ?

surwassu 06-08-2011 07:44 AM

Quote:

Originally Posted by Snark1994 (Post 4379745)
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

catkin 06-08-2011 10:15 AM

Quote:

Originally Posted by surwassu (Post 4379799)
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".

Snark1994 06-09-2011 03:44 AM

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 :D I just searched for "c++ cups api tutorial", and related terms, in order to find those links.

Hope this helps,

surwassu 06-09-2011 04:27 AM

Quote:

Originally Posted by Snark1994 (Post 4380733)
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 :D 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

surwassu 06-09-2011 04:31 AM

Quote:

Originally Posted by divyashree (Post 4379628)
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

Snark1994 06-10-2011 04:00 AM

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,

surwassu 06-12-2011 09:09 AM

Quote:

Originally Posted by Snark1994 (Post 4381664)
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

surwassu 06-12-2011 09:20 AM

API for printing error
 
hi guys ,
i would like to know whether there is any API for displaying error in printing file.Its like printer is out of paper,tray is open .I am working on Linux machine,cups version is 1.4 .
plz help me guys.

regards,
sumit

Snark1994 06-13-2011 05:22 AM

Try to sort one problem at a time. You keep asking for different APIs, different tools, different languages. You say you can print from the command line with .txt and .ps files, but not .pdf files? Work out how to print .pdf files before you start asking about error APIs. If you can print .ps files, why not try:

Code:

$> pdftops myFile.pdf myFile.ps
And see if myFile.ps has converted correctly, then:

Code:

$> lpr myFile.ps
This might help you track down the 'memory' error. I assume you do have 128MB of RAM (I assume this is what the error is talking about - unless it is referring to the printer's internal memory...)

surwassu 06-13-2011 05:31 AM

Quote:

Originally Posted by Snark1994 (Post 4384012)
Try to sort one problem at a time. You keep asking for different APIs, different tools, different languages. You say you can print from the command line with .txt and .ps files, but not .pdf files? Work out how to print .pdf files before you start asking about error APIs. If you can print .ps files, why not try:

[CODE]$> pdftops myFile.pdf myFile.ps[/CODE}

And see if myFile.ps has converted correctly, then:

Code:

$> lpr myFile.ps

Hi buddy,
If u can see my previous post might notice that I tried this things and after that M getting error about memory ,I thinks that problem is related to printers own memory....


All times are GMT -5. The time now is 06:37 AM.