简体   繁体   English

将 CMYK tif 图像打印到 WPF 中的 CMYK pdf 会失去颜色

[英]Printing a CMYK tif image to a CMYK pdf in WPF loses color

I have a tiff file saved in CMYK, which I'm loading into an image in WPF.我有一个保存在 CMYK 中的 tiff 文件,我正在将其加载到 WPF 中的图像中。 I'm then adding the image to a document and saving it to a CMYK PDF using the Adobe PDF print driver.然后,我使用 Adobe PDF 打印驱动程序将图像添加到文档并保存到 CMYK PDF。 The Image in the PDF document is less vibrant than the original image. PDF 文档中的图像不如原始图像鲜艳。 I've tried many settings for the PDF printer to no avail.我尝试了 PDF 打印机的许多设置,但无济于事。 If I save to the PDF in an RGB color space, the color is preserved perfectly, as far as I can tell.据我所知,如果我在 RGB 颜色空间中保存到 PDF 中,颜色将被完美保存。 Alternatively, I can create a CMYK PDF file within Adobe Acrobat from the same CMYK image and the quality is perfect.或者,我可以使用相同的 CMYK 图像在 Adobe Acrobat 中创建 CMYK PDF 文件,并且质量非常好。

My guess is that somewhere between loading the image in WPF and printing the image, I'm getting RGB pixels, which are then converted back to CMYK, losing the original color information, but I really don't know.我的猜测是,在加载 WPF 中的图像和打印图像之间的某个地方,我得到了 RGB 像素,然后将其转换回 CMYK,丢失了原始颜色信息,但我真的不知道。 When the bitmap image is loaded, I can see in the debugger that the format is Cmyk32, so maybe the image control, the page or the document is rendering it in RGB when going through XPS.当 bitmap 图像加载时,我可以在调试器中看到格式为 Cmyk32,所以可能图像控件、页面或文档在通过 XPS 时以 RGB 呈现。 I can't tell.我说不出来。 Does anyone have any ideas?有没有人有任何想法? Here's a code sample I created to show the issue.这是我为显示该问题而创建的代码示例。

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

I have seen a few other questions about using CMYK in WPF, but I haven't found this exact issue.我已经看到了一些关于在 WPF 中使用 CMYK 的其他问题,但我还没有找到这个确切的问题。 I really need the CMYK pdf to submit to a professional print company, but the artwork is losing color going through the software.我真的需要 CMYK pdf 提交给专业的印刷公司,但是通过软件,艺术品正在失去颜色。 The problem gets worse (looks worse) when the tiff file also has transparency.当 tiff 文件也具有透明度时,问题会变得更糟(看起来更糟)。

Edit编辑

After trying out various things to track down where the problem is occurring, I decided to just save out the XPS file.在尝试了各种方法来追踪问题发生的位置之后,我决定只保存 XPS 文件。 In doing so, I found something quite disheartening.在这样做的过程中,我发现了一些非常令人沮丧的事情。 Here's a code snippet:这是一个代码片段:

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);
    }
}

I'm passing in the same image here as in the first code snippet just to see what the XpsDocumentWriter will do with it.我在这里传递了与第一个代码片段相同的图像,只是为了看看 XpsDocumentWriter 将用它做什么。 When I opened the resulting.xps file with 7zip, I discovered that the original tiff file was gone, and had been converted to a png, If I'm understanding the printing system correctly, my original CMYK tiff file never makes it to the pdf printer.当我用 7zip 打开生成的 .xps 文件时,我发现原来的 tiff 文件不见了,并且已经被转换为 png,如果我正确理解打印系统,我原来的 CMYK tiff 文件永远不会进入 pdf打印机。 as it goes through the XPS system to get there?因为它通过 XPS 系统到达那里? is there any remedy for this?有什么补救措施吗? Is there any way for XPS to retain the original image? XPS有什么办法可以保留原图吗? Is it perhaps even before this stage that the problem occurs?是否甚至在这个阶段之前就出现了问题? Please help!请帮忙!

If it is an option for you, you could consider using an Imaging Toolkit like the LEADTOOLS Imaging SDK which has classes for handling the CMYK color space.如果它适合您,您可以考虑使用像 LEADTOOLS Imaging SDK 这样的成像工具包,它具有处理 CMYK 颜色空间的类。 (Disclaimer: I am an employee of the vendor of this toolkit) (免责声明:我是此工具包供应商的员工)

The toolkit has a LoadCmykPlanes and SaveCmykPlanes methods that can be used to convert your TIFF image to a CMYK PDF without affecting the CMYK planes.该工具包具有LoadCmykPlanesSaveCmykPlanes方法,可用于将 TIFF 图像转换为 CMYK PDF 而不会影响 CMYK 平面。

The code for this is as follows:代码如下:

// take CMYK data from file inputCmykTiff and save it as PDF into file outputCmykPdf
Leadtools.Codecs.RasterCodecs codecs = new RasterCodecs();
Leadtools.RasterImage imageWithPlanes = codecs.LoadCmykPlanes(inputCmykTiff, 0, 1);
codecs.SaveCmykPlanes(imageWithPlanes, outputCmykPdf, RasterImageFormat.RasPdfCmyk, 8, 1, CodecsSavePageMode.Overwrite);

As the result will depend on your input images, I'd suggest testing with the free evaluation to see if this produces a good result.由于结果将取决于您的输入图像,我建议使用免费评估进行测试,看看这是否会产生良好的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM