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;
}
Am I doing something wrong?
Thank you,
Mick