首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PDF渲染效果很好,但打印时边缘参差不齐- PDFSharp

问PDF渲染效果很好,但打印时边缘参差不齐- PDFSharp
EN

Stack Overflow用户
提问于 2012-06-20 00:18:57
回答 1查看 1.3K关注 0票数 0

我有一个复杂的应用程序通过PDFSharp生成PDF。我遇到了一个很难解决的问题。

旋转渲染图像(文本也是图像)时,生成的PDF看起来很好,但打印时边缘参差不齐,通常会弄乱--请参阅附件。

相关代码如下:

代码语言:javascript
复制
// determine how big the image should be
double destinationWidth = Math.Round(pageWidth * imageInfo.WidthFactor);
double destinationHeight = destinationWidth;

// rescale the image to needed size
imageInfo.Image = ImageHelper.ResizeImage(imageInfo.Image, (int)(destinationWidth * 3), (int)(destinationHeight * 3));

// get image
XImage xImage = XImage.FromGdiPlusImage(imageInfo.Image);

// define fill area
XRect destination = new XRect();
destination.X = imageInfo.XFactor * pageWidth;
destination.Y = imageInfo.YFactor * pageHeight;
destination.Width = destinationWidth; //pageWidth * imageInfo.WidthFactor;
destination.Height = destinationHeight; //destination.Width; // shouldn't this use the page height and height factor?

// save state before rotate
XGraphicsState previousState = gfx.Save();

// rotate canvas
gfx.RotateAtTransform(imageInfo.RotationAngle, new XPoint(destination.X + destination.Width / 2, destination.Y + destination.Height / 2));

// render image
gfx.DrawImage(xImage, destination);

// undo transforms
gfx.Restore(previousState);

求求你救救我。它可以在Chrome的PDF查看器中正常打印,这是值得的。

我尝试将图像转换为SVG (逐个像素)并进行渲染,效果很好,但性能不佳。我需要找到一个更优雅的解决方案。

非常感谢!

PDF:https://dl.dropbox.com/u/49564994/PDF.pdf

打印输出:https://dl.dropbox.com/u/49564994/Print.jpg

EN

回答 1

Stack Overflow用户

发布于 2012-06-20 02:32:40

大约两年前,我也遇到过类似的问题。当我打印一个生成的PDF时,它已经完全乱码了。这只是一份报告,没有包含任何图像,但缺少几个句子或单词。

我使用了Word模板,替换了一些占位符来生成报告,然后使用Office Save As PDF add-in将Word文档保存为PDF。

当您使用PCL打印机驱动程序或PostScript打印机驱动程序打印PDF时,会有所不同。如果你得到了它们之间的任何区别,请查看。可能是字体问题。检查字体编码是否设置正确。

当时我还没有找到解决方案。最后求助于将PDF转换为图像并将其发送到打印机。工作得很好。

使用invoking GhostScript to create images from PDF pages的PDFSharp也可以做到这一点。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11105165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档