-
Notifications
You must be signed in to change notification settings - Fork 36
Open
Description
No step by step guide available
I was looking for Getting Started with Poppler and wasted a lot of time in not looking into the actual documentation itself. The problem is that there is hardly any step by step guide to get started with poppler.
What is poppler?
For people not aware of Poppler; Poppler is basically a very common library I have seen while installing packages in Linux. I hardly had any idea of what it was until I saw that many apps use poppler to display PDFs.
Getting started
- There are three sets of APIs available for poppler (as given here):
a. CPP
b. Glib
c. qt5 - The test I have done is using
poppler-cpp. So, make sure it(libraries and headers) is installed on your system. - Since it is in C++, you need to have a C++ compiler installed. I would be using
g++for this example. - Finding and linking specific libraries and headers manually is a hard task. I will be using
pkg-configto get that information. - The program:
#include <poppler/cpp/poppler-document.h>
#include <poppler/cpp/poppler-image.h>
#include <poppler/cpp/poppler-page-renderer.h>
int main(int argc, char **argv) {
// argv[1] should have the file you want to read from
poppler::document *d = poppler::document::load_from_file(argv[1]);
// This creates the first page in the memory
poppler::page *p = d->create_page(0);
// This will create an image off the first page in memory of 200xDPI and 200yDPI
// You can get further documentation online
poppler::page_renderer pr;
poppler::image img = pr.render_page(p, 200, 200);
// This will save the image from memory to a file
img.save(argv[2], "png");
// This will free up the memory
delete d;
return 0;
}- Compile it using the following command:
g++ `pkg-config --cflags --libs poppler-cpp` x.cpp- When running the executable, give two arguments:
./a.out ~/Downloads/pdf/resume.pdf test2.pngWhile working on this I will be updating about this issue in the comments. If you want you can start a PR since it might take time for me to put up a proper version. I will try my best though.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels