首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在php中使用pdf2htmlEX转换pdf文件为html文件

如何在php中使用pdf2htmlEX转换pdf文件为html文件
EN

Stack Overflow用户
提问于 2015-03-10 16:43:08
回答 3查看 2.6K关注 0票数 0

如何在php中使用pdf2htmlEX转换pdf文件为html文件

以下是链接:

https://github.com/coolwanglu/pdf2htmlEX

如果有人知道请帮帮忙

提前谢谢。

EN

回答 3

Stack Overflow用户

发布于 2018-12-11 13:45:15

正致力于此,使其工作,共享代码,以便它可能会帮助某人:)

它需要在linux上安装pdf2htmlEX和pdftocairo才能工作。

代码语言:javascript
复制
$ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$allowedExt = array('pdf');
if (in_array(strtolower($ext), $allowedExt)) {
    $upload_file = time() . '.pdf';
    $upload_file = str_replace(' ', '_', $upload_file);
    if (!file_exists('upload_directory')) {
        mkdir('upload_directory', 0777, true);
    }
    if (move_uploaded_file($_FILES['file']['tmp_name'], 'upload_directory/' . $upload_file)) {
        $unq_no = 1; //Can be from database entry
        $file_name = $upload_file;
        $pdf_path = 'upload_directory/' . $file_name;
        $name = str_replace('.pdf', '', $file_name);
        $save_path = 'upload_directory/' . $unq_no;

        new Folder($save_path, true, 0777);
        $pdf_thumb_save_path = $save_path . '/' . $name;
        if (!file_exists($pdf_thumb_save_path)) {
            mkdir($pdf_thumb_save_path, 0777, true);
        }

        shell_exec("pdf2htmlEX --dest-dir $save_path --embed cfi --fit-width 760 --hdpi 72 $pdf_path");
        shell_exec("pdftocairo -png -singlefile  $pdf_path $pdf_thumb_save_path");

        if (file_exists($save_path . '/f1.woff')) {
            shell_exec("/path/rename_font.fs $save_path/f1.woff f1 $save_path/");
        }
        if (file_exists($save_path . '/f2.woff')) {
            shell_exec("/path/rename_font.fs $save_path/f2.woff f2 $save_path/");
        }
        if (file_exists($save_path . '/f3.woff')) {
            shell_exec("/path/rename_font.fs $save_path/f3.woff f3 $save_path/");
        }
        if (file_exists($save_path . '/f4.woff')) {
            shell_exec("/var/app/current/webroot/img/uploads/rename_font.fs $save_path/f4.woff f4 $save_path/");
        }
        if (file_exists($save_path . '/f5.woff')) {
            shell_exec("/path/rename_font.fs $save_path/f5.woff f5 $save_path/");
        }
        if (file_exists($save_path . '/f6.woff')) {
            shell_exec("/var/app/current/webroot/img/uploads/rename_font.fs $save_path/f6.woff f6 $save_path/");
        }
        if (file_exists($save_path . '/f7.woff')) {
            shell_exec("/path/rename_font.fs $save_path/f7.woff f7 $save_path/");
        }
        if (file_exists($save_path . '/f8.woff')) {
            shell_exec("/path/rename_font.fs $save_path/f8.woff f8 $save_path/");
        }


        $base_folder_path = 'uploads/pdfs/html/' . $unq_no . '/';

        $file_path = $base_url . $base_folder_path . $name . '.html';
        $css_path = $base_url . $base_folder_path . $unq_no . '/';
        chmod($pdf_thumb_save_path, 0777);
        $current_data = file_get_contents($file_path);
        $modified_data = str_replace('"stylesheet" href="', '"stylesheet" href="' . $css_path, $current_data);
        $file_handle = fopen($pdf_thumb_save_path . '.html', 'w');
        fwrite($file_handle, $modified_data);
        fclose($file_handle);
    }
}
票数 0
EN

Stack Overflow用户

发布于 2015-03-10 18:52:15

你看过维基了吗?

请参见示例:https://github.com/coolwanglu/pdf2htmlEX/wiki/Quick-Start

票数 -1
EN

Stack Overflow用户

发布于 2015-03-11 12:21:15

我使用了Scribd平台API,它很容易实现,而且效果很好。

Thnx

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28959276

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档