1

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>';
MShoaib
  • 15
  • 1
  • 6

0 Answers0