Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to extract color of text segment? #121

Open
luckymore opened this issue Dec 9, 2024 · 7 comments
Open

Is it possible to extract color of text segment? #121

luckymore opened this issue Dec 9, 2024 · 7 comments

Comments

@luckymore
Copy link

luckymore commented Dec 9, 2024

just like:

{
  bbox,
  text,
  font,
  // add color here
  color,
}
@jamie-lemon
Copy link
Collaborator

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.

@luckymore
Copy link
Author

awe!

  1. 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 🤣

  2. 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()))

image

@jamie-lemon
Copy link
Collaborator

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?

@luckymore
Copy link
Author

luckymore commented Dec 11, 2024

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>

@luckymore
Copy link
Author

I found another options to solve this:

page.toStructuredText('preserve-spans').asJSON()

@jamie-lemon
Copy link
Collaborator

Sure - but I still think that we need to add something to the API to return the font color info.

@luckymore
Copy link
Author

Yes, that'll be great! lft 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants