pdf2htmlEX icon indicating copy to clipboard operation
pdf2htmlEX copied to clipboard

Thousands of useless spans

Open djvs opened this issue 12 years ago • 23 comments

After converting any of my sample PDFs to HTML, I notice the output is extremely cluttered with spans that seemingly have no effect at all - spans with class attributes "_ _ 0" seem to have no perceptible effect, spans with class "_ _ 1" seem to be replaceable with a space, and "_ _ d" perhaps with " &nbsp". (there is a space between the last two characters of each class attrib, because Github's markdown otherwise makes them italic).

Having a minimal number of elements in the output is vitally important for the project I'm working on - is there any way for me to tweak the CLI params for pdf2htmlEX to get simplified HTML? I am already invoking:

pdf2htmlEX --process-outline 0 --embed-css 0 --embed-font 0 --embed-javascript 0 --embed-image 0 --optimize-text 1 --space-threshold 0.4 --squeeze-wide-glyph 0 --stretch-narrow-glyph 1 (pdffile)

with no apparent changes.

djvs avatar May 10 '14 20:05 djvs

try a larger value for heps

coolwanglu avatar May 11 '14 05:05 coolwanglu

the higher i raise that, the more it breaks the visual formatting - we're trying to use this inside of an doc viewer which lets people use a highlighter JS plugin, which separates highlights element-by-element. the problem comes up when somebody wants to un-highlight an entire page of highlights, and has to click 150-300 times to do it.

couldn't this just use  ? maybe a CLI option to replace a range of --heps with a  ? i'd take anything here.

djvs avatar May 28 '14 03:05 djvs

--heps is already a fault tolerance for spaces. There reason that you see so many tags is because they are spaces of different widths, say 1cm, 2cm or 3cm etc. If a standard space is 2cm, and --heps is small, then only 2cm spaces will be replaced with a space character; when --heps is at least 1cm, all spaces between 1cm and 3cm will be replaced with a space character.

I don't have a better solution yet, can you propose one?

coolwanglu avatar Jun 06 '14 23:06 coolwanglu

[space], [space],  [space]...

djvs avatar Jun 06 '14 23:06 djvs

You mean to use multiple characters for a single space?

coolwanglu avatar Jun 06 '14 23:06 coolwanglu

better than [space]<span class="_ _1"></span> or whatever

djvs avatar Jun 06 '14 23:06 djvs

It was designed so to maintain correct text, whenever you select some text and copy them out, they will remain the same as in the PDF. Multiple characters will break it.

Also I'm not sure if this will actually help that much, suppose that each space char s 1cm, then 2-space-char will only help for 2cm spaces. How about 1.5cm space then?

Can you also provide a sample PDF file?

coolwanglu avatar Jun 06 '14 23:06 coolwanglu

Well, that is what CSS letter-spacing is for, no? Usually people don't type one and a half spaces. This issue came up with every PDF file I tried besides one generated directly from a txt file with unoconv (which was still one element per line). On Jun 6, 2014 7:57 PM, "Lu Wang" [email protected] wrote:

It was designed so to maintain correct text, whenever you select some text and copy them out, they will remain the same as in the PDF. Multiple characters will break it.

Also I'm not sure if this will actually help that much, suppose that each space is 1cm, then 2-space will only help for 2cm spaces. How about 1.5cm space then?

Can you also provide a sample PDF file?

— Reply to this email directly or view it on GitHub https://github.com/coolwanglu/pdf2htmlEX/issues/342#issuecomment-45395093 .

djvs avatar Jun 07 '14 00:06 djvs

letter-spacing has been considered already, which doesn't help a lot.

Usually people don't type one and a half spaces.

This is not true, for example LaTeX often take care of each single space to make it perfect.

coolwanglu avatar Jun 07 '14 00:06 coolwanglu

Sure, but in other contexts besides LaTeX, spacing is usually uniform for a text field, relative to character width. Shouldn't that be the default then? On Jun 6, 2014 8:03 PM, "Lu Wang" [email protected] wrote:

letter-spacing has been considered already, which doesn't help a lot.

Usually people don't type one and a half spaces. This is not true, for example LaTeX often take care of each single space http://coolwanglu.github.io/pdf2htmlEX/demo/demo.html to make it perfect.

— Reply to this email directly or view it on GitHub https://github.com/coolwanglu/pdf2htmlEX/issues/342#issuecomment-45395331 .

djvs avatar Jun 07 '14 00:06 djvs

So, can you provide some sample PDF files for analysis?

On Fri, Jun 6, 2014 at 5:08 PM, djvs [email protected] wrote:

Sure, but in other contexts besides LaTeX, spacing is usually uniform for a text field, relative to character width. Shouldn't that be the default then? On Jun 6, 2014 8:03 PM, "Lu Wang" [email protected] wrote:

letter-spacing has been considered already, which doesn't help a lot.

Usually people don't type one and a half spaces. This is not true, for example LaTeX often take care of each single space http://coolwanglu.github.io/pdf2htmlEX/demo/demo.html to make it perfect.

— Reply to this email directly or view it on GitHub < https://github.com/coolwanglu/pdf2htmlEX/issues/342#issuecomment-45395331>

.

— Reply to this email directly or view it on GitHub https://github.com/coolwanglu/pdf2htmlEX/issues/342#issuecomment-45395558 .

coolwanglu avatar Jun 07 '14 00:06 coolwanglu

Sure - the GNU Wget manual PDF is a good example:

http://www.gnu.org/software/wget/manual/wget.pdf

Converted with default options, there's a span between nearly every word.

I converted about 2400 PDFs with --heps 4, which took care of most of the verbosity problems, but after a point it breaks the formatting.

djvs avatar Jun 07 '14 00:06 djvs

This file seems to be produced by LaTeX. Try pdfinfo on it.

coolwanglu avatar Jun 07 '14 04:06 coolwanglu

I should probably stop using it for tests then, lol

djvs avatar Jun 07 '14 04:06 djvs

The main issue we're having is trying to load any of these into CKeditor for HTML editing. This is a feature we're trying to offer our users. The combination of absolute positioning, enforced page divs, highly specific elements etc.. as a whole makes this process totally impossible - as a result we're considering a split between pdf2htmlEX for display purposes, and pdftohtml/Acrobat HTML output for editing purposes. It'd be fantastic if we could resolve this only using pdf2htmlEX, but maybe that's not in the cards?

djvs avatar Jun 11 '14 15:06 djvs

I see. There were people doing the same thing AFAIK. The output of pdf2htmlEX was not designed to be easily edited, and I don't have a good solution for that without breaking the format.

There are on going work trying to minimize the number of elements while minimizing the change in format, but I don't have enough time to finish it.

coolwanglu avatar Jun 12 '14 10:06 coolwanglu

Do you have it as git stash or something? Honestly, I think most of the issue is that everything is absolutely positioned, versus defined in terms of margins, floats etc. (like in Acrobat's HTML output).

djvs avatar Jun 12 '14 14:06 djvs

No I'm afraid, it was a prototype and not finished.

coolwanglu avatar Jun 12 '14 18:06 coolwanglu

Hmm, i came across the same problem. i tried removing all the with _0, _1 and _2 ... formating didnt break much.

peterpisljar avatar Jun 25 '14 13:06 peterpisljar

the reson why this bothered me:

  • i feel the text pdf2htmlEX generates is really hard to read ( i am using external hint tool as suggested)
  • when playing arround with produced html i found out that removing this spans improves readability

here is a document describing the problem (on my google docs): https://docs.google.com/document/d/1VQ3NrSxOKoSinoy5lC2A_ziz8EdLEkAcWagxjjeTlxU/edit?usp=sharing

you can see comparison of pdf, generated html and generated html after spans were removed. formating didnt break, but the readability improves.

there is still however a problem with font-matching .... the generated fonts are much less readable than the ones in pdf (my feeling), however this doesnt belong in this post.

peterpisljar avatar Jun 25 '14 13:06 peterpisljar