简体   繁体   中英

PHP - IPP printer class not printing specific PDF file

The IPP class is printing PDF properly, but it is not printing specific file of SWIFT which is in PDF. I tried all possible attribute in IPP class which had no result.

The main purpose of running this application is to scan the SWIFT folder for PDF files, then print each file PDF in specific printer and move the file to backup folder.

require_once('php_classes/PrintIPP.php');

$clientPath = "../swiftapp/public/_assets/getfile/";
$pdffiles     = array();
$valid_files  = array('pdf');

$ipp = new PrintIPP();

if(is_dir($clientPath)){
    foreach(scandir($clientPath) as $file){

        $ext = pathinfo($file, PATHINFO_EXTENSION);

        if(in_array($ext, $valid_files)){

            array_push($pdffiles, $file);
            $filePath = $clientPath.$file;
        
            // IPP printer configuration
            $ipp->setHost('172.18.0.98');
            $ipp->setPort(631);
            $ipp->setPrinterURI('./printers/NPIAB29B2 (HP LaserJet M402dn)');
            
            // IPP file configuration
            $ipp->setDocumentName($file);
            $ipp->setMimeMediaType('application/pdf');
            $ipp->unsetFidelity();
            $ipp->setCharset('utf-8');
            
            // Set PDF data for print
            $ipp->setData($getInsideFile);
            
            // send file for print
            $getPrintObj = $ipp->printJob();

            if($getPrintObj == 'successfull-ok'){

                $destinationFilePath = '../swiftapp/public/_assets/copyfile/'.$file;

                if( rename($filePath, $destinationFilePath) ) {
                    echo "<p style='color:#fff; 68b631'>$file file has been moved.</p>";
                } else {
                    echo "<p style='color:#EB1000'>File can't be moved!</p>";
                }

            }

        }

    }
}

This link is one of the real PDF file which IPP cant print it PDF file for print

Well, the first thing is that the file was allegedly created by Ghostscript 9.27 which I find alarming if this is the SWIFT banking network, as that version of Ghostscript has significant well-publicised security vulnerabilities.

That said, it looks to me like either the Producer field is incorrect or someone edited the file after it was created. Or, just possibly, the creator used a broken build of Ghostscript, which would raise the question of where they got it from.

In any event, the file is broken. Badly so. The end of the file has the startxref token, which should be an offset into the file where the xref token can be found given like this:

startxref
%ld
%%EOF

Obviously %ld looks remarkably like it's an argument to sprintf. In addition the xref table itself is invalid:

xref
0 %ld
0000000000 65535 f 
        %ld 00000 n 
        %ld 00000 n 
        %ld 00000 n 
        %ld 00000 n 
        %ld 00000 n 
        %ld 00000 n 
        %ld 00000 n 
        %ld 00000 n 
        %ld 00000 n 
        %ld 00000 n 
        %ld 00000 n 
        %ld 00000 n 
        %ld 00000 n 
        %ld 00000 n 

I've never seen any version of Ghostscript which would produce a file broken in that way.

You could run the file back through Ghostscript to the pdfwrite device which will repair the file for you, producing a PDF file which you can then print, but I don't really recommend that as standard practice.

If you open the file in Acrobat and then close it, Acrobat will offer to 'save the changes' (a fairly good sign the file is damaged) and produce a fixed file for you.

Other than that, you need to go back to whoever is creating these files and tell them they are making garbage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM