Question

I've seen some ABCpdf questions on this site but not this one yet. I am working on a project that requires PDF output with some rather specific options. ABCpdf seems to be able to offer this through their API but the documentation is confusing and/or incomplete.

using (var xpsStream = (MemoryStream)xps.Write(doc))
{
    xpsStream.Position = 0;
    pdfDoc.Clear();

    pdfDoc.Read(xpsStream, new XReadOptions
    {
        FileExtension = "xps"
    });

    pdfDoc.Rendering.DotsPerInch = 72;
    pdfDoc.Rendering.ColorSpace = XRendering.ColorSpaceType.Cmyk;
    pdfDoc.Rendering.IccCmyk = "device";

    pdfDoc.Save(stream);
}

This renders a PDF that does not come across with the set rendering properties. The documentation does state that in order to save the rendering properties they must be saved via the Save() method in the XRendering class. So I would have to do something like:

    pdfDoc.Rendering.DotsPerInch = 72;
    pdfDoc.Rendering.ColorSpace = XRendering.ColorSpaceType.Cmyk;
    pdfDoc.Rendering.IccCmyk = "device";
    pdfDoc.Rendering.Save("blah", stream);   // they want a "name" argument

The name argument in their documentation is described as "A dummy file name used to determine the type of image required." Later they say "The file name extensions which may be used are .TIF, .TIFF, .JPG, .GIF, .PNG, .BMP, .JP2, .EMF, .PS and .EPS."

Then after the latter version of the code runs, I do get output but it is not PDF, it is either TIF, JPG, or whatever I choose from that list. If I say 'mom.pdf' it throws an error. This is terrible because this is the way they beging the description of the Save() method in XRendering is "Use this method to render the PDF."

Was it helpful?

Solution

There are two different things here.

1) The Doc.Save method which saves the document in PDF, XPS or other similar document format.

2) The Doc.Rendering.Save which renders the current section of the current page to an image format like TIFF or JPEG.

The Doc.Rendering properties are used to control the rendering. Not saving the Doc.

For control over saving the Doc you want the Doc.SaveOptions.

You cannot mix and match the two.

So...

It seems to me from your code, that what you are trying to do is to import an XPS document and convert it to CMYK.

The way to do this is to change the color space of the document before you save it using Doc.Save.

To change the color space of the PDF you need to use the RecolorOperation class. This will allow you to change the color space of your document to RGB, CMYK, Grayscale, ICC / ICM or indeed whatever you fancy.

If I am wrong then presumably you want CMYK output in TIFF, JPEG, JPEG 2000, PSD or similar. To do that you need to use the doc.Rendering options to control the color space and bit depth (either 8 or 16 bits per component) and then call doc.Rendering.Save.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top