Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.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 如何使用gdriveapi将docx或html转换为pdf?_Php_Api_Pdf_Docx - Fatal编程技术网

Php 如何使用gdriveapi将docx或html转换为pdf?

Php 如何使用gdriveapi将docx或html转换为pdf?,php,api,pdf,docx,Php,Api,Pdf,Docx,我需要转换html或docx使用GriveAPI 我的代码 $client = new \Google_Client(); $client->setAccessToken($_SESSION['access_token']); $service = new \Google_Service_Drive($client); $content = file_get_contents('template.html');//template.docx $

我需要转换html或docx使用GriveAPI

我的代码

    $client = new \Google_Client();
    $client->setAccessToken($_SESSION['access_token']);
    $service = new \Google_Service_Drive($client);


    $content = file_get_contents('template.html');//template.docx 
    $fileMetadata = new \Google_Service_Drive_DriveFile(array(
        'name' => 'test', // name file
        'mimeType' => 'application/pdf', // mime type for save in gdrive
        //'parents' => array($id_folder) 
            ));
    $file = $service->files->create($fileMetadata, array(
        'data' => $content, // file
        'mimeType' => 'text/html', // application/vnd.openxmlformats-officedocument.wordprocessingml.document
        //'uploadType' => 'multipart',
        'fields' => 'id')); // 
文件上载到dDrive normal,但当我打开它test.pdf时,我看到此错误

无法加载其他页面

但是我的文件只有一页

如何解决此问题?

请参见示例。特别是我不认为你需要有字段元素在那里,我不能在文档中找到。当您将文件上传为text/html时,请确保您拥有正确的元数据,并在一次完成内容和元数据的同时启用多部分

我还建议分小步来做,首先让它成为非常简单的html内容,如果这样做有效的话,你的内容可能不会让pdf像正常一样出现

如果您研究了其中的一些示例,那么如果问题出现在元数据、内容或其他方面,则很容易进行调试。

请参阅示例。特别是我不认为你需要有字段元素在那里,我不能在文档中找到。当您将文件上传为text/html时,请确保您拥有正确的元数据,并在一次完成内容和元数据的同时启用多部分

我还建议分小步来做,首先让它成为非常简单的html内容,如果这样做有效的话,你的内容可能不会让pdf像正常一样出现


如果您研究了其中一些示例,那么如果问题出现在元数据、内容或其他任何方面,则很容易进行调试。

执行上载小文本文件的基本测试。使用示例代码,如果可以的话,可以一步一步地修改它。我上传了一个小的txt文件,得到了和上传pdf文件相同的错误。尝试上传txt/html,然后一旦上传完成,再尝试下载pdf格式的相同文件。我想你正在尝试上传html/txt作为pdf格式,但这是行不通的。请做一个上传小文本文件的基本测试。使用示例代码,如果可以的话,可以一步一步地修改它。我上传了一个小的txt文件,得到了和上传pdf文件相同的错误。尝试上传txt/html,然后一旦上传完成,再尝试下载pdf格式的相同文件。我想你正在试图上传html/txt作为pdf格式,这是行不通的。