Replies: 15 comments 7 replies
-
I recommend to use the new Page method insert_htmlbox. So - if you know elementary HTML / CSS syntax - you can change font, color, boldness etc. in one single string that you pass as a parameter. And you can stop worrying about whether your content will fit: |
Beta Was this translation helpful? Give feedback.
-
File "F:/pycharm2020.2/RapidStructure-0.0.0/OnnxDetRec_pdf_writeOcrtxtLine_html20240110.py", line 923, in convert_pdf_to_ppt Any sample code to replace TextWriter? tw.write_text(page, opacity=None, color=color, morph=(pos, mat), overlay=True, oc=0, render_mode=0)
|
Beta Was this translation helpful? Give feedback.
-
but there is below error when try to use it. page = doc[i] page.insert_htmlbox(rect, text, css="* {font-family: sans-serif;font-size:14px;}") |
Beta Was this translation helpful? Give feedback.
-
Still same error after import fitz_new
AttributeError: 'Page' object has no attribute 'insert_htmlbox' |
Beta Was this translation helpful? Give feedback.
-
Still same error after import fitz_new
AttributeError: 'Page' object has no attribute 'insert_htmlbox' |
Beta Was this translation helpful? Give feedback.
-
PyMuPDF 1.20.2 |
Beta Was this translation helpful? Give feedback.
-
ダイス molding - Google 搜索_overlay.pdf
|
Beta Was this translation helpful? Give feedback.
-
Thank you. Will play once I have time. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
when try to use this method, the result is not correct. textwidth = fitz.get_text_length(text, fontsize=fontsize)
|
Beta Was this translation helpful? Give feedback.
-
Is it possible to support htm canvas/javascript when using insert_htmlbox? Example effect? It is blank when I try to insert text with below code. '''
''' |
Beta Was this translation helpful? Give feedback.
-
No, javascript is not supported, only HTML (v4) and CSS (v2) syntax. To go into more detail, please read chapter 16 about Story of the free book Mupdf Explored.
import fitz
rect = fitz.Rect(100, 100, 400, 300)
text = """Lorem ipsum dolor sit amet, consectetur adipisici elit, sed
eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation <b>ullamco <i>laboris</i></b>
nisi ut aliquid ex ea commodi consequat. Quis aute iure
<div style="color: red;background-color: yellow;">reprehenderit</div>
in <span style="color: green;font-weight:bold;">voluptate</span> velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat
cupiditat non proident, sunt in culpa qui
<a href="https://www.artifex.com">officia</a> deserunt mollit anim id
est laborum."""
doc = fitz.Document()
page = doc.new_page()
page.insert_htmlbox(rect, text, css="* {font-family: sans-serif;font-size:14px;}")
doc.ez_save(__file__.replace(".py", ".pdf"))
Don't understand. This code import fitz
rect = fitz.Rect(100, 250, 300, 350)
text = """<img src="nur-ruhig.jpg">"""
doc = fitz.open()
page = doc.new_page()
page.insert_htmlbox(rect, text, archive=fitz.Archive("."), opacity=0.5, rotate=90)
page.draw_rect(rect, color=(1, 0, 0))
doc.save(__file__.replace(".py", ".pdf")) Produces this page: >>> page.get_images()
[(6, 0, 439, 501, 8, 'DeviceRGB', '', 'Img3', 'DCTDecode')]
>>> pprint(page.get_image_rects(6,transform=True))
[(Rect(101.0, 251.0, 212.84054565429688, 349.0),
Matrix(0.0, -98.0, 111.84054565429688, 0.0, 101.0, 349.0))]
No there is not .. yet. |
Beta Was this translation helpful? Give feedback.
-
Attached a file with Adobe OCR layer. |
Beta Was this translation helpful? Give feedback.
-
Is there any external python method to calculate proper font size for html rectganle shape so as to realize autofit in pymupdf through insert_htmlbox? |
Beta Was this translation helpful? Give feedback.
-
ok |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How to fill text in a rectangle shape without defiing font size?
Beta Was this translation helpful? Give feedback.
All reactions