Skip to content

PDF display prototype #78

@Compro-Prasad

Description

@Compro-Prasad

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

  1. There are three sets of APIs available for poppler (as given here):
    a. CPP
    b. Glib
    c. qt5
  2. The test I have done is using poppler-cpp. So, make sure it(libraries and headers) is installed on your system.
  3. Since it is in C++, you need to have a C++ compiler installed. I would be using g++ for this example.
  4. Finding and linking specific libraries and headers manually is a hard task. I will be using pkg-config to get that information.
  5. 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;
}
  1. Compile it using the following command:
g++ `pkg-config --cflags --libs poppler-cpp` x.cpp
  1. When running the executable, give two arguments:
./a.out ~/Downloads/pdf/resume.pdf test2.png

While 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions