Firefox :命令行下静默打印html/mht文件为pdf

本文介绍了如何在Firefox浏览器中通过命令行实现静默打印HTML和MHT文件为PDF。首先需要安装Firefox并设置为默认打印机为Adobe PDF,同时安装UnMHT和cmdlnprint扩展。在确保不打印页眉页脚并调整缩放比例后,通过`firefox -print`命令执行转换操作。
摘要由CSDN通过智能技术生成

Firefox :命令行下静默打印html/mht为pdf

 

准备:

1.    安装Firefox

2.    将Firefox的打印设置设为静默打印:

3.    Firefox中安装UnMHT扩展插件。

        因为mht文件是IE打包的文件,默认状态下Firefox不能打开mht文件。

4.    设置系统默认打印机为Adobe PDF,设置默认输出路径,不要打印页眉页脚

      

5.    为了防止字体太大,导致转成图片,不能复制文字。因此在打印的时候,在Firefox的打印中设置设为以30%比例打印。

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要将MHT文件转换为HTML文件,可以使用以下代码: ```java import java.io.*; public class Mht2Html { public static void main(String[] args) throws Exception { String mhtFile = "path/to/mht/file.mht"; String htmlFile = "path/to/html/file.html"; String line; BufferedReader reader = new BufferedReader(new FileReader(mhtFile)); BufferedWriter writer = new BufferedWriter(new FileWriter(htmlFile)); while ((line = reader.readLine()) != null) { if (line.startsWith("Content-Type:")) { String contentType = line.substring("Content-Type:".length()).trim(); if (contentType.equalsIgnoreCase("text/html")) { writer.write("<html>\n"); writer.write("<head>\n"); writer.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"); writer.write("</head>\n"); writer.write("<body>\n"); } } else if (line.startsWith("Content-Transfer-Encoding:")) { String encoding = line.substring("Content-Transfer-Encoding:".length()).trim(); if (encoding.equalsIgnoreCase("base64")) { reader.readLine(); // skip empty line String base64 = ""; while (!(line = reader.readLine()).equals("==")) { base64 += line; } byte[] bytes = Base64.getDecoder().decode(base64); String text = new String(bytes, "UTF-8"); writer.write(text); } } if (line.equals("") || line.equals("--")) { writer.write("</body>\n"); writer.write("</html>\n"); } } reader.close(); writer.close(); } } ``` 这个代码会解析MHT文件,将其中的HTML部分提取出来,并转换为HTML文件。你需要将代码中的`path/to/mht/file.mht`和`path/to/html/file.html`替换为你自己的文件路径。需要注意的是,这个代码中使用了`java.util.Base64`类,如果你的Java版本低于8,需要使用其他的Base64库替换。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值