我有一个复杂的应用程序通过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 (逐个像素)并进行渲染,效果很好,但性能不佳。我需要找到一个更优雅的解决方案。
非常感谢!
发布于 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也可以做到这一点。
https://stackoverflow.com/questions/11105165
复制相似问题