{"id":21899145,"url":"https://github.com/anhoder/office2pdf","last_synced_at":"2025-07-24T15:34:43.324Z","repository":{"id":56943646,"uuid":"142391116","full_name":"anhoder/office2pdf","owner":"anhoder","description":"office转换为pdf，计算office页数，基于COM","archived":false,"fork":false,"pushed_at":"2020-04-23T03:15:53.000Z","size":620,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-22T21:04:10.906Z","etag":null,"topics":["excel","office","office-pdf","pdf","php","ppt","word","wps"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anhoder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-26T05:05:35.000Z","updated_at":"2025-01-18T04:58:48.000Z","dependencies_parsed_at":"2022-08-21T07:50:38.729Z","dependency_job_id":null,"html_url":"https://github.com/anhoder/office2pdf","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/anhoder/office2pdf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhoder%2Foffice2pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhoder%2Foffice2pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhoder%2Foffice2pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhoder%2Foffice2pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anhoder","download_url":"https://codeload.github.com/anhoder/office2pdf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anhoder%2Foffice2pdf/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266862618,"owners_count":23996866,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["excel","office","office-pdf","pdf","php","ppt","word","wps"],"created_at":"2024-11-28T14:38:15.743Z","updated_at":"2025-07-24T15:34:43.298Z","avatar_url":"https://github.com/anhoder.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nOffice转PDF\n\n \u003e 该库基于Office(或WPS) COM组件，因此只支持Windows系统，其他系统可以考虑使用其他库，例如Open Office、PHPOffice。\n\n## 安装\n\n * Microsoft Office或WPS\n * PHP配置开启`com.allow_dcom = true`\n * PHP配置`extension=php_com_dotnet.dll`（PHP 5.4.5之前的版本自带，不需要开启）\n\n\n## 使用\n\n1. `composer require alanalbert/office2pdf`\n2. 包含composer的自动加载文件`autoload.php`\n3. 编写具体业务逻辑，如下（注意：Windows使用的中文编码为GBK，因此需要使用`iconv`函数进行编码转换）：\n\n\n```php\nrequire '../vendor/autoload.php';\n\n$source_path_utf8 = \"E:/测试.doc\";                           // Word文件路径\n$source_path = iconv('UTF-8', 'GBK', $source_path_utf8);\t// 转为GBK，防止中文乱码而找不到文件\n$output_path = $source_path . '.pdf';                       // PDF目标文件路径\n\n$office = new Office\\OfficeCOM();\n$office-\u003erun('word');\nvar_dump($office-\u003eword2Pdf($source_path, $output_path));\n$office-\u003eclose('word');\n```\n\n## 方法\n\n```php\n/*\n * @method boolean      run($type = 'all')                      运行应用, 参数: all|word|excel|ppt\n * @method boolean      close($type = 'all')                    关闭应用, 参数: all|word|excel|ppt\n * @method int|false    getPageNumFromDoc($file)                获取Word文档页数\n * @method int|false    getPageNumFromPpt($file)                获取PPT文档页数\n * @method int|false    getPageNumFromExcel($file)              获取Excel文档页数\n * @method int|false    getPageNumFromPdf($file)                获取PDF文件页数\n * @method boolean      word2Pdf($source_file, $output_file)    Word转PDF\n * @method boolean      excel2Pdf($source_file, $output_file)   Excel转PDF\n * @method boolean      ppt2Pdf($source_file, $output_file)     PPT转PDF\n */\n```\n\n## 更多\n\n如果需要使用更多功能，请参考[微软office开发文档](https://msdn.microsoft.com/vba/office-vba-reference)\n（适用于WPS）。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanhoder%2Foffice2pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanhoder%2Foffice2pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanhoder%2Foffice2pdf/lists"}