如何在.NET中打印高质量的.PDF文件? [英] How can I print high-quality .PDF files in .NET?

查看:174
本文介绍了如何在.NET中打印高质量的.PDF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在VB.NET中创建一个允许用户从文件夹中打印.PDF文件的函数。所述功能必须具有以下规格:

- 打印文件的质量必须与原始文件相同,不会降级。

- 用户必须能够在打印文件之前选择打印机并编辑打印设置。特别是双面打印是必须的。

- 程序必须正常工作,无论打印机的规格或用户安装的程序如何(此功能将成为需要安装的程序的一部分)在不同的计算机上,所以我不能对打印机的类型或用户是否有Adobe进行假设。

- 该功能在打印时不得打开其他程序。

- 该函数不能依赖于许可或付费的DLL。

我已经尝试过下面详述的方法,但它们都没有满足所有要求:我还搜索了许多不同的站点,但所有答案导致我已经尝试过的方法或建议使用第三方DLL。任何人都可以推荐我另一种方法,或者给我一个如何解决我已经尝试过的问题的建议?在此先感谢。



我尝试过:



方法我尝试了以下内容:



- 我尝试使用iTextSharp转换图像中的每个页面,然后使用PrintDocument打印所述图像。这种方法几乎满足所有规格,但是这种方式生成的图像与原版相比确实降级了,所以我不得不寻找另一种解决方案。



- 我尝试过使用ProcessStartInfo的代码与此类似,因此系统将使用默认打印程序执行任务:

I'm trying to make a function in VB.NET that allows the user to print a .PDF file from a folder. Said function must have the following specifications:
- The quality of the printed file must be the same as the original, with no degradation.
- The user must be able to select a printer and edit the print settings before printing the file. Duplex printing, in particular, is a must.
- The program must work properly, regardless of the printer's specifications or the user's installed programs (this function will be part of a program that will need to be installed on different computers, so I can't make assumptions on the type of printer, or whether the user has Adobe or not).
- The function must not open other programs while printing.
- The function must not rely on licensed or paid DLLs.
I've already tried the methods detailed below, but none of them met all the requisites: I've also searched many different sites, but all answers led to either a method I've already tried or a suggestion to use third-party DLLs. Can anyone recommend me an alternative method, or give me a suggestion on how to solve the issues with the ones I've already tried? Thanks in advance.

What I have tried:

The methods I've tried are the following:

- I've tried using iTextSharp to convert each page in an image, and then print said images using PrintDocument. This method met almost all specifications, but the images generated this way were really degraded compared to the original, so I had to look for another solution.

- I tried using ProcessStartInfo with code similar to this, so that the system would use the default print program for the task:

Using dialogPrint As New PrintDialog

    dialogPrint.AllowPrintToFile = True
    dialogPrint.AllowSomePages = True

    If dialogPrint.ShowDialog = DialogResult.OK Then
        Dim proc As New Process
        proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        proc.StartInfo.Verb = "PrintTo"
        proc.StartInfo.FileName = selectedFile
        proc.StartInfo.Arguments = """" & dialogPrint.PrinterSettings.PrinterName & """"
        proc.StartInfo.CreateNoWindow = True
        proc.StartInfo.UseShellExecute = True

        proc.Start()
        If Not proc.HasExited Then
            proc.WaitForExit(10000)
        End If

        proc.Close()

    End If

End Using

但是,此方法无法满足多种规格:不仅不允许我打印文件处于双工模式,但也会打开我每次尝试打印文档时都会使用Adobe。此外,由于该功能依赖于已经安装的程序,我不确定这种方法是否可靠。



- 我尝试使用此页面将文件直接发送到打印机。然而,这种方法太不可靠了:打印到文件时结果非常完美,但每当我尝试将文件发送到物理打印机时,它都没有打印任何内容。

This method, however, failed to meet several specifications: not only it doesn't allow me to print the file in duplex mode, but it also opens Adobe every time I try to print the document. Also, since the function relies on a program already installed, I'm not sure this method is necessarily reliable.

- I tried using the method described in this page to send the file directly to the printer. This method, however, was too unreliable: the result was perfect when printing to file, but whenever I tried sending the file to a physical printer, it didn't print anything.

推荐答案

如果没有可以读取和格式化内容的支持应用程序,则无法打印PDF文件;例如Acrobat Reader,Foxit等。或者您可以使用iTextSharp或类似的支持库编写自己的。打印功能的其余要求取决于用户站点上安装的打印机类型。
You cannot print a PDF file without some support application that can read and format the content; such as Acrobat Reader, Foxit etc. Or you could write your own using iTextSharp or similar support library. And the remaining requirements of the print features are dependent on the type of printer installed at the user's site.


这篇关于如何在.NET中打印高质量的.PDF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆