# OCR to Add Text to File

**URL:** <https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439>\
**Category:** Applications\
**Created:** [July 20, 2022, 2:10pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439 "2022-07-20T14:10:48Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 20, 2022, 3:37pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/21 "2022-07-20T15:37:24Z")

</div>

> [@pycrk](#):
>
> by default jinja2 is not available. you need jinja2, don’t know why it’s not in the dependencies 🤷‍♂️

```auto
[limo@limo ~]$ yay -Syyu jinja2
:: Synchronizing package databases...
 core 156.8 KiB 266 KiB/s 00:01 [------------------------------------] 100%
 extra 1716.7 KiB 907 KiB/s 00:02 [------------------------------------] 100%
 community 6.7 MiB 1410 KiB/s 00:05 [------------------------------------] 100%
 multilib 170.9 KiB 247 KiB/s 00:01 [------------------------------------] 100%
 endeavouros 33.5 KiB 28.8 KiB/s 00:01 [------------------------------------] 100%
:: Starting full system upgrade...
 there is nothing to do
:: Searching databases for updates...
:: Searching AUR for updates...
 -> Could not find all required packages:
        jinja2 (Target)
[limo@limo ~]$ 

```

It is not in the repos?!  
Should I add a repo? how to?

UPDATE:

```auto
[limo@limo ~]$ pip install coloredlogs
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: coloredlogs in ./.local/lib/python3.10/site-packages (15.0.1)
Requirement already satisfied: humanfriendly>=9.1 in /usr/lib/python3.10/site-packages (from coloredlogs) (10.0)
[limo@limo ~]$ 

```

🤔

---

<div class="post-metadata">

**Author:** ![pycrk](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pycrk/32/71109_2.png) [@pycrk](https://forum.endeavouros.com/u/pycrk)\
**Post date:** [July 20, 2022, 3:46pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/22 "2022-07-20T15:46:50Z")

</div>

you should install pip, if don’t available on your system.

```auto
yay -S python-pip

```

and run the command

```auto
sudo pip install jinja2

```

that installs jinja2

---

<div class="post-metadata">

**Author:** ![2000](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/2/ee59a6/32.png) [@2000](https://forum.endeavouros.com/u/2000)\
**Post date:** [July 20, 2022, 3:51pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/23 "2022-07-20T15:51:36Z")

</div>

For reference:  
Once you’ve overcome your problems installing `ocrmypdf` and `tesseract-data-ara` (normally `yay -S ocrmypdf tesseract-data-ara --needed` should suffice), simply run

`ocrmypdf --output-type pdf -s -l ara input.pdf output.pdf`

to attach the arabic ocr data to the newly created `output.pdf`.  
Make sure the input.pdf has a high enough resolution; else your ocr results may be underwhelming.

* * *

To check which languages tesseract can access, run  
`tesseract --list-langs`

If you need other languages, [see here](https://archlinux.org/packages/?sort=&q=tesseract-data&maintainer=&flagged=); install with `sudo pacman -S <package-name>`

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 20, 2022, 3:51pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/24 "2022-07-20T15:51:53Z")

</div>

> [@pycrk](#):
>
> ```auto
> pip install jinja2
> 
> ```

```auto
[limo@limo ~]$ pip install jinja2
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: jinja2 in ./.local/lib/python3.10/site-packages (3.1.2)
Requirement already satisfied: MarkupSafe>=2.0 in ./.local/lib/python3.10/site-packages (from jinja2) (2.1.1)
[limo@limo ~]$ pip install jinja2
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: jinja2 in ./.local/lib/python3.10/site-packages (3.1.2)
Requirement already satisfied: MarkupSafe>=2.0 in ./.local/lib/python3.10/site-packages (from jinja2) (2.1.1)
[limo@limo ~]$ 

```

```auto
[limo@limo ~]$ pip install coloredlogs
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: coloredlogs in ./.local/lib/python3.10/site-packages (15.0.1)
Requirement already satisfied: humanfriendly>=9.1 in /usr/lib/python3.10/site-packages (from coloredlogs) (10.0)
[limo@limo ~]$ 

```

Still

```auto
    from sphinx.util.rst import append_epilog, docinfo_re, prepend_prolog
  File "/home/limo/.local/lib/python3.10/site-packages/sphinx/util/rst.py", line 22, in <module>
    from jinja2 import environmentfilter
ImportError: cannot import name 'environmentfilter' from 'jinja2' (/usr/lib/python3.10/site-packages/jinja2/ __init__.py)
==> ERROR: A failure occurred in build().
    Aborting...
 -> error making: python-coloredlogs
[limo@limo ~]$ 

```

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 20, 2022, 3:54pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/25 "2022-07-20T15:54:30Z")

</div>

> [@2000](#):
>
> to attach the arabic ocr data to the newly created `output.pdf`

Thank you @2000  
Amazing and wonderful community as usual.  
BUT I hope I can do without creating a new file!  
Would giving the target file same name as source do?

I already did

```auto
yay -Syyu tesseract-data-ara

```

---

<div class="post-metadata">

**Author:** ![pycrk](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pycrk/32/71109_2.png) [@pycrk](https://forum.endeavouros.com/u/pycrk)\
**Post date:** [July 20, 2022, 3:55pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/26 "2022-07-20T15:55:48Z")

</div>

try it with sudo, you need root permissions

```auto
sudo pip install jinja2

```

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 20, 2022, 3:57pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/27 "2022-07-20T15:57:04Z")

</div>

> [@pycrk](#):
>
> ```auto
> sudo pip install jinja2
> 
> ```

```auto
[limo@limo ~]$ sudo pip install jinja2

[sudo] password for limo: 
Requirement already satisfied: jinja2 in /usr/lib/python3.10/site-packages (3.1.2)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/lib/python3.10/site-packages (from jinja2) (2.1.1)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[limo@limo ~]$ 

```

Saying already satisfied!???  
My system has gone bananas!?

---

<div class="post-metadata">

**Author:** ![pycrk](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pycrk/32/71109_2.png) [@pycrk](https://forum.endeavouros.com/u/pycrk)\
**Post date:** [July 20, 2022, 4:00pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/28 "2022-07-20T16:00:07Z")

</div>

if you look in the folder

```auto
/usr/lib/python3.10/site-packages

```

do you find the jinja2 folder there?

---

<div class="post-metadata">

**Author:** ![dalto](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/dalto/32/5577_2.png) [@dalto](https://forum.endeavouros.com/u/dalto)\
**Post date:** [July 20, 2022, 4:01pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/29 "2022-07-20T16:01:22Z")

</div>

> [@pycrk](#):
>
> `sudo pip install jinja2`

Please stop. This is horrific advice.

**Never, ever use `sudo pip` on an Arch based system**

This is a direct path to broken updates.

---

<div class="post-metadata">

**Author:** ![pycrk](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/pycrk/32/71109_2.png) [@pycrk](https://forum.endeavouros.com/u/pycrk)\
**Post date:** [July 20, 2022, 4:01pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/30 "2022-07-20T16:01:57Z")

</div>

i tried the commands by me, my output is different and jinja2 folder is available:

```auto
[pycrk@ovoEnd ~]$ pip install jinja2
Defaulting to user installation because normal site-packages is not writeable
Collecting jinja2
  Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 kB 1.6 MB/s eta 0:00:00
Collecting MarkupSafe>=2.0
  Downloading MarkupSafe-2.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Installing collected packages: MarkupSafe, jinja2
Successfully installed MarkupSafe-2.1.1 jinja2-3.1.2
[pycrk@ovoEnd ~]$ sudo pip install jinja2
Collecting jinja2
  Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 kB 2.3 MB/s eta 0:00:00
Collecting MarkupSafe>=2.0
  Downloading MarkupSafe-2.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Installing collected packages: MarkupSafe, jinja2
Successfully installed MarkupSafe-2.1.1 jinja2-3.1.2
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv                                                                                                                                                             
[pycrk@ovoEnd ~]$              

```

---

<div class="post-metadata">

**Author:** ![2000](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/2/ee59a6/32.png) [@2000](https://forum.endeavouros.com/u/2000)\
**Post date:** [July 20, 2022, 4:02pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/31 "2022-07-20T16:02:34Z")

</div>

> [@limotux](#):
>
> Would giving the target file same name as source do?

Yes,

`ocrmypdf --output-type pdf -s -l ara input.pdf input.pdf`

would overwrite the original pdf.

---

<div class="post-metadata">

**Author:** ![dalto](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/dalto/32/5577_2.png) [@dalto](https://forum.endeavouros.com/u/dalto)\
**Post date:** [July 20, 2022, 4:03pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/32 "2022-07-20T16:03:45Z")

</div>

Are we sure that jinja2 being missing is even the issue?

I don’t have that installed and my build went fine.

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 20, 2022, 4:04pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/33 "2022-07-20T16:04:26Z")

</div>

> [@dalto](#):
>
> Never, ever use `sudo pip` on an Arch based system

Ooooops! I already did!  
Can I revert back?

---

<div class="post-metadata">

**Author:** ![dalto](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/dalto/32/5577_2.png) [@dalto](https://forum.endeavouros.com/u/dalto)\
**Post date:** [July 20, 2022, 4:05pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/34 "2022-07-20T16:05:15Z")

</div>

> [@limotux](#):
>
> Ooooops! I already did!

In your case, it looks like it failed to do anything. Should be OK.

---

<div class="post-metadata">

**Author:** ![dalto](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/dalto/32/5577_2.png) [@dalto](https://forum.endeavouros.com/u/dalto)\
**Post date:** [July 20, 2022, 4:05pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/35 "2022-07-20T16:05:40Z")

</div>

Can we see the output of `pacman -Q | grep -i jinja`

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 20, 2022, 4:07pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/36 "2022-07-20T16:07:29Z")

</div>

> [@pycrk](#):
>
> do you find the jinja2 folder there?

Yes, I have a few as follows, I tried lots of things:

```auto
jinja2
Jinja2-3.1.2-py3.10.egg-info
jinja2_time
jinja2_time-0.2.0-py3.10.egg-info

```

---

<div class="post-metadata">

**Author:** ![2000](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/2/ee59a6/32.png) [@2000](https://forum.endeavouros.com/u/2000)\
**Post date:** [July 20, 2022, 4:08pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/37 "2022-07-20T16:08:39Z")

</div>

> [@pycrk](#):
>
> and run the command
> 
> ```auto
> pip install jinja2
> 
> ```

It’s probably too late for you now, but for future refererence:  
It’s not recommended to use pip to install system-wide packages! Use your package manager (`pacman`) instead.

I’d recommend reading up on [Virtual environments](https://wiki.archlinux.org/title/Python/Virtual_environment) to create a self-contained Python environment in which you can install whatever you want with `pip`, without it conflicting with your system down the road.

For example:

```auto
sudo pacman -S python-virtualenv
virtualenv path/to/my_virtenv
source path/to/my_virtenv/bin/activate

```

would leave you in your my\_virtenv environment. Now, your Python interpreter will use packages from _that_ environment, instead of your system-wide Python install. As long as you remain in this environment you can install whatever you want with pip, it’s not going to conflict with your system.

To exit the environment, just run the command `deactivate`. If you want to get rid of the environment completely, just delete the folder `my_virtenv`.

* * *

[Edit] Dalto beat me to it.

> [@dalto](#):
>
> Never, ever use `sudo pip` on an Arch based system

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 20, 2022, 4:09pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/38 "2022-07-20T16:09:16Z")

</div>

> [@dalto](#):
>
> Can we see the output of `pacman -Q | grep -i jinja`

```auto
[limo@limo ~]$ pacman -Q | grep -i jinja
python-jinja 1:3.1.2-2
python-jinja-time 0.2.0-7
[limo@limo ~]$ 

```

---

<div class="post-metadata">

**Author:** ![dalto](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/dalto/32/5577_2.png) [@dalto](https://forum.endeavouros.com/u/dalto)\
**Post date:** [July 20, 2022, 4:11pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/39 "2022-07-20T16:11:35Z")

</div>

What does `pacman -Qo /usr/lib/python3.10/site-packages/jinja2` show?

---

<div class="post-metadata">

**Author:** ![limotux](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/limotux/32/35347_2.png) [@limotux](https://forum.endeavouros.com/u/limotux)\
**Post date:** [July 20, 2022, 4:13pm UTC](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439/40 "2022-07-20T16:13:32Z")

</div>

> [@2000](#):
>
> Dalto beat me to it.

But he said

> [@dalto](#):
>
> In your case, it looks like it failed to do anything. Should be OK.

Hopefully it is still OK.

```auto
[limo@limo ~]$ yay -Syyu
:: Synchronizing package databases...
 core 156.8 KiB 223 KiB/s 00:01 [------------------------------------] 100%
 extra 1716.7 KiB 723 KiB/s 00:02 [------------------------------------] 100%
 community 6.7 MiB 1551 KiB/s 00:04 [------------------------------------] 100%
 multilib 170.9 KiB 281 KiB/s 00:01 [------------------------------------] 100%
 endeavouros 33.5 KiB 35.7 KiB/s 00:01 [------------------------------------] 100%
:: Starting full system upgrade...
 there is nothing to do
:: Searching databases for updates...
:: Searching AUR for updates...
 there is nothing to do
[limo@limo ~]$ 

```

[Previous page](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439.md?page=1)

[Next page](https://forum.endeavouros.com/t/ocr-to-add-text-to-file/29439.md?page=3)
