[poppler] API: Help getting PDF page into pixbuf

Angus March angus at uducat.com
Fri May 1 12:19:18 PDT 2009


Dominic Lachowicz wrote:
> Maybe you could post your code somewhere, like a pastebin. Have you
> called g_type_init() at the beginning of your program?
>   

    No. Looking it up I see that the function is deprecated--they don't
say what I should be using instead.
    But now that I have used it, I've gotten past the seg fault, and
into another problem. I did like you said, and saved the file as png,
but the image quality is horrible. Using a test PDF, Adobe Acrobat
Professional saves it as jpegs with about 1500 pixels width, while the
PNG rendered by Poppler is half that. Not only that, gradients have
these dark lines running across them, and this page that is supposed to
have a white background has a transparent background. If I did this
using your pseudocode, what should I be doing?

> On Fri, May 1, 2009 at 12:39 PM, Angus March <angus at uducat.com> wrote:
>   
>> I might need some more help, though. I tried getting the PDF from a file
>> using:
>>    GError *error = NULL;
>>    PopplerDocument *pDoc = poppler_document_new_from_file(sPath, NULL,
>> &error);
>>
>> Valgrind reports that the segmentation fault was in
>> poppler_document_new_from_file() in the form of:
>> Invalid write of size 8
>> at 0x71D4DC8: (within /usr/lib64/libpoppler-glib.so.4.0.0)
>> ...
>> Address 0x18 is not stack'd, malloc'd or (recently) free'd
>>
>> Address 0x18, eh? That doesn't seem like a likely memory address.
>>    This was the first call to anything Poppler in that app.
>>
>>
>> Dominic Lachowicz wrote:
>>     
>>> You can render PopplerPage objects to any Cairo surface, including
>>> image surfaces. Here's some pseudo-code that should get you in the
>>> right direction:
>>>
>>> page = poppler_document_get_page();
>>> width, height = poppler_page_get_size(page);
>>> surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
>>> cairo = cairo_create(surface);
>>> poppler_page_render(page, cairo);
>>>
>>> // do what you want with the image surface, such as write it to disk
>>> cairo_surface_write_to_png(surface, "/home/angus/page0.png");
>>>
>>> cairo_destroy(cairo);
>>> cairo_surface_destroy(surface);
>>>
>>> http://www.cairographics.org/manual/
>>>
>>> On Thu, Apr 30, 2009 at 2:51 PM, Angus March <angus at uducat.com> wrote:
>>>
>>>       
>>>> I need to have a PDF as an image, but the API documentation is very
>>>> sparing with information, and I have some questions:
>>>>
>>>>   1. Do I use poppler_page_render_selection_to_pixbuf () to do this?
>>>>   2. Assuming 1. is true, do I get page from
>>>>      poppler_document_new_from_file(), and the PopplerDocument instance
>>>>      from poppler_document_new_from_file()?
>>>>   3. How do I interpret the data in pixbuf, or is that for another manual?
>>>>   4. Can selection be made from the data returned by
>>>>      poppler_page_get_size()?
>>>>   5. What's a "Poppler selection style" and what difference does it
>>>>      make for this function?
>>>>   6. I don't know what glyph_color and background_color should be.
>>>>      Isn't that sort of thing native to the PDF document?
>>>>
>>>> _______________________________________________
>>>> poppler mailing list
>>>> poppler at lists.freedesktop.org
>>>> http://lists.freedesktop.org/mailman/listinfo/poppler
>>>>
>>>>
>>>>         
>>>
>>>
>>>       
>>     
>
>
>
>   



More information about the poppler mailing list