pktpaulie commited on
Commit
7d4e1af
·
verified ·
1 Parent(s): 406be54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -12,7 +12,7 @@ import shutil
12
  import io
13
  from io import BytesIO
14
  import tempfile
15
- from PIL import Image
16
  import PyPDF2
17
  from docx2pdf import convert
18
  import docx
@@ -281,6 +281,29 @@ def save_docx_as_pdf1(input_path, output_path='output.pdf'):
281
  # save_docx_as_pdf(resume_path, 'uploaded_resume.pdf')
282
  # display_doc_as_image('uploaded_resume.pdf')
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  def display_pdf_page(pdf_path, page_number=1):
285
  with open(pdf_path, 'rb') as file:
286
  reader = PyPDF2.PdfReader(file)
 
12
  import io
13
  from io import BytesIO
14
  import tempfile
15
+ from PIL import Image, ImageDraw, ImageFont
16
  import PyPDF2
17
  from docx2pdf import convert
18
  import docx
 
281
  # save_docx_as_pdf(resume_path, 'uploaded_resume.pdf')
282
  # display_doc_as_image('uploaded_resume.pdf')
283
 
284
+ def display_pdf_page1(pdf_path):
285
+ try:
286
+ # Open PDF file
287
+ with open(pdf_path, 'rb') as file:
288
+ reader = PyPDF2.PdfReader(file)
289
+
290
+ # Extract text from the first page
291
+ page = reader.pages[0]
292
+ x_object = page.extract_text()
293
+
294
+ # Convert text to image (using PIL)
295
+ img = Image.new('RGB', (800, 1000))
296
+ draw = ImageDraw.Draw(img)
297
+ font = ImageFont.truetype("arial.ttf", 20)
298
+
299
+ # Draw text on the image
300
+ draw.text((10, 10), x_object[:500], fill=(255, 255, 255), font=font)
301
+
302
+ # Display the image
303
+ display(img)
304
+ except Exception as e:
305
+ st.error(f"Failed to display image: {str(e)}")
306
+
307
  def display_pdf_page(pdf_path, page_number=1):
308
  with open(pdf_path, 'rb') as file:
309
  reader = PyPDF2.PdfReader(file)