Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Reporting the byte location of images #161

Open
keto33 opened this issue Nov 3, 2023 · 2 comments
Open

[Suggestion] Reporting the byte location of images #161

keto33 opened this issue Nov 3, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@keto33
Copy link

keto33 commented Nov 3, 2023

I have tested many PDF-to-text programs, and this one is the most robust. However, handling images is always a question since they are heavy objects and usually unnecessary. If I am correct, starting from version 0.7, GROBID dropped the option of extracting images.

I suggest adding an option to save the byte location of image elements instead of saving the image to disk. In this case, we can later read the image directly from the PDF file whenever needed instead of storing all images on the disk.

Implementing this feature should be trivial since the location and length of the image objects are already known to pdfalto.

@kermitt2
Copy link
Owner

kermitt2 commented Nov 6, 2023

Thank you @keto33 !

In pdfalto, you can choose to extract and process images (embedded bitmap and vector graphics) or not with the argument -noImage.

Grobid can extract or not images (called "assets"):

Using the byte location in the PDF as alternative seems a good idea for pdfalto! This could be used then by Grobid for example. I don't know if it can be portable and how exactly doing it, I will look at it.

@kermitt2 kermitt2 added the enhancement New feature or request label Nov 6, 2023
@keto33
Copy link
Author

keto33 commented Nov 12, 2023

Thanks for your kind attention, @kermitt2 !

This actually should be done in xpdf rather than pdfalto itself. I am not a C++ expert, but I am a little bit familiar with xpdf, as I tweaked it for a project.

Since images are stored as stream objects in PDF, xpdf fetches and writes them by str = ((DCTStream *)str)->getRawStream(); line in ImageOutputDev.cc. Therefore, we need to add a new function of, say, getStreamBoundaries in Stream.cc to return the location/length of the object instead of its content.

I think the existing function of getStreamIndex defined in Parser.h does part of the job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants