使用 wkhtmltopdf 从 URL 列表生成单个本地 PDF 的批处理文件
正如 @Mofi 在上一个问题<中所描述和解决的/a> 对于单个文件,我想使用 wkhtmltopdf 生成一个单个 PDF 文件,其中包含文本文件中 URL 列表中的内容。
Mofi 提供的下面的代码非常适合使用 URL 列表生成单独的 PDF
@echo off
cd /D "%ProgramFiles%\wkhtmltopdf\bin" || exit /B if
for /F useback^ delims^=^ eol^= %%I in ("%ProgramFiles%\wkhtmltopdf\bin\urls.txt") do wkhtmltopdf.exe "%%~I" "%ProgramFiles%\wkhtmltopdf\bin\pdfs\%%~nI.pdf"
pause
我认为通过使用以下代码(通过从 pdf 文件名部分中删除循环)它会起作用。但事实证明,PDF 文件不断地用它从 txt 文件处理的最后一个 URL 的文章重写自己。
@echo off
cd /D "%ProgramFiles%\wkhtmltopdf\bin" || exit /B if
for /F useback^ delims^=^ eol^= %%I in ("%ProgramFiles%\wkhtmltopdf\bin\urls.txt") do wkhtmltopdf.exe "%%~I" "%ProgramFiles%\wkhtmltopdf\bin\pdfs\master.pdf"
pause
我现在需要做的就是如何调整这段代码,以便当批处理文件从 urls.txt 文件读取 URL 时,生成一个 PDF 文件,该文件通过添加每个 URL 的内容而不断增大大小到这个单一的 PDF 中。
As described and solved by @Mofi in the previous question for individual files, I would like to use wkhtmltopdf to generate a single PDF file with the contents from a list of URLs within a text file.
The code below that Mofi provided works perfectly well for using the list of URLs to generate individual PDFs
@echo off
cd /D "%ProgramFiles%\wkhtmltopdf\bin" || exit /B if
for /F useback^ delims^=^ eol^= %%I in ("%ProgramFiles%\wkhtmltopdf\bin\urls.txt") do wkhtmltopdf.exe "%%~I" "%ProgramFiles%\wkhtmltopdf\bin\pdfs\%%~nI.pdf"
pause
I thought that by using the following code (by removing the loop from the pdf filename part) it would work. But it turned out that the PDF file kept rewriting itself with the article of the last URL it processed from the txt file.
@echo off
cd /D "%ProgramFiles%\wkhtmltopdf\bin" || exit /B if
for /F useback^ delims^=^ eol^= %%I in ("%ProgramFiles%\wkhtmltopdf\bin\urls.txt") do wkhtmltopdf.exe "%%~I" "%ProgramFiles%\wkhtmltopdf\bin\pdfs\master.pdf"
pause
What I need it do now, is just how to tweak this piece of code so as the batch file reads the URLs from the urls.txt file, there is a single PDF file generated which keeps growing in size by adding the contents of each URL into this single PDF.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要站点列表不超过变量的最大长度(8192 个字符),此操作就应该有效。如果名称的平均长度为 60 个字符,则站点的最大数量为 136。
This should work as long as the sites list does not exceed the max lenght for a variable (8192 characters). If the names have an average lenght of 60 characters, then the max number of sites is 136.