unstructured: Image extract to payload is not giving base64 metadata

Describe the bug I want to extract the image in base64 format for the pdf elements. Apparently, I am able to extract only the compositeElement and Table as the elements. The metadata of Table as base64 image string, but there is no such base64 string for the images that were present.

raw_pdf_elements = partition_pdf(
    filename=path+file_name,
    extract_images_in_pdf= True,
    chunking_strategy="by_title",
    max_characters=2000, # chunk into n chars 
    new_after_n_chars=1800, #cut off chunks after this many chars
    combine_text_under_n_chars=1000, # combine chars under "title" to reach 2000 if <2000
    extract_image_block_types=["Image", "Table"],   
    extract_image_block_to_payload=True
)

when I do

for element in raw_pdf_elements: 
   print(element.category)
   print(element.metadata.to_dict())

Only table elements have base64 image str as metadata

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (8 by maintainers)

Most upvoted comments

@AlokRanjanSwain remove chunking_strategy=“by_title” and it’ll work. I think it merges other elements when creating the chunks and converts it to CompositeElement hence losing the metadata.

@christinestraub can you explain a bit more on why this happens? Also, if there any way to retrieve images as base64 while providing the chunk_strategy as “by_title”

@christinestraub , This is the pdf I was trying to extract Link

@AlokRanjanSwain remove chunking_strategy=“by_title” and it’ll work. I think it merges other elements when creating the chunks and converts it to CompositeElement hence losing the metadata.