【发布时间】:2021-08-09 17:54:21
【问题描述】:
我有一个以 CMYK 格式保存的 tiff 文件,我正在将其加载到 WPF 中的图像中。然后,我将图像添加到文档中,并使用 Adobe PDF 打印驱动程序将其保存为 CMYK PDF。 PDF 文档中的图像不如原始图像鲜艳。我已经为 PDF 打印机尝试了许多设置,但均无济于事。据我所知,如果我在 RGB 颜色空间中保存到 PDF 中,颜色会被完美地保留。或者,我可以使用相同的 CMYK 图像在 Adobe Acrobat 中创建 CMYK PDF 文件,并且质量非常好。
我的猜测是,在 WPF 中加载图像和打印图像之间的某个地方,我得到了 RGB 像素,然后将其转换回 CMYK,丢失了原始颜色信息,但我真的不知道。当加载位图图像时,我可以在调试器中看到格式为 Cmyk32,因此可能图像控件、页面或文档在通过 XPS 时以 RGB 呈现它。我说不出来。有没有人有任何想法?这是我创建的用于显示问题的代码示例。
// select printer and get printer settings
PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() != true)
{
return;
}
LocalPrintServer ps = new LocalPrintServer();
// Get the default print queue
PrintQueue pq = ps.GetPrintQueue(printDialog.PrintQueue.FullName);
// create a document
FixedDocument document = new FixedDocument();
document.DocumentPaginator.PageSize =
new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);
// create a page
FixedPage page = new FixedPage
{
Width = document.DocumentPaginator.PageSize.Width,
Height = document.DocumentPaginator.PageSize.Height
};
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri("testcmyk.tif", UriKind.RelativeOrAbsolute);
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
bi.EndInit();
Image image = new Image
{
Source = bi
};
page.Children.Add(image);
PageContent content = new PageContent
{
Child = page
};
document.Pages.Add(content);
XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(pq);
xpsdw.Write(document, printDialog.PrintTicket);
我看到了一些关于在 WPF 中使用 CMYK 的其他问题,但我还没有找到这个确切的问题。我真的需要将 CMYK pdf 提交给专业的印刷公司,但是艺术品通过软件正在失去颜色。当 tiff 文件也具有透明度时,问题会变得更糟(看起来更糟)。
编辑
在尝试了各种方法来找出问题所在之后,我决定只保存 XPS 文件。在这样做的过程中,我发现了一些非常令人沮丧的事情。这是一个代码sn-p:
using (FileStream stream = new FileStream("test.xps", FileMode.Create))
{
Package package = Package.Open(stream, FileMode.Create);
using (XpsDocument xpsDoc = new XpsDocument(package, System.IO.Packaging.CompressionOption.NotCompressed))
{
XpsDocumentWriter xpsdw = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
xpsdw.Write(image);
}
}
我在这里传递与第一个代码 sn-p 相同的图像,只是为了看看 XpsDocumentWriter 将如何处理它。当我用 7zip 打开生成的 .xps 文件时,我发现原来的 tiff 文件已经不见了,并且已经被转换为 png!如果我正确理解了打印系统,我的原始 CMYK tiff 文件永远不会进入 pdf 打印机,因为它通过 XPS 系统到达那里。有什么补救措施吗? XPS有什么办法可以保留原图吗?是否甚至在这个阶段之前就出现了问题?请帮忙!
【问题讨论】:
标签: wpf pdf printing tiff cmyk