Need help in aligning Image in PDF header using page.insert_htmlbox() method #3390
-
I'm encountering an issue with Here's the HTML snippet I'm using: <div style="font-family: arial, helvetica, sans-serif; font-size: 13px;">
<div style="font-family: arial, helvetica,
sans-serif; font-size: 13px;">
<div style="font-family: arial, helvetica, sans-serif; font-size: 13px;">
<div style="font-family: arial, helvetica, sans-serif; font-size: 13px;"><img style="display: block;
margin-left: auto; margin-right: auto;"
src="<--base64 data-->"
alt="\" width="100" height="101">
</div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 13px; text-align: center;">
<strong>tagline</strong>
</div>
</div>
</div>
</div> In Python, I'm attempting to adjust the page dimensions and insert the HTML: doc = fitz.open(pdfpath)
h_height = 100 # Just a placeholder height for testing
for page in doc:
prect = page.rect
myrect = fitz.Rect(0, 0, prect.width, h_height)
page.set_mediabox(fitz.Rect(0, 0, prect.width, prect.height + h_height))
page.insert_htmlbox(myrect, text=header_html) Despite specifying center alignment for the image, it remains aligned to the left. Any insights on how to resolve this issue would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This works as you seem to intend: html = """<div style="text-align:center;"><img src="image2.jpg" height=100><br>tagline</div>"""
arch = fitz.Archive(".")
rect = fitz.Rect(100, 100, 500, 400)
doc = fitz.open()
page = doc.new_page()
page.insert_htmlbox(rect, html, archive=arch)
page.draw_rect(rect, color=(1, 0, 0))
doc.ez_save(__file__.replace(".py", ".pdf")) BTW I am amazed that you were successful using embedded image data. The documentation clearly says, that this is not supported ... only external images are. |
Beta Was this translation helpful? Give feedback.
This works as you seem to intend:
BTW I am amazed that you were successful using embedded image data. The documentation clearly says, that this is not supported ... only external images are.