sumatrapdfreader / sumatrapdf

SumatraPDF reader
http://www.sumatrapdfreader.org
GNU General Public License v3.0
13.72k stars 1.73k forks source link

Can't translate with Google #4547

Open Mitia99 opened 1 month ago

Mitia99 commented 1 month ago

SumatraPDF version image

Describe the bug Translate with Google not working with this file when selecting all text on page 1. Character count limit isn't exceeded though.

To Reproduce Steps to reproduce the behavior:

  1. Select all text on Page 1
  2. Right click > Selection then Translate with Google

Nothing happens

image

Expected behavior Open web browser and translate text

File that reproduces the problem 5000_character_paragraph.pdf

Additional context Browser : Microsoft Edge latest stable version

Thanks for investigating,

GitHubRulesOK commented 1 month ago

Hmm that is a limitation of URLs they have a defined https:// working length, Best I can see is currently around 1500 characters.

@kjk is SumatraPDF limiting by a working buffer length ? I cannot see where a value is garnered for variables WCHAR buf[ INTERNET_MAX_URL_LENGTH + 16]{}; // +16 jic https://github.com/sumatrapdfreader/sumatrapdf/blob/3a708482bfaed25e21656829eb6529824f8aea8f/src/SumatraPDF.cpp#L4663

image

In theory perhaps 8000 but in practice much less and tainted by add-ons such as %20 for one space character.

Extremely long URLs are usually a mistake. URLs over 2,000 characters will not work in the most popular web browsers. Don't use them if you intend your site to work for the majority of Internet users. from http://stackoverflow.com/questions/417142/ddg#417184

So that method of send a string, is length limited by Windows shell and its current Browser, even if Google allows 5000 by pasting.

image

Google Translate can work with uploaded documents but SumatraPDF cannot upload files in that fashion. image

Potential solutions ?

SumatraPDF currently can export a page number to any external application / "shim" such as a CMD file. Then that CMD file can extract page or text or whole file to send to a Google API via curl.

However that shell customisation is outside of a normal Viewer/Readers remit.

What would help is if the selected text were sent to an external command file.