我有一个通过 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(逐个像素)并进行渲染,效果很好,但性能使其不可行。我需要找到一个更优雅的解决方案。
非常感谢!