from borb.pdf import Document
from borb.pdf import Page
from borb.pdf import Paragraph
from borb.pdf import Run
pdf_text = """
Long text here
divided in various sections
"""
# Create a PDF document
document = Document()
# Split resume text into sections
sections = pdf_text.split("\n\n")
# Iterate over sections and add them to the PDF document
for section in sections:
paragraph = Paragraph()
runs = [Run(text=section)]
paragraph.add(*runs)
page = Page()
page.add(paragraph)
document.add(page)
# Save the PDF document to a file
document.save("updated.pdf")
In the above code I'm trying to insert text into pdf using borb
ImportError Traceback (most recent call last)
<ipython-input-19-d90b0d6013d2> in <cell line: 8>()
6 from borb.pdf import Paragraph
7 #from borb.pdf.text.run import Run
----> 8 from borb.pdf import Run
9 #from borb.pdf.text.run import run
10
ImportError: cannot import name 'Run' from 'borb.pdf' (/usr/local/lib/python3.10/dist-packages/borb/pdf/__init__.py)
But I'm getting the above error, is 'Run' function deprecated ? and How to solve above error ? Thanks.
disclaimer: I am the author of the borb
library.
You are (most likely) trying to run some code that was generated by chatGPT (or similar). I know (from experience) that it will try to invent new classes that simply don't exist in borb
.
Recently even, I did an experiment where I fed chatGPT the entire README.md
of borb
to see if it could answer a simple query. And it failed. And in one of these tests, it also used a non-existent class Run
.
I would suggest you read the documentation. It's very comprehensive, and easy to follow along. You don't need an AI to write the code for you.