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

docling doesn't see images in some docx files #674

Open
ilushenka opened this issue Jan 4, 2025 · 0 comments
Open

docling doesn't see images in some docx files #674

ilushenka opened this issue Jan 4, 2025 · 0 comments
Assignees
Labels
bug Something isn't working docx issue related to docx backend

Comments

@ilushenka
Copy link

Bug

I tried to take images from docx using docling but I found that in some files he did not see images and I don't know why.
...
My code(there are methods in my class):

    def _docling_parse(self):
        pipeline_options = PdfPipelineOptions()
        pipeline_options.images_scale = IMAGE_RESOLUTION_SCALE
        pipeline_options.generate_picture_images = True
        pipeline_options.generate_page_images = True

        return DocumentConverter(
                    format_options={
                        InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)
                    }
                )

    def _get_images(self, output_dir, document):
        res = []
        picture_counter = 0
        images_dir = output_dir / 'images'
        images_dir.mkdir(parents=True, exist_ok=True)
        for element, _level in document.iterate_items():
            if isinstance(element, PictureItem):
                picture_counter += 1
                element_image_filename = (
                    images_dir / f"{picture_counter}.png"
                )
                res.append(Path('images/') / f'{picture_counter}.png')
                with element_image_filename.open("wb") as fp:
                    element.get_image(document).save(fp, "PNG")
        return res
   def docx_parse(self, file_path, output_path='./'):

        input_doc_path = Path(file_path)
        output_dir = Path(output_path) / f"parsed_{input_doc_path.name}"

        doc_converter = self._docling_parse()
        conv_res = doc_converter.convert(input_doc_path)

        output_dir.mkdir(parents=True, exist_ok=True)

        images_list = self._get_images(output_dir, conv_res.document)

File that has incorrect conversion

5.3.docx

@ilushenka ilushenka added the bug Something isn't working label Jan 4, 2025
@cau-git cau-git added the docx issue related to docx backend label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docx issue related to docx backend
Projects
None yet
Development

No branches or pull requests

3 participants