Extract text from pdf not working in Laravel - laravel

I am trying to extract some text from a PDF file in Laravel using Spatie-PdfToText. However, I get the error no such file or directory. The function is in this path app\Http\Controllers\AddRecordsController and the PDF in this path \app\Http\Controllers\book.pdf.
I've also tried changing the path in getText() to the path written above but same error.
Code to extract:
public function readPDF(){
echo Pdf::getText('book.pdf'); //returns the text
}
Can anyone assist me?

in first you need instal binary library.
if you use Ubuntu or Debian:
apt-get install poppler-utils
or if use RedHat or CentOS:
yum install poppler-utils
After it install library via composer:
composer require spatie/pdf-to-text
Then use it in your controller:
use Spatie\PdfToText\Pdf;
...
echo Pdf::getText('/path/to/file.pdf');

Related

setup-install magento 2. Type Error occurred when creating object

I'm having a problem when I install new Magento 2 on my ubuntu. I got an error when I run the command:
sudo bin/magento setup:install
--admin-firstname="zzz"
--admin-lastname="zzz"
--admin-email="zzz#gmail.com"
--admin-user="admin"
--admin-password="admin123"
--db-name="zzzdb"
--db-user="root"
--db-password=""
Error:
Type Error occurred when creating object: Magento\Framework\Stdlib\DateTime\DateTime
I've consulted the solutions but it seems to be creating a new project, not installing. And I tried rm -rf generated/, chmod -R 777 generated/. But it doesn't work =((
Thanks for any answers.
Type Error means that Object Manager can't instantiate given object due to invalid parameters. The class \Magento\Framework\Stdlib\DateTime\DateTime has a dependency on TimezoneInterface
public function __construct(TimezoneInterface $localeDate)
Which is implemented by
Magento\Framework\Stdlib\DateTime\Timezone
which then depends on
Magento\Framework\Stdlib\DateTime\Intl\DateFormatterFactory
that requires PHP-intl extension.
(in the constructor instantiates IntlDateFormatter)
$formatter = new \IntlDateFormatter(
$locale,
$dateStyle,
$timeStyle,
$timeZone
);
My guess is that you haven't installed intl extension for PHP.
https://www.php.net/manual/en/intl.installation.php
You can get more verbose input by providing -vvv as the command argument.
That is very simple, since \DateTime object always contains a timezone, it is possible to translate it into UTC at any time. As you see, it does call internally \Magento\Framework\Stdlib\DateTime to convert time into a text representation.
Ideally, as with any other modern PHP ORM, you should be able to specify the \DateTime object, and the rest of how it is stored should be processed by the library itself. So, it's very well known that during installation, the PHP intl extension is missing.
Hope it will help you.
You can check if all module are available/installed in your system by run command in your magento2 root directory:
composer install
if this give some error then read error there mentioned php-missing modules.
Then you can install them by :
sudo apt-get php{php version}-{module name}
example
sudo apt-get php8.1-intl

error trying to create extension: pg_stat_statement

I'm trying to install pg_stat_statements doing this:
CREATE EXTENSION pg_stat_statements;
and I get this:
ERROR: could not open extension control file "/usr/local/greenplum-db-6.10.1/share/postgresql/extension/pg_stat_statements.control": No such file or directory
I already installed postgresql-contrib as follow:
sudo yum install postgresql-contrib
The file pg_stat_statements.control is not found on the location specified in the error, should I download it? or how does it work?
There is no documentation of that extension of greenplum. I would say its not supported.

Problem in download dropbox file from laravel

I am using laravel-dropbox-driver package.
When i try to download file from droobox like
Storage::disk('dropbox') - >download($filename) ;
It throws an error
Call to undefined method league/flysysten download
You are missing a required package, run the below command:
composer require spatie/flysystem-dropbox
This will install the required League Flysystem.

Python - cant find pip.ini or pip.conf in Windows

I got Python 2.7.8 installed on my Win7 machine, which comes with pip already pre-installed. I'm successfully able to install new packages from pip and now I need to add custom repository url to the install list of pip
To do so I need to modify pip.ini which is in %APPDATA%\pip\pip.ini according to the Official Manual
However there are no pip folder anywhere (not in Roaming, not in Local, not in LocalLow)
nor there exists PyPa folder in: C:\ProgramData\PyPA\pip\pip.conf
Could you tell me where do i search for pip.ini? how to add foreign repo to the install list?
Instead of checking a list of well-known locations, you can ask pip to list the valid locations:
pip config -v list
Fun fact
On the same machine, with the same pip version, the valid locations can vary based on the actual Python version.
Environment: Win 7 x64, the HOME environment variable is set to D:\Home
Python 3.7.3:
> pip config -v list
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'D:\Home\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\foobar\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'C:\Python37\pip.ini'
Python 3.8.0:
> pip config -v list
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\foobar\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\foobar\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'C:\Python38\pip.ini'
Finally got it sorted.
Apparently for Windows users pip.ini config file is not created, however can be added manually!
just create new %APPDATA%\pip\pip.ini and content of custom repository:
[install]
find-links = https://<login>:<password>#your.repo.com/custom/url
Reference: https://pip.pypa.io/en/stable/user_guide/#config-file
A bit late, but for reference:
Try adding the pip.ini file in %USERPROFILE%\pip\pip.ini (usually: C:\Users\<username>\pip\pip.ini).
On windows pip.exe looks for "pip.ini" in this order:
C:\ProgramData\pip\pip.ini
C:\Users\<username>\pip\pip.ini
C:\Users\<username>\AppData\Roaming\pip\pip.ini
It's been 7 years, and I think there's now a better answer for most people -- but it does depend on version of pip. For the most recent pips I'm using:
$ pip config -v debug
lists where it's looking and you can decide which location is
most useful for what you've got in mind. It does look like a fairly recent
change: On a year-old docker image I had with pip 20.1
I got "ERROR: Need an action (edit, get, list, set, unset) to
perform." On that system, pip config -v list gave a list of files it would try, this is supposed to be 'global', 'user' or 'site' variants of pip.ini locations.
For Windows 10, for pip 21.2.4 on both 3.9.6 and 3.6.8, I get response below with pip config -v debug, while pip config -v list is silent (unless a pip.ini is found).
global:
C:\ProgramData\pip\pip.ini, exists: False
site:
c:\py\myvenv\pip.ini, exists: False
user:
C:\Users\myname\pip\pip.ini, exists: False
C:\Users\myname\AppData\Roaming\pip\pip.ini, exists: False
From a downloaded image I got from dockerhub in June 2021 with pip 21.2.2 and python 3.6.10:
pip config -v debug
env_var:
env:
global:
/etc/xdg/pip/pip.conf, exists: False
/etc/pip.conf, exists: True
global.extra-index-url: http://trynexs:8081/repository/repo_group/simple
site:
/usr/local/pip.conf, exists: False
user:
/home/tanhauser/.pip/pip.conf, exists: False
/home/tanhauser/.config/pip/pip.conf, exists: False
Pip changed the location of the config file in windows starting in pip 6.0 the pip config docs explain the location of the config files as follows.
pip --version >= 6 (as of version 18.1 hasn't changed again yet)
%APPDATA%\pip\pip.ini
pip --version < 6
%HOME%\pip\pip.ini
Inside a virtual env
%VIRTUAL_ENV%\pip.ini
Site-wide win7+ (same as of win10)
C:\ProgramData\pip\pip.ini
Site-wide winxp (note windows vista side wide not supported)
C:\Documents and Settings\All Users\Application Data\pip\pip.ini
NOTE: If multiple configuration files are found by pip then they are combined in the following order:
The site-wide file is read
The per-user file is read
The virtualenv-specific file is read
Also pip added a config command starting in pip 10.
pip config --help
I know this is a bit late, however, this post is high on the rankings when searching. Inside a virtual environment pip.ini can also be in the root of the virtual environment. From the docs and https://pip.pypa.io/en/stable/user_guide/?highlight=pip.ini#configuration
Inside a virtualenv:
On Unix and macOS the file is $VIRTUAL_ENV/pip.conf
On Windows the file is: %VIRTUAL_ENV%\pip.ini
All the answers are partially wrong and right.
It depends on how your system is configured. The only way (for me) to find out was to patch site-packages/pip/locations.py at the point where site_config_files is assigned (around line 120 for pip 9.0.1)
print('########## ' + str(site_config_files))
and then run pip search foo
On my system it printed ########## ['C:\\ProgramData\\pip\\pip.ini'], of which location I assumed I could not create/edit. But it just worked.
Btw, for my system %APPDATA% points to C:\Users\MYUSER\AppData\Roaming, which is not looked at when running pip on my system.
Rather than guessing first check if you have any default global/local config which is read by pip with the below command:
pip config list
This will give all details of the default config loaded by python.
If the above command doesn't give any output please try to find where pip tries to find for the global config file with the below command:
pip config --editor <path to editor of your choice> edit
The above command will open the config file which pip reads by default or else it will give an error saying that the file doesn't exist.
If there's an error please go ahead and create the exact directory and file structure as show in the error. Once the file has been created please make your changes e.g.
[global]
cert = /path/to/base64/ssl/certificate.pem
proxy = http://username:password#ipaddress:port
Save the file and please try to check (the above mentioned check command) if the configs are loaded by pip or not.
For more info please follow pip config documentation
Make sure you acually have a pip.ini file, not pip.ini.txt.
For me (Windows 8, pip 9.0.1, python 3.5.3), the correct path was
c:\Users\<UserName>\.pypirc <- sic!, even on windows
Windows 10:
I had to create 'pip' directory inside
C:\Users\UserName\AppData\Roaming\
then create pip.ini file inside that 'pip' directory:
C:\Users\<username>\AppData\Roaming\pip\pip.ini
No other location worked for me.
For Windows, python will load the config from path below. So, if pip.ini file is not exist in these paths you can create the new file by refer these path depend on environment scopes (global, user & site) that you need python execute.
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\MyName\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\MyName\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'c:\python39-32\pip.ini'
By the way, you can check the paths as above by
pip config -v list
On a Windows 10 machine with multiple users I used this:
c:\users\all users\pip\pip.ini
Using pip version 22.3.1 with python version 3.10.4..

unoconv not working on ubuntu 12.04 server

I am using unoconv to convert different file formats to pdf. It is working well on my local machine for all formats. But on my ubuntu 12.04 server unoconv is failing for some formats such as xls, ppt, pptx etc. However it is working fine for doc files. It shows the following error for the ppt conversion.
$unoconv -f pdf Googling.ppt
unoconv: UnoException during conversion in <class '__main__.com.sun.star.lang.IllegalArgumentException'>: Unsupported URL <file:///home/pythonuser/almamapper/media/library/files/c1cb92e62ce54b29a017a6e8eaa23c/Googling.ppt>: ""
Traceback (most recent call last):
File "/usr/bin/unoconv", line 790, in <module>
main()
File "/usr/bin/unoconv", line 769, in main
convertor.convert(inputfn)
File "/usr/bin/unoconv", line 679, in convert
error("ERROR: The provided document cannot be converted to the desired format. (code: %s)" % e.ErrCode)
File "/usr/lib/python2.7/dist-packages/uno.py", line 337, in _uno_struct__getattr__
return __builtin__.getattr(self.__dict__["value"],name)
AttributeError: ErrCode
I know I have to install openoffice-headless version on my server. But from this link I understand that Ubuntu switched to libreoffice instead of openoffice quite a while ago. So I installed libreoffice by the following command.
apt-get install libreoffice-core libreoffice-writer libreoffice-calc
But still am getting the same error. Am I missing something to install? Do anyone have any thoughts on this issue?
I fixed the above issue by installing latest version of unoconv. I tried updating libreoffice and installing complete version, neither helped.
I was using unoconv 0.3, and the latest available version is 0.6. So I installed the latest one and it solved the issue.
Here is the steps i followed:
apt-get remove --purge unoconv (remove the old unoconv first)
git clone https://github.com/dagwieers/unoconv
(download latest version of unoconv from github.)
now cd to unoconv directory and do sudo make install
Note: pls do git clone, dont download the tar file. In my case the installation failed when I downloaded the tar.
I had the same general problem after doing apt-get install unoconv, an additional apt-get install libreoffice fixed it. Probably your limited install of only some libreoffice components is the reason it only works for some formats. Certainly I would expect it to need libreoffice-impress for ppt conversion?

Resources