简体   繁体   English

将 Word.docx 文件保存为 PDF 到 .NET - 如何保持图像质量

[英]Saving Word .docx Files as PDF through .NET - How to retain image quality

I am using the Word .NET API from powershell to bulk convert Word.docx files to PDF in powershell like so: I am using the Word .NET API from powershell to bulk convert Word.docx files to PDF in powershell like so:

$wordApplication = New-Object -ComObject Word.Application
$doc = $wordApplication.documents.open($infilename, $false)
$doc.SaveAs($outfilename, 17)

The word files have Images with QR codes in them, and the image quality is significantly worse in the PDF than in the original.docx. word文件中包含带有二维码的图像,PDF中的图像质量明显低于original.docx中的图像质量。 This is true on screen and when printing (the latter being my actual use case).在屏幕上和打印时都是如此(后者是我的实际用例)。

Is there any way to do this conversion (preferably without 3rd-party tools) in a way that the image quality is retained?有没有办法以保持图像质量的方式进行这种转换(最好没有第三方工具)?

Thanks in advance for any help!提前感谢您的帮助!

Best, eDude最好的,eDude

EDIT : Tried the Document.ExportAsFixedFormat2 method, thanks for the pointer, Unfortunately.编辑:尝试了Document.ExportAsFixedFormat2方法,感谢您的指针,不幸的是。 none of the option seem to make any difference on the end result, For reference: I tried:没有一个选项似乎对最终结果有任何影响,供参考:我试过:

    $doc.ExportAsFixedFormat2($outfilename,
                              17,        # file format (pdf)
                              $false,    # open after export
                              0,         # optimize for (print)
                              0,         # range (entire document)
                              1,         # from
                              1,         # to
                              0,         # export without markup
                              $false,    # include document properties
                              $true,     # keep IRM
                              0,         # create bookmarks (no)
                              $true,     # doc structure tags
                              $true,     # include missing fonts as bitmaps
                              $false,    # use ISO19005_1
                              $true      # optimize for image quality
    )

But it still washes out the qr code.但它仍然会洗掉二维码。 This is the case for both ISO19005_1 on and off.开启和关闭 ISO19005_1 都是这种情况。

In the word file, it looks like this:在word文件中是这样的:

word文件中的二维码

In the pdf, it comes out as:在 pdf 中,它出来为:

pdf文件中的二维码

It is really frustrating, none of the calls or options seem to make any difference to the outcome:@真是令人沮丧,没有一个电话或选项似乎对结果有任何影响:@

EDIT 2 : Could not get it to run.编辑 2 :无法让它运行。 In the end, I hacked around with the QR code generator code until it gave me svg files, which work fine both in.docx and PDF (screen and printer).最后,我修改了二维码生成器代码,直到它给了我 svg 文件,这些文件在 in.docx 和 PDF(屏幕和打印机)都可以正常工作。

Try to use the Document.ExportAsFixedFormat / ExportAsFixedFormat2 methods instead.尝试改用Document.ExportAsFixedFormat / ExportAsFixedFormat2方法。 They accept a bunch of parameters that allow setting up PDF documents properly.他们接受一堆允许正确设置 PDF 文档的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM