You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to disable font ligatures in insert_htmlbox method #4981
I would like to disable font ligatures when creating a page using insert_htmlbox method.
I tried creating the following css to disable the same but it had no effect
body {
font-family:'Calibri';
font-size:12pt;
font-feature-settings:"liga"0,"calt"0!important;
font-variant-ligatures: none !important;
}
Image
If you notice the image below in the word "Introduction" the letters "ti" as compressed into one
Impact
If a user tries to copy the word from the PDF and pastes it into another app it becomes "Introducon" (Notice that the characters "ti" are dropped here.
This also affecting the search_for() function, when i pass "Introduction" as the parameter i.e. page.search_for("Introduction") it is unable to find the same
How to reproduce the bug
Create a pdf using insert_htmlbox method with Calibri font with content as "Introduction"
Parsing the HTML and CSS syntax in the text and the css parameters is done by our base library MuPDF. As documented, not the full respective syntaxes are covered by this parsing. So you will always find unsupported language expressions.
PyMuPDF has no way of influencing this. All you can do is contacting the MuPDF team in this Discord channel.
However: Even when your request would be implemented, it would not solve your problem, because "ti" is no official ligature. There exists no Unicode definition for it.
The problem is caused by the font itself.
Text searching in PyMuPDF has no problem with ligatures: they will be automatically decomposed, letting you successfully find e.g. "fi" - whether present as separate characters or as ligature "fi".
I reproduced your observation with this snippet:
You can of course use page.insert_textbox() - this is a character-based output method and thus avoids the use of Harfbuzz. The result will be as you expect it.
I have a page (table of contents page) created using the insert_htmlbox method and the rest of the contents of the pdf come from merging several other PDFs
I would like to create links (preferably with <a> tag) to other pages.. I tried the following
You could give up using .insert_htmlbox() altogether and use the Story object directly. The HTMLBOX method also makes use of it under the hood.
If you use Story then you can let it create TOCs automatically. It also takes care of fitting content to page rectangles and much more. This would free you from above pesky problems.
Using Story basically means that you prepare the complete content in one string, including require HTML / CSS styling, tables, and potential images to be embedded. Then use one of the Story methods to create the PDF output.
Definitely @JorjMcKie I am currently thinking, if there is a way i can define the internal address in the href attribute of the <a> tag. The href attribute should specify both the "page number" and the "y" location in the page so that when the user clicks the link in the first page it goes to the "exact" location.
Activity
JorjMcKie commentedon May 3, 2026
Parsing the HTML and CSS syntax in the text and the css parameters is done by our base library MuPDF. As documented, not the full respective syntaxes are covered by this parsing. So you will always find unsupported language expressions.
PyMuPDF has no way of influencing this. All you can do is contacting the MuPDF team in this Discord channel.
However: Even when your request would be implemented, it would not solve your problem, because "ti" is no official ligature. There exists no Unicode definition for it.
The problem is caused by the font itself.
Text searching in PyMuPDF has no problem with ligatures: they will be automatically decomposed, letting you successfully find e.g. "fi" - whether present as separate characters or as ligature "fi".
I reproduced your observation with this snippet:
The output:
IAW: the font contains no backtranslation information for this pseudo-ligature.
My recommendation: Use a different font!
JorjMcKie commentedon May 4, 2026
You can of course use
page.insert_textbox()- this is a character-based output method and thus avoids the use of Harfbuzz. The result will be as you expect it.kishaningithub commentedon May 4, 2026
@JorjMcKie My usecase is the following
I have a page (table of contents page) created using the
insert_htmlboxmethod and the rest of the contents of the pdf come from merging several other PDFsI would like to create links (preferably with
<a>tag) to other pages.. I tried the followingbut the above did not works as expected because
search_forwas not detecting the strings like "Introduction"Any pointers would be much appreciated.
JorjMcKie commentedon May 4, 2026
You could give up using
.insert_htmlbox()altogether and use theStoryobject directly. The HTMLBOX method also makes use of it under the hood.If you use
Storythen you can let it create TOCs automatically. It also takes care of fitting content to page rectangles and much more. This would free you from above pesky problems.Using Story basically means that you prepare the complete content in one string, including require HTML / CSS styling, tables, and potential images to be embedded. Then use one of the Story methods to create the PDF output.
JorjMcKie commentedon May 4, 2026
BTW - You are aware of Calibri license restrictions that may apply to you? This is not a free font.
kishaningithub commentedon May 4, 2026
@JorjMcKie How to solve the linking problem using the Story object? Could not get that working. Any pointers to examples would be great..
JorjMcKie commentedon May 4, 2026
Use a method like this one to get a a PDF Document object in which the links contained in your source text have been correctly resolved.
JorjMcKie commentedon May 5, 2026
Let me know how you get on with this!
kishaningithub commentedon May 5, 2026
Definitely @JorjMcKie I am currently thinking, if there is a way i can define the internal address in the
hrefattribute of the<a>tag. Thehrefattribute should specify both the "page number" and the "y" location in the page so that when the user clicks the link in the first page it goes to the "exact" location.JorjMcKie commentedon May 5, 2026
Let's move this to the Discussions tab first.