Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从PDF创建XML_Php_Xml - Fatal编程技术网

Php 从PDF创建XML

Php 从PDF创建XML,php,xml,Php,Xml,我想创建一个基于pdf的XML文件。我有以下设置: <?php $pdf = 'http://mywebsite.com/files/test.pdf'; /** * Get Remote File Size * * @param sting $url as remote file URL * @return int as file size in byte */ function remote_file_size($url){ # Get all header inf

我想创建一个基于pdf的XML文件。我有以下设置:

<?php
$pdf = 'http://mywebsite.com/files/test.pdf';

/**
 * Get Remote File Size
 *
 * @param sting $url as remote file URL
 * @return int as file size in byte
 */
function remote_file_size($url){
    # Get all header information
    $data = get_headers($url, true);
    # Look up validity
    if (isset($data['Content-Length']))
        # Return file size
        return (int) $data['Content-Length'];
}

function createxml($pdf){
    $file = pathinfo($pdf);
    $file_dir = $file['dirname'];
    $file_base = $file['basename'];
    $file_ext = $file['extension'];
    $file_name = $file['filename'];
    $file_size = remote_file_size($pdf);

    $date = date('Y-m-d H:i:s');

$xml = <<<EOT
<?xml version="1.0" encoding="utf-8"?> 
<BluebeamRemotePackage Version="1.1" ID="pk123"> 
 <Provider>ProviderKey</Provider> 
 <LogoURL>http://mywebsite.com/files/logo.png</LogoURL> 
 <ProviderURL>www.mywebsite.com</ProviderURL> 
 <UserID>$user_id</UserID> 
 <UserName>$user_displayname</UserName> 
 <CompanyName>My Company</CompanyName> 
 <UserType>$user_company</UserType> 
 <Date>$date</Date> 
 <Project Name="$project" ID="$post_id"> 
  <Company>$user_company</Company> 
  <ProjectURL>$post_url</ProjectURL> 
  <File Name="$file_name" ID="$file_base"> 
   <FileURL>$pdf</FileURL> 
   <Size>$file_size</Size>  
   <Date>$date</Date> 
   <Load>True</Load>  
   <Security> 
    … 
   </Security> 
 </Project> 
</BluebeamRemotePackage> 
EOT;


    $dom = new DomDocument;
    $dom->preserveWhiteSpace = FALSE;
    $dom->loadXML($xml);

    echo $dom->saveXML();
}

if (file_exists($pdf)) {
  $xml = $pdf['filename'] . '.xml';
    header('Content-Type: application/octet-stream');
    header("Content-Transfer-Encoding: Binary"); 
    header("Content-disposition: attachment; filename=\"" . basename($xml) . "\""); 
    readfile($xml); // do the double-download-dance (dirty but worky)
} else {
  createxml($pdf);
}
我想知道我是否做得对,或者是否有更好的方法。基本上,我希望脚本查看与pdf关联的XML文件是否存在,如果不存在;我想让它创建xml文件