XPS to PDF and Gradient Color

The PDF Creator .NET Library enables you to create secure PDF documents on the fly and to view, print and process existing PDF documents. If you have any questions about PDF Creator .Net, please post them here.
Post Reply
mist83
Posts: 4
Joined: Fri Apr 23 2010

XPS to PDF and Gradient Color

Post by mist83 »

When I have an XPS file that has a gradient color in it, say for example a gradient from red to green, when I convert it to a PDF with the Amyuni library the entire gradient area is black (neither red or green). When it's solid, however, it shows up correctly.

Here is some sample code that reproduces the issue (hook up a button click event and add references as necessary). I create the XPS document in line with the code so it can be modified easily (for testing):

Code: Select all

private void Button_Click(object sender, RoutedEventArgs e)
{
    AmyuniTest();
}

private void AmyuniTest()
{
    // Initialize Amyuni stuff
    acPDFCreatorLib.Initialize();
    PDFCreator pdfCreator = new PDFCreator();

    // Create a temporary XPS file
    string tempFile = CreateXPSFile();
    string filename = null;

    // Open the XPS file and output it to a PDF
    using (FileStream fileStream = new FileStream(tempFile, FileMode.Open))
    {
        IacDocument document = new IacDocument();
        document.Open(fileStream, string.Empty);

        filename = tempFile.Replace(".tmp", ".pdf");
        using (Stream outputStream = new FileStream(filename, FileMode.Create))
        {
            document.Save(outputStream, IacFileSaveOption.acFileSavePDFA);
        }
    }

    // Free Amyuni resources
    acPDFCreatorLib.Terminate();

    // Preview the pdf output (created by Amyuni)
    Process.Start(filename);
}

// This method just creates an XPS file - it's not important to this post
public string CreateXPSFile()
{
    //Set up the WPF Control to be printed
    LinearGradientBrush linearGradientBrush = new LinearGradientBrush();
    linearGradientBrush.GradientStops.Add(new GradientStop { Color = Colors.Red, Offset = 0 });
    linearGradientBrush.GradientStops.Add(new GradientStop { Color = Colors.Green, Offset = 1 });
    Rectangle rectangle = new Rectangle { Fill = linearGradientBrush, Width = 792, Height = 612 };
    // Uncomment this line to verify that Amyuni processes the image correctly
    //rectangle = new Rectangle { Fill = Brushes.LimeGreen, Width = 792, Height = 612 };

    FixedDocument fixedDoc = new FixedDocument();
    PageContent pageContent = new PageContent();
    FixedPage fixedPage = new FixedPage { Width = rectangle.Width, Height = rectangle.Height };

    // Create first page of document
    fixedPage.Children.Add(rectangle);
    ((IAddChild)pageContent).AddChild(fixedPage);
    fixedDoc.Pages.Add(pageContent);

    string fileName = System.IO.Path.GetTempFileName();
    if (File.Exists(fileName)) File.Delete(fileName);

    XpsDocument xpsDocument = new XpsDocument(fileName, FileAccess.ReadWrite);
    XpsDocumentWriter xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
    xpsDocumentWriter.Write(fixedDoc);
    xpsDocument.Close();

    return fileName;
}
Also, I placed xmllite.dll in my bin directory when running this sample because the documentation said it was required, but it doesn't seem to make any difference. The output is the same when it is there and when it is not.

Am I doing something wrong?

Thank you,
Mick
mist83
Posts: 4
Joined: Fri Apr 23 2010

Re: XPS to PDF and Gradient Color

Post by mist83 »

Is this an issue, or am I doing something wrong?

Does this code produce the results that I received for anyone else?

Thank you,
Mick
Post Reply