使用html中的php在google drive中创建pdf文件

使用html中的php在google drive中创建pdf文件,php,pdf,google-drive-api,Php,Pdf,Google Drive Api,我有一个html格式,我希望它被创建为pdf在我的谷歌驱动器 示例这是我的html格式 <h1>Hello World</h1> <p>paragraph here... </p> 你好,世界 这里的段落 我希望它在我的谷歌硬盘上变成pdf格式,但我不知道怎么做。这是我的php使用GoogleDriveSDK的snip it代码 .... //Then, insert the file $file = new Google_DriveFile(

我有一个html格式,我希望它被创建为pdf在我的谷歌驱动器

示例这是我的html格式

<h1>Hello World</h1>
<p>paragraph here... </p>
你好,世界
这里的段落

我希望它在我的谷歌硬盘上变成pdf格式,但我不知道怎么做。这是我的php使用GoogleDriveSDK的snip it代码

....
//Then, insert the file
$file = new Google_DriveFile();
$file->setTitle( 'new_pdf' );
$file->setMimeType( 'application/pdf' );
$createdFile = $service->files->insert( $file, array(
    'data' => '<h1>Hello world!</h1><p>paragraph here... </p>',
    'mimeType' => 'text/plain',
));
....
。。。。
//然后,插入文件
$file=new Google_DriveFile();
$file->setTitle('new_pdf');
$file->setMimeType('application/pdf');
$createdFile=$service->files->insert($file,array)(
“数据”=>“你好,世界!这里的段落…

”, 'mimeType'=>'text/plain', )); ....
我的问题是如何将html格式应用于pdf内容


我试过这个,但是在我的google drive中,
test.pdf
文件坏了。

使用html2pdf类将数据转换为pdf我不认为我会使用html2pdf,我需要在google drive SDK创建的pdf中使用html格式。mimetype应该是text/html吗?您是否在创建google_驱动文件时添加了要传递的其他参数<代码>$file=新Google_服务_驱动器_驱动器文件()$文件->设置标题($title)$文件->设置描述($description)$文件->setMimeType($mimeType);//设置父文件夹。如果($parentId!=null){$parent=new Google_Service_Drive_ParentReference();$parent->setId($parentId);$file->setParents(array($parent));}模拟类型为application/pdf,我希望pdf文件的内容是html格式,以便易于阅读。
'mimeType'=>'text/plain'
将其更改为
'mimeType'=>'text/html'
使用html2pdf类将数据转换为pdf我不认为我会使用html2pdf,我需要在google drive SDK创建的pdf中使用html格式。mimetype应该是text/html吗?您是否在创建google_驱动文件时添加了要传递的其他参数<代码>$file=新Google_服务_驱动器_驱动器文件()$文件->设置标题($title)$文件->设置描述($description)$文件->setMimeType($mimeType);//设置父文件夹。如果($parentId!=null){$parent=new Google_Service_Drive_ParentReference();$parent->setId($parentId);$file->setParents(array($parent));}模拟类型为application/pdf,我希望pdf文件的内容为html格式,以便易于阅读。
'mimeType'=>'text/plain'
将其更改为
'mimeType'=>'text/html'