Home > Net >  How can I converting multi page PDF file to many images .jpeg with Vips in C ?
How can I converting multi page PDF file to many images .jpeg with Vips in C ?

Time:07-16

I'am trying using vips in c to read a .PDF and convert to .jpeg files. The problem is that the code save all the pages in a single file .jpeg. How can i save in many .jpeg files?

My Code

    VOption *voptions = new VOption();
    voptions->set("dpi",150);
    voptions->set("page", 0);
    voptions->set("n", -1);

    VImage in = VImage().pdfload("/Users/gui/Desktop/PDF_Reader/files/TEST_DOC_READER.pdf",voptions);

    in.write_to_file("/Users/MyUser/Desktop/PDF_Reader/outputs/*.jpeg");

CodePudding user response:

I found a way to solve this using crop.

    VImage in = VImage().pdfload("/Users/MyUser/Desktop/PDF_Reader/files/TEST_DOC_READER.pdf", voptions);
    pages = in.get_int("n-pages");
    h = in.height()/pages;

    for(int i=0; i<pages; i  ){
        in.crop(0,i*h, in.width(), h).jpegsave((outdir to_string(i) format).c_str());
    }
  • Related