Converting pdf to images gives squares in text areas of the converted image
I'm trying to convert pdf to image using the following code, but the conversion is working fine but for each element in the pdf it gives a square over the element like for each text area there is a square from io import BytesIO import PyPDF2 from pdf2image import convert_from_bytes # Assuming "file" is an InMemoryUploadedFile object containing the PDF content # Read the PDF content from the InMemoryUploadedFile pdf_content = file.read() # Create a BytesIO object to handle the PDF content pdf_stream = BytesIO(pdf_content) # Use PyPDF2 to get the number of pages in the PDF (optional step) pdf_reader = PyPDF2.PdfFileReader(pdf_stream) num_pages = pdf_reader.numPages # Convert the PDF content to images using pdf2image images = convert_from_bytes(pdf_content, poppler_path=r"C:\Python\poppler\poppler-23.07.0\Library\bin") # Save each image for i, pdf in enumerate(images): # Save pages as images in the pdf pdf.save(f'PDF\image_mods\image_converted_{i + 1}.png', 'PNG' )
I'm trying to convert pdf to image using the following code, but the conversion is working fine but for each element in the pdf it gives a square over the element like for each text area there is a square
from io import BytesIO
import PyPDF2
from pdf2image import convert_from_bytes
# Assuming "file" is an InMemoryUploadedFile object containing the PDF content
# Read the PDF content from the InMemoryUploadedFile
pdf_content = file.read()
# Create a BytesIO object to handle the PDF content
pdf_stream = BytesIO(pdf_content)
# Use PyPDF2 to get the number of pages in the PDF (optional step)
pdf_reader = PyPDF2.PdfFileReader(pdf_stream)
num_pages = pdf_reader.numPages
# Convert the PDF content to images using pdf2image
images = convert_from_bytes(pdf_content, poppler_path=r"C:\Python\poppler\poppler-23.07.0\Library\bin")
# Save each image
for i, pdf in enumerate(images):
# Save pages as images in the pdf
pdf.save(f'PDF\image_mods\image_converted_{i + 1}.png', 'PNG'
)