How to convert Pdf file to byte array in php and send? : <p>I have found pdf to byte array and vice-versa in java,dotnet and python. But i want to convert pdf to byte array in php laravel. I am using "IMUIS" which is accounting software solution and need to sending journal entries from laravel lumen to "IMUIS" for processing.But it gives the error after converting.</p>

<blockquote>
  <p>"Foutmelding": "Kan een object van het type System.String niet converteren naar het type System.Byte[]."</p>
</blockquote>

<p>In english that means </p>

<blockquote>
  <p>"Error message": "Can not convert a System.String object to the System.Byte [] type."</p>
</blockquote>

<p>The documentation is given here:</p>

<p><a href="http://cswdoc.imuisonline.com/?page_id=382" rel="noreferrer">doc link</a></p>

<p>Here is the code for it. </p>

<pre><code>public function saveJournal($values = '') {
    //echo "adasd";dd();
    $partnerKey = $values-&gt;input('Partnerkey');
    $omgevingscode = $values-&gt;input('Environmentcode');  
    $file = file_get_contents($values-&gt;file('Pdffile'));
    $str = base64_encode($file);
    $options = array(
        \WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_URL =&gt; env('IMUIS_URL'),
        \WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_CLASSMAP =&gt; ClassMap::get(),
    );
    $login = new \mysdk\ImuisSDK\ServiceType\Login($options);
    if ($login-&gt;Login(new \mysdk\ImuisSDK\StructType\Login($partnerKey, $omgevingscode)) !== false) {
        $sessionid = $login-&gt;getResult()-&gt;SessionId;
    }

    $array = [
        'BOE' =&gt; [
           'JR' =&gt; '2018',
           'PN' =&gt; '5',
           'DAGB' =&gt; 20,
           'REK' =&gt; 20032,
           'TEGREK' =&gt; '40',
           'FACT' =&gt; 0,
           'BTW' =&gt; 4,
           'BEDRBOEK' =&gt; 123.45,
           'DAT' =&gt; '08-05-2018',
           'OPM' =&gt; 'Anand testing from wsdl',
           'BEDRBTW' =&gt; 21,
           'FACT' =&gt; 0,
           'OMSCHR' =&gt; 'Testing from wsdl api',
           'BOEKSTUK' =&gt; 2018075
        ],
        'DIGDOS' =&gt; [
            'FILE' =&gt; $str
        ]
    ];

    $journaalpost = ArrayToXml::convert($array, 'NewDataSet');//convert array to xml string

    $create = new \mysdk\ImuisSDK\ServiceType\Create($options);
    if ($create-&gt;CreateJournaalpost(new \mysdk\ImuisSDK\StructType\CreateJournaalpost($partnerKey, $omgevingscode, $sessionid, $journaalpost)) !== false) {
        $jsonResponse = $create-&gt;getResult();
    } else {
        $jsonResponse = $create-&gt;getLastError();
    }
    return $jsonResponse;
}
</code></pre>

<p>and here is the response as well:</p>

<pre><code>{
    "success": true,
    "result": {
        "CreateJournaalpostResult": false,
        "Journaalpost": "&lt;?xml version=\"1.0\"?&gt;\n&lt;NewDataSet&gt;&lt;BOE&gt;&lt;JR&gt;2018&lt;/JR&gt;&lt;PN&gt;5&lt;/PN&gt;&lt;DAGB&gt;20&lt;/DAGB&gt;&lt;REK&gt;20032&lt;/REK&gt;&lt;TEGREK&gt;40&lt;/TEGREK&gt;&lt;FACT&gt;0&lt;/FACT&gt;&lt;BTW&gt;4&lt;/BTW&gt;&lt;BEDRBOEK&gt;123.45&lt;/BEDRBOEK&gt;&lt;DAT&gt;08-05-2018&lt;/DAT&gt;&lt;OPM&gt;Anand testing from wsdl&lt;/OPM&gt;&lt;BEDRBTW&gt;21&lt;/BEDRBTW&gt;&lt;OMSCHR&gt;Testing from wsdl api&lt;/OMSCHR&gt;&lt;BOEKSTUK&gt;2018075&lt;/BOEKSTUK&gt;&lt;/BOE&gt;&lt;DIGDOS&gt;&lt;FILE&gt;JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAyIDAgUgovQ29udGVudHMgNCAwIFI+PgplbmRvYmoKNCAwIG9iago8PC9GaWx0ZXIgL0ZsYXRlRGVjb2RlIC9MZW5ndGggMzg2Pj4Kc3RyZWFtCniclZNPb9pAEMXvfIp3TA8Zdme93jE3G0xFJWgKJtdolbhICTYU6L9v3zWEGKnUVeST1++9+b2xzfjUU2QdfvayAv2xRkJKofiKvOh9g00ssUCFS0xMzFDNY0uxw2OF/kRjtMGXxms06QSOLUnwP+Fmkd+lyMr9wddP+9r7aoDxfFE8NOfaKqtZO+PoV7X+gOK5mdekSBhg/opJfb0qK+9fDthsB2Cl5VbZWx1D80DZAbtzhiIX2iiSJGBTIoLd6mo1hRXesGMRSuxx3ixNpxjl2aRY5vPX1NDwzcASk1GXjnE6LJbL+Ww5nV51RCykokvHZDZMF5+R5aN5+rF1BJ2xcDoiY1DBSmBT5/s1FqceDPl3D8fEpxmj8schLB/DTbX19e+OJq1Hc+Q6CrTCJBzwFeUrhQ1fTfROitYTs+mAaHVamU4KI8TmnRStJ+Zr0WeKVvefVbBu/prjS6/333e+fiwx9bVflbs9MrqnDpjWq7WRDpoLYSTOUXyxwD9RUucvCmVuZHN0cmVhbQplbmRvYmoKMSAwIG9iago8PC9UeXBlIC9QYWdlcwovS2lkcyBbMyAwIFIgXQovQ291bnQgMQovTWVkaWV5s7I11RFTyPO/t9OL74tl5/das6enN0bXwr//AKZ629kqeo76x9P/AOOs4y+N/wDK6nJuq/7nerWTI6zQrTReVjEVir+fVST/AF1m6Wrf7W+uMQ+o/D744dNdW2I8fKx2Ny8nCOrKu5j18zJOGq/JoeLX9ndp47YfR9t7+zUmmy59IPG9wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABuIAowMDAwMDc2NDgzIDAwMDAwIG4gCjAwMDAwNzY1NTkgMDAwMDAgbiAKdHJhaWxlcgo8PAovU2l6ZSAxMQovUm9vdCAxMCAwIFIKL0luZm8gOSAwIFIKPj4Kc3RhcnR4cmVmCjc2NjA5CiUlRU9GCg0KCiAgICAgIA==&lt;/FILE&gt;&lt;/DIGDOS&gt;&lt;/NewDataSet&gt;\n",
        "Primarykey": null,
        "Foutmelding": "Kan een object van het type System.String niet converteren naar het type System.Byte[]."
    }
}
</code></pre>
