Is it possible to extract color of text segment?
just like:
{
bbox,
text,
font,
// add color here
color,
}
Not right now, I think we would need to add a color parameter to the StructuredText walk method (https://mupdfjs.readthedocs.io/en/latest/classes/StructuredText.html#walk). I think this may be possible to do, but I will refer to @ccxvii for feasibility here.
awe!
-
Actually I have completed a color Structured version based on
pdf.js. But there are some issues with missing colors, invisible characters, textItem not in the same order as the command, not sure if you will occur the same problem about it, it's really a difficult job 🤣 -
then I have another question about text bolding that I hope you can answer. The whole line is bolded
const document = Document.openDocument(arrayBuffer, './AlphaZero-like tree-search canuide LLM decoding and training 5.pdf')
const page = document.loadPage(0)
console.log('doc', JSON.parse(page.toStructuredText().asJSON()))
Hmmmm, this is wrong, it would be better obviously if the text object had inline styling markup - we should look further into this.
What happens if you do page.toStructuredText().asHTML() do you get the kind of markup around the text that you might expect?
Yes, asHTML() get the correct style, but I need the data in JSON format more than HTML
<p style="top:538.2pt;left:307.1pt;line-height:10.1pt">
<b><span style="font-family:NimbusRomNo9L,serif;font-size:10.1pt">Task Setups</span></b>
<span style="font-family:NimbusRomNo9L,serif;font-size:10.1pt"> For a given MDP, the nature of the search</span>
</p>
I found another options to solve this:
page.toStructuredText('preserve-spans').asJSON()
Sure - but I still think that we need to add something to the API to return the font color info.
Yes, that'll be great! lft 👀
@jamie-lemon You should handle color in onChar query for text walker because inline can be different color for each char. I collecting different spans follow to font + color props.
https://github.com/ArtifexSoftware/mupdf.js/blob/master/src/mupdf.ts#L1402