Pdftk not working with Laravel on shared hosting - shared-hosting

I am working on a project that needs a pdf form populated from a database my project is to develop on Laravel 9 and for pdf fill using mikehaertl/php-pdftk and this website is live on shared hosting. I am getting this error and am not able to solve this.
Error
Error: Unexpected Exception in open_reader()
java.lang.RuntimeException: java.lang.RuntimeException: error instantiating default socket factory: java.security.KeyManagementException: java.security.KeyStoreException: java.io.FileNotFoundException: /usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre/lib/security/cacerts (No such file or directory)
at javax.net.ssl.SSLSocketFactory$ErrorSocketFactory.createSocket(libgcj.so.10)
at gnu.java.net.protocol.http.HTTPConnection.getSocket(libgcj.so.10)
at gnu.java.net.protocol.http.HTTPConnection.getOutputStream(libgcj.so.10)
at gnu.java.net.protocol.http.Request.dispatch(libgcj.so.10)
at gnu.java.net.protocol.http.HTTPURLConnection.connect(libgcj.so.10)
at gnu.java.net.protocol.http.HTTPURLConnection.getInputStream(libgcj.so.10)
at java.net.URL.openStream(libgcj.so.10)
at pdftk.com.lowagie.text.pdf.RandomAccessFileOrArray.(pdftk)
at pdftk.com.lowagie.text.pdf.RandomAccessFileOrArray.(pdftk)
at pdftk.com.lowagie.text.pdf.PRTokeniser.(pdftk)
at pdftk.com.lowagie.text.pdf.PdfReader.(pdftk)
at pdftk.com.lowagie.text.pdf.PdfReader.(pdftk)
Caused by: java.lang.RuntimeException: error instantiating default socket factory: java.security.KeyManagementException: java.security.KeyStoreException: java.io.FileNotFoundException: /usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre/lib/security/cacerts (No such file or directory)
at javax.net.ssl.SSLSocketFactory.getDefault(libgcj.so.10)
at javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(libgcj.so.10)
at javax.net.ssl.HttpsURLConnection.getSSLSocketFactory(libgcj.so.10)
...8 more
Caused by: java.security.KeyManagementException: java.security.KeyStoreException: java.io.FileNotFoundException: /usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre/lib/security/cacerts (No such file or directory)
at gnu.javax.net.ssl.provider.SSLContextImpl.defaultTrustManager(libgcj.so.10)
at gnu.javax.net.ssl.provider.SSLContextImpl.engineInit(libgcj.so.10)
at javax.net.ssl.SSLContext.init(libgcj.so.10)
at javax.net.ssl.SSLSocketFactory.getDefault(libgcj.so.10)
...10 more
Caused by: java.security.KeyStoreException: java.io.FileNotFoundException: /usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre/lib/security/cacerts (No such file or directory)
at gnu.javax.net.ssl.provider.X509TrustManagerFactory.engineInit(libgcj.so.10)
at javax.net.ssl.TrustManagerFactory.init(libgcj.so.10)
at gnu.javax.net.ssl.provider.SSLContextImpl.defaultTrustManager(libgcj.so.10)
...13 more
Caused by: java.io.FileNotFoundException: /usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre/lib/security/cacerts (No such file or directory)
at gnu.java.nio.channels.FileChannelImpl.open(libgcj.so.10)
at gnu.java.nio.channels.FileChannelImpl.(libgcj.so.10)
at gnu.java.nio.channels.FileChannelImpl.create(libgcj.so.10)
at java.io.FileInputStream.(libgcj.so.10)
at java.io.FileInputStream.(libgcj.so.10)
at gnu.javax.net.ssl.provider.X509TrustManagerFactory.engineInit(libgcj.so.10)
...15 more
Error: Failed to open PDF file:
https://tax-ein-number.com/pdf/fss4.pdf
Errors encountered. No output created.
Done. Input errors, so no output created.
Here is the Laravel Controller code
use mikehaertl\pdftk\Pdf;
class FillAblePdfController extends Controller
{
public function autofillpdf_ss4(Request $request, $order_id)
{
$filename = 'pdf_'.rand(2000, 1200000).'.pdf';
$pdf = new Pdf(asset('/pdf/fss4.pdf'),[
'command' => public_path('/pdftk/bin/pdftk'),
'procEnv' => ['LD_LIBRARY_PATH' => public_path('pdftk/bin/libgcj.so.10')]
]);
$result = $pdf->fillForm([
'topmostSubform[0].Page1[0].f1_40[0]' => 'Jhon',
])->needAppearances()->saveAs(asset('pdf/'.$filename));
if ($result === false) {
echo $pdf->getError();
}
}
}
One important thing I have this code also tested in Core PHP (without Laravel Framework) on the same hosting and domain that is working fine but i need it in Laravel.
Core PHP code that works as I need
require_once 'vendor/autoload.php';
use mikehaertl\pdftk\Pdf;
$filename = 'pdf_'.rand(2000, 1200000).'.pdf';
$pdf = new Pdf('./fss4.pdf',['command' => './pdftk/bin/pdftk','procEnv' => ['LD_LIBRARY_PATH' => './pdftk/lib/libgcj.so.10']]);
$result = $pdf->fillForm([
'topmostSubform[0].Page1[0].f1_40[0]' => 'Ali'
])->needAppearances()
->saveAs('./pdf/'.$filename);
if ($result === false) {
echo $pdf->getError();
}
echo 'Your PDF is now generated, <a href="./pdf/'.$filename.'" download>Download it here</a>';

Related

How to load a pdf file from Application Directory in flutter?

I am trying to load a PDF file from the application directory, I tried loading it from the url and it works and no I need to load the already downloaded PDF from the Application directory.
This is the package that I used to view PDF flutter_pdfview, while trying to load it from a url this works fine, now what I need is load an already downloaded pdf from the directory.
for loading file from directory i tried this:
var dir = await getApplicationDocumentsDirectory();
File file = File('${dir.path}/$pName.pdf');
bool fileExists = File(await '${dir.path}/$pName.pdf')
.existsSync();
if(fileExists)
{
urlPdfPath = file.toString();
print('url pdf path $urlPdfPath');
Navigator.push(context, MaterialPageRoute(builder: (context) {
return PdfViewer(
path: urlPdfPath,
product: pName,
);
}));
}
when i run this i got the exception
D/AndroidRuntime( 4565): Shutting down VM
E/AndroidRuntime( 4565): FATAL EXCEPTION: main
E/AndroidRuntime( 4565): java.lang.IllegalArgumentException: Unsupported value: java.io.FileNotFoundException: No such file or directory
In your Code:
Change - urlPdfPath = file.toString(); to urlPdfPath = file.path;

Magento Soap API 1.9 - failed to load external entity

when i tried to connect to Soap Api, i'm getting this error :
SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://www.lignedublanc.fr/index.php/api/soap/?wsdl' : failed to load external entity "https://www.lignedublanc.fr/index.php/api/soap/?wsdl
i tried with soap UI and same errors.
i tried everything on the net but nothing helped.
Maybe someone here can help me ?
<?php
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
$url = 'https://www.lignedublanc.fr/index.php/api/soap/?wsdl=1';
$MagentoAPILogin = '';
$MagentoAPIPass = '';
$context = stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]);
try {
echo "Connecting to : $url\n";
//$client = new SoapClient($url);
$client = new SoapClient($url, ['stream_context' => $context]);
echo $client->login($MagentoAPILogin, $MagentoAPIPass)."\n";
echo 'Login successful';
} catch (Exception $e) {
echo 'Login fail'."\n";
echo $e->getMessage()."\n";
echo $e->getTraceAsString()."\n";
}
I believe the problem is caused by the server not being able to access the API from the local machine. It is actually the .htaccess file that blocking any hosts except the development machines. Hence, it results in a 403 Forbidden error which is actually the SOAP error. For more reference, have a look:
Unable to connect to Magento SOAP API v2 due to "failed to load external entity"

can't test eloquent with php unit

I try to implement some unit tests with phpUnit, on a project that uses Eloquent. The installation is made with composer for both frameworks. But when I try to implement a simple example test, it fails loading database.php
the example test
include("database.php");
class ArticleControllerTest extends TestCase
{
public function testAccueil()
{
//récupère la date du jour
$a = \app\model\Article::first();
$this->assertInternalType("string", $a->titreGeneral);
}
}
Database.php
<?php
require 'vendor/autoload.php';
use Illuminate\Container\Container;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;
$capsule = new Capsule;
$capsule->addConnection(array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'spectacles',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
));
$capsule->setEventDispatcher(new Dispatcher(new Container));
$capsule->setAsGlobal();
$capsule->bootEloquent();
error message with these script (the database is in the right folder)
PHP Warning: include(../../database.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/spectacles/TestUnits/controllerTest/ArticleControllerTest.php on line 6
Warning: include(../../database.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/spectacles/TestUnits/controllerTest/ArticleControllerTest.php on line 6
PHP Warning: include(): Failed opening '../../database.php' for inclusion (include_path='.:') in /Applications/MAMP/htdocs/spectacles/TestUnits/controllerTest/ArticleControllerTest.php on line 6
Warning: include(): Failed opening '../../database.php' for inclusion (include_path='.:') in /Applications/MAMP/htdocs/spectacles/TestUnits/controllerTest/ArticleControllerTest.php on line 6
And error messages when I try to put the code in database.php directly in the example test :
PDOException: SQLSTATE[HY000] [2002] No such file or directory
I don't think the problem comes prom the paths (they are the right paths). Did I miss something ?
PDOException: SQLSTATE[HY000] [2002] No such file or directory means the database could not connect.
The other errors are clearly telling you that the script could not include the database.php file.
The paths are not correct. You are not properly understanding how include() works. Read http://php.net/manual/en/function.include.php.
In a nutshell, the following code expects the database.php file to exist in the same directory as the file itself, or on the include path.
include("database.php");
class ArticleControllerTest extends TestCase
{
...
These may also help:
Understanding include_path output PHP
Include Config and Database from other files

Puppet - Error: Could not retrieve catalog; skipping run

when I try to connect the puppet agent with puppet agent --test, I have this error :
Info: Retrieving plugin
Error: Could not retrieve catalog from remote server: Error 400 on SERVER :Could not find class <my_module> for <my_agent> on node <my_agent>
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
I have import nodes on sites.pp and include <my_module> on nodes.pp
--edit--
Content of sites.pp :
import "nodes"
filebucket { main: server => "<my_master>" }
File { backup => main }
Exec { path => "/usr/bin:/usr/sbon:/bin:/sbin" }
Content of nodes.pp :
node "<my_agent>" {
include <my_module>
}
--edit--
What is the real problem ?
Thanks
I have created another VM, and that's working now ! =)
Maybe I have taken a mistake in the network configuration.

CakePHP 2.0 + Notice (8): Undefined index: Upload [APP/Controller/UploadsController.php, line 32]

Im using 000webhost as a way to host my portfolio of websites. However Im getting this error thrown in which doesn't happen to me on localhost.
Notice (8): Undefined index: Upload [APP/Controller/UploadsController.php, line 32]
This is the code it seems to be referring to,
public function add() {
$this->render();
if($this->request->is('post')){
$file = $this->request->data['Upload']['file'];
if($this->Upload->save($this->data) && move_uploaded_file($file['tmp_name'],APP.'webroot/files/uploads'.DS.$this->Upload->id.'.mp4'))
{
$this->Session->setFlash('<p class="uploadflash">The upload has been saved</p>', true);
$this->redirect(array('controller'=>'Uploads', 'action' => 'watch', $this->Upload->id));
} else {
$this->Session->setFlash('<p class="loginerror">The upload could not be saved, mp4 files can be saved only.</p>', true);
}
}
}
Any ideas as to why this is happening?
Also in addition my Elements are not showing up on this online hosting either?
I get thrown this error on the page
Element Not Found: Elements/uploads/recentuploads.ctp
Does anyone else seem to have this problem??
Upon further inspection I have found that the server does not allow file upload sizes to exceed 2mb, in this instance PHP throws the error above.