0

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

渲染旋转图像(文本也是图像)时,生成的 PDF 看起来不错,但打印时它的边缘参差不齐,而且通常混乱——见附件。

以下是相关代码:

// 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

4

1 回答 1

0

大约两年前,我遇到了类似的问题。生成的 PDF 在我打印时全部乱码。那只是一份报告,没有任何图像,但少了几个句子或单词。

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

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

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

这也应该可以通过调用 GhostScript 从 PDF 页面创建图像来使用 PDFSharp 。

于 2012-06-19T18:32:40.390 回答