<legend id='cX8Ah'><style id='cX8Ah'><dir id='cX8Ah'><q id='cX8Ah'></q></dir></style></legend>

    <i id='cX8Ah'><tr id='cX8Ah'><dt id='cX8Ah'><q id='cX8Ah'><span id='cX8Ah'><b id='cX8Ah'><form id='cX8Ah'><ins id='cX8Ah'></ins><ul id='cX8Ah'></ul><sub id='cX8Ah'></sub></form><legend id='cX8Ah'></legend><bdo id='cX8Ah'><pre id='cX8Ah'><center id='cX8Ah'></center></pre></bdo></b><th id='cX8Ah'></th></span></q></dt></tr></i><div id='cX8Ah'><tfoot id='cX8Ah'></tfoot><dl id='cX8Ah'><fieldset id='cX8Ah'></fieldset></dl></div>

    • <bdo id='cX8Ah'></bdo><ul id='cX8Ah'></ul>
  1. <small id='cX8Ah'></small><noframes id='cX8Ah'>

      <tfoot id='cX8Ah'></tfoot>

      PHP 获取 Pdf 文件属性中的高度和宽度

      时间:2023-10-12
        <tbody id='pVeI0'></tbody>
        <legend id='pVeI0'><style id='pVeI0'><dir id='pVeI0'><q id='pVeI0'></q></dir></style></legend>
      • <i id='pVeI0'><tr id='pVeI0'><dt id='pVeI0'><q id='pVeI0'><span id='pVeI0'><b id='pVeI0'><form id='pVeI0'><ins id='pVeI0'></ins><ul id='pVeI0'></ul><sub id='pVeI0'></sub></form><legend id='pVeI0'></legend><bdo id='pVeI0'><pre id='pVeI0'><center id='pVeI0'></center></pre></bdo></b><th id='pVeI0'></th></span></q></dt></tr></i><div id='pVeI0'><tfoot id='pVeI0'></tfoot><dl id='pVeI0'><fieldset id='pVeI0'></fieldset></dl></div>

          <tfoot id='pVeI0'></tfoot>

          <small id='pVeI0'></small><noframes id='pVeI0'>

              <bdo id='pVeI0'></bdo><ul id='pVeI0'></ul>
              1. 本文介绍了PHP 获取 Pdf 文件属性中的高度和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个 PDF 文件.我想以毫米为单位得到它的高度和宽度.

                I have a PDF file. I would to get it height and width in mm.

                所以我做了一个 exec(pdfinfo ... );我有这个结果:

                So I do an exec(pdfinfo ... ); I have this result :

                创作者:Adobe InDesign CS5 (7.0.3) 制作者:Acrobat Distiller 9.4.2 (Macintosh) CreationDate:Mon Jan 30 15:48:43 2012 ModDate:Fri Feb 10 10:35:05 2012 标记:无 页数:34 加密:无页面大小:552.744 x 708.643 pts 文件大小:80724791 字节优化:是 PDF 版本:1.3

                Creator: Adobe InDesign CS5 (7.0.3) Producer: Acrobat Distiller 9.4.2 (Macintosh) CreationDate: Mon Jan 30 15:48:43 2012 ModDate: Fri Feb 10 10:35:05 2012 Tagged: no Pages: 34 Encrypted: no Page size: 552.744 x 708.643 pts File size: 80724791 bytes Optimized: yes PDF version: 1.3

                我有一个脚本女巫提取我的信息:

                I have a script witch extract my info :

                <?php 
                $output = shell_exec("pdfinfo ".$pdflivrelink);
                $data = explode("
                ", $output); //puts it into an array
                for($c=0; $c < count($data); $c++) {
                        if(stristr($data[$c],"Pages") == true) {
                        $pagesnumber = trim(substr($data[$c],6));
                        }
                        if(stristr($data[$c],"Page size") == true) {
                            $pagesize_H = height_pdf(trim(substr($data[$c],9)));
                        }
                        if(stristr($data[$c],"Page size") == true) {
                            $pagesize_L = width_pdf(trim(substr($data[$c],9)));
                        }
                
                }
                function height_pdf($size){
                $hauteur = round(substr($size,7,7)/2.83);
                return $hauteur;
                }
                function width_pdf($size){
                $largeur = round(substr($size,17,7)/2.83);
                return $largeur;
                } ?>
                

                没关系,因为我有三个数字点三个数字 (552.744 x 708.643).但是,我不知道为什么,有些 PDF 文件包含此信息:

                It's OK, because I have three numbers dot three numbers (552.744 x 708.643). But, I don't know why, some PDF files have this info :

                创作者:pdftk 1.41 - www.pdftk.com 制作者:iText 2.1.5(by lowagie.com)创作日期:Mon Feb 27 13:18:23 2012 ModDate:Mon Feb 27 16:26:12 2012 标记:否页数:36 加密:无页面大小:425.2 x 538.582 pts 文件大小:5097597 字节优化:是 PDF 版本:1.6

                Creator: pdftk 1.41 - www.pdftk.com Producer: iText 2.1.5 (by lowagie.com) CreationDate: Mon Feb 27 13:18:23 2012 ModDate: Mon Feb 27 16:26:12 2012 Tagged: no Pages: 36 Encrypted: no Page size: 425.2 x 538.582 pts File size: 5097597 bytes Optimized: yes PDF version: 1.6

                425.2 x 538.582:所以我的脚本不起作用!

                425.2 x 538.582 : So my script doesn't work!

                你能帮我吗?非常感谢!

                Can you help me? thank a lot!

                我对此进行了测试:

                    $output = shell_exec("pdfinfo ".$pdflivrelink);
                    $data = explode("
                ", $output); //puts it into an array
                    for($c=0; $c < count($data); $c++) {
                            if(stristr($data[$c],"Pages") == true) {
                            $pagesnumber = trim(substr($data[$c],6));
                
                            }
                            if(stristr($data[$c],"Page size") == true) {
                                echo $data[$c];
                    preg_match('/Page size: ([0-9]*.?[0-9]?) x ([0-9]*.?[0-9]?)/', $data[$c], $matchess);
                    $width = round($matchess[1]/2.83);
                    $height = round($matchess[2]/2.83);
                
                            }
                }
                echo "width = $width<br>height = $height";
                

                结果:

                页面大小:425.2 x 538.582 ptswidth = 0 height = 0

                Page size: 425.2 x 538.582 ptswidth = 0 height = 0

                推荐答案

                一点正则表达式就能得到正确的结果.

                A little regex will get you the correct results.

                <?php
                $str = 'Creator: pdftk 1.41 - www.pdftk.com Producer: iText 2.1.5 (by lowagie.com) CreationDate: Mon Feb 27 13:18:23 2012 ModDate: Mon Feb 27 16:26:12 2012 Tagged: no Pages: 36 Encrypted: no Page size: 425.2 x 538.582 pts File size: 5097597 bytes Optimized: yes PDF version: 1.6';
                
                preg_match('/Page size: ([0-9]*.?[0-9]?) x ([0-9]*.?[0-9]?)/', $str, $matches);
                $width = round($matches[1]/2.83);
                $height = round($matches[2]/2.83);
                
                echo "width = $width<br>height = $height";
                ?>
                

                更新(询问更多细节):完整的工作示例如下.我已经更新了 Regex 以匹配 pdfinfo

                Update ( asked for more details ) : Complete working example below. I've updated Regex to match real output from pdfinfo

                <?php
                
                $output = shell_exec("pdfinfo ".$pdflivrelink);
                
                // find page count
                preg_match('/Pages:s+([0-9]+)/', $output, $pagecountmatches);
                $pagecount = $pagecountmatches[1];
                
                // find page sizes
                preg_match('/Page size:s+([0-9]{0,5}.?[0-9]{0,3}) x ([0-9]{0,5}.?[0-9]{0,3})/', $output, $pagesizematches);
                $width = round($pagesizematches[1]/2.83);
                $height = round($pagesizematches[2]/2.83);
                
                echo "pagecount = $pagecount <br>width = $width<br>height = $height";
                
                ?>
                

                这篇关于PHP 获取 Pdf 文件属性中的高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:使用带有参数的 file_get_contents 从 PHP 获取请求 下一篇:我可以有多个具有相同键、不同值的 $_GET 吗?

                相关文章

                  <small id='qYQRN'></small><noframes id='qYQRN'>

                  1. <legend id='qYQRN'><style id='qYQRN'><dir id='qYQRN'><q id='qYQRN'></q></dir></style></legend>

                  2. <i id='qYQRN'><tr id='qYQRN'><dt id='qYQRN'><q id='qYQRN'><span id='qYQRN'><b id='qYQRN'><form id='qYQRN'><ins id='qYQRN'></ins><ul id='qYQRN'></ul><sub id='qYQRN'></sub></form><legend id='qYQRN'></legend><bdo id='qYQRN'><pre id='qYQRN'><center id='qYQRN'></center></pre></bdo></b><th id='qYQRN'></th></span></q></dt></tr></i><div id='qYQRN'><tfoot id='qYQRN'></tfoot><dl id='qYQRN'><fieldset id='qYQRN'></fieldset></dl></div>
                  3. <tfoot id='qYQRN'></tfoot>

                      <bdo id='qYQRN'></bdo><ul id='qYQRN'></ul>