使用GhostScript.NET DPI打印问题打印PDF [英] Printing PDF using GhostScript.NET DPI printing issue

查看:1660
本文介绍了使用GhostScript.NET DPI打印问题打印PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 GhostScript.NET 打印PDF文件。
当我打印在96DPI的PDF打印好的,但有点模糊。
。如果我尝试打印在600DPI的文档时,打印极其放大的页面。

I am using GhostScript.NET to print a PDF. When I print it at 96DPI, the PDF prints fine, but is a little blurry. If I try to print the document at 600DPI, the page that prints extremely magnified.

using GhostScript.NET.Rasterizer;
using System.Drawing.Printing;

PrintDocument doc = new PrintDocument();
doc.PrinterSettings.PrinterName="<printer name>";
doc.PrinterSettings.Copies=(short)1;
GhostScriptRasterizer rasterizer = new GhostScriptRasterizer();
rasterizer.Open("abc.pdf");
//Image page = rasterizer.GetPage(96,96); <-- this one prints ok
Image page = rasterizer.GetPage(600,600);
doc.Graphics.DrawImage(page, new Point());

有一件事,我在看网页对象时注意到的是,虽然我通过GETPAGE()600, 600 - 返回的图像具有96 Horizo​​ntalResolution和96 VerticalResolution

One thing that I noticed when looking at the page object was that although I passed GetPage() 600, 600 - the image returned had a HorizontalResolution of 96 and a VerticalResolution of 96.

于是,我尝试了以下内容:

So I tried the following:

Bitmap b = new Bitmap(page.Width,page.Height);
b.SetResolution(600,600);
Graphics g = Graphics.FromImage(b);
g.DrawImage(page,0,0);
page = b; 

这有600和600 VerticalResolution一个Horizo​​ntalResolution,但打印的图像更大!

This has a HorizontalResolution of 600 and VerticalResolution of 600, but this printed the image even larger!

谁能给建议吗?

推荐答案

您好,我得到了同样的问题

hi i got the same Problem.

光栅只能放大到DPI ...

The Rasterizer only zoom to the dpi...

您必须使用GhostScriptProcessor。

you have to use the GhostScriptProcessor.

private List<string> GetImageWithGhostGhostscriptProcessor(string psFilename, string outputPath, int dip = 300)
    {
        if (!Directory.Exists(outputPath))
            Directory.CreateDirectory(outputPath);

        GhostscriptVersionInfo gv = GhostscriptVersionInfo.GetLastInstalledVersion(
            GhostscriptLicense.GPL | GhostscriptLicense.AFPL,
            GhostscriptLicense.GPL);

        using (GhostscriptProcessor processor = new GhostscriptProcessor(gv, true))
        {
            processor.Processing += new GhostscriptProcessorProcessingEventHandler(processor_Processing);

            List<string> switches = new List<string>();
            switches.Add("-empty");
            switches.Add("-dSAFER");
            switches.Add("-dBATCH");
            switches.Add("-dNOPAUSE");
            switches.Add("-dNOPROMPT");
            switches.Add(@"-sFONTPATH=" + System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts));
            switches.Add("-dFirstPage=" + 1);
            switches.Add("-dLastPage=" + 1);
            //switches.Add("-sDEVICE=png16m");
            switches.Add("-sDEVICE=tiff24nc");
            //switches.Add("-sDEVICE=pdfwrite");

            switches.Add("-r" + dip);
            switches.Add("-dTextAlphaBits=4");
            switches.Add("-dGraphicsAlphaBits=4");

            switches.Add(@"-sOutputFile=" + outputPath + "\\page-%03d.tif");
            //switches.Add(@"-sOutputFile=" + outputPath + "page-%03d.png");
            switches.Add(@"-f");
            switches.Add(psFilename);



            processor.StartProcessing(switches.ToArray(), null);
        }

        return Directory.EnumerateFiles(outputPath).ToList();
    }

这篇关于使用GhostScript.NET DPI打印问题打印PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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