首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用wkhtmltopdf和批处理文件中的其他选项加载多个html文件

如何使用wkhtmltopdf和批处理文件中的其他选项加载多个html文件
EN

Stack Overflow用户
提问于 2022-07-27 09:34:35
回答 1查看 192关注 0票数 0

我试图通过在批处理文件中使用wkhtmltopdf(ver0.12.6)将多个html文件组合成一个pdf文件,另外还有一些选项需要处理。

因为在运行批处理文件之前,我需要的html文件的数量可能会发生变化,所以我将所有这些文件都移动到一个文件夹中。因此,我的目标是加载文件夹中的所有html文件,添加一些我需要的选项,并调用wkhtmltopdf来生成pdf文件。

以下是我所做的:

代码语言:javascript
运行
复制
@echo off
setlocal
set TARGET=Result

:: go to the folder with lots of html files and one css file
cd .\myfolder

:: convert to a pdf file
wkhtmltopdf ^
--enable-local-file-access ^
--user-style-sheet %TARGET%_Report.css ^
(FOR %%A IN ("*.html") DO %%A) ^
%TARGET%_Report.pdf

cd..
pause

遗憾的是,它不能工作。我认为问题是我不能用这种方式使用FOR循环,但我不知道如何修复它。

这是错误信息。请给我一些建议,谢谢!

代码语言:javascript
运行
复制
Loading pages (1/6)
Error: Failed to load http:/, with network status code 3 and http status code 0 - Host  not found
Error: Failed loading page http: (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed to load http:/, with network status code 3 and http status code 0 - Host  not found
Error: Failed loading page http: (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed to load http:/, with network status code 3 and http status code 0 - Host  not found
Error: Failed loading page http: (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed to load http:/, with network status code 3 and http status code 0 - Host  not found
Error: Failed loading page http: (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed to load http://in/, with network status code 3 and http status code 0 - Host in not found
Error: Failed loading page http://in (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed to load http://do/, with network status code 3 and http status code 0 - Host do not found
Error: Failed loading page http://do (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: HostNotFoundError
EN

回答 1

Stack Overflow用户

发布于 2022-10-06 06:46:22

请试试我的代码

回声开启

对于/f "delims=“%a in ('dir /b /s "D:\source folder*.html‘),请执行"directorywkhtmltopdf\bin\wkhtmltopdf.exe”-s A4 %a "D:\OUTPUT DIRECTORY\pdf%%~na.pdf“

暂停回波

我试过这段代码,它可以工作。

但是,在result.pdf上的结果,您必须转到您的pdf文档的最后一页,以查看结果。

我仍然对结果感到困惑:我也许有更多的帮助

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

https://stackoverflow.com/questions/73135520

复制
相关文章

相似问题

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