Here is the code I have right now:
Code: Select all
public void Format(ReportData reportData, System.IO.Stream outputStream) {
            /* Snip: build a FlowDocument containing the data specified in reportData */
            Stream xpsStream = new MemoryStream();
            using(Package package = ZipPackage.Open(xpsStream, FileMode.Create)) {
                using(XpsDocument xpsDoc = new XpsDocument(package)) {
                    XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
                    writer.Document.ColumnWidth = 400;
                    xpsWriter.Write(((IDocumentPaginatorSource)flowDocument).DocumentPaginator);
                }
            }
            xpsStream.Flush();  //probably not necessary, but just in case
            xpsStream.Seek(0, SeekOrigin.Begin);
            acPDFCreatorLib.Initialize();
            acPDFCreatorLib.SetLicenseKey("Evaluation Version Developer Pro", /*Snip: License Key Here*/);
            IacDocument pdfDocument = new IacDocument();
            Stream pdfStream;
            //Make sure the stream passed in supports seeking.  Otherwise,
            //we'll have to cache it into a MemoryStream and write to the
            //output stream afterwards.
            if(!outputStream.CanSeek) {
                pdfStream = new MemoryStream();
            } else {
                pdfStream = outputStream;
            }
            pdfDocument.Open(xpsStream, String.Empty);
            pdfDocument.Save(pdfStream, IacFileSaveOption.acFileSaveView);
            //If we wrote the PDF to a temporary stream, write the contents
            //of that stream to the output stream.
            if(pdfStream != outputStream) {
                pdfStream.Flush();
                outputStream.Write(((MemoryStream)pdfStream).GetBuffer(), 0, (int)((MemoryStream)pdfStream).Length);
            }
        }
