[Solved] Problem Converting XPS Document

The PDF Creator enables you to create secure PDF documents and to view, print and process existing PDF documents.
If you have any questions about the installation and usage of the PDF Creator please post them here.
Post Reply
kpyancey
Posts: 7
Joined: Mon Dec 31 2007

[Solved] Problem Converting XPS Document

Post by kpyancey »

I'm evaluating the PDF Creator library for a project I'm working on. I can't reveal too much detail about the project itself, but the software I am writing essentially extracts data from a database based upon criteria specified in a request and outputs a report in one of several possible formats. I already have the code to generate the report as an XPS document, but I also need to support PDF. To do this, I was hoping to use PDF Creator to import the XPS Document, and then save it to a stream as a PDF (note that I'm using the non-gui version of the API).

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);
            }
        }
This code creates the XPS document correctly. The XPS Document varies in size from 5 pages to 50 pages. However, when I save it as a PDF, I get a 1 page document that has numerous overlapping red square outlines arranged diagonally. I have no idea why this would be. I've checked the code several times, and everything seems to work until I call pdfDocument.Open. After that call, according to the debugger, the number of pages in the pdfDocument are 1. So, I know at that point something has gone wrong. Can anyone give me an idea of what I'm doing wrong? :?
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello,

Which version of the PDF Creator are you using?

How are you creating the XPS documents? using which application?
Custom Brand the Amyuni PDF Printer Driver http://www.amyuni.com/en/developer/branding/index.html

Amyuni PDF Converter tested for true PDF performance. View results - http://www.amyuni.com/benchmark
kpyancey
Posts: 7
Joined: Mon Dec 31 2007

Post by kpyancey »

We're using the trial version of PDF Creator for .NET we downloaded from the company's site last Thursday.

The XPS documents are created in code using the .NET Framework 3.0 libraries. Specifically, we build a FlowDocument object, and then use the XpsDocumentWriter object to write the flow document as an XPS document.

I can save the XPS Document to a file and it opens fine, so I know it is valid. But, it doesn't seem that XPS Creator can read it.
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello,

In the latest version of the PDF Creator.Net I noticed a problem in opening XPS files. Opening XPS files using PDF Creator ActiveX is working properly.

I am going to check this issue with our Developers and will get back to you.
Custom Brand the Amyuni PDF Printer Driver http://www.amyuni.com/en/developer/branding/index.html

Amyuni PDF Converter tested for true PDF performance. View results - http://www.amyuni.com/benchmark
kpyancey
Posts: 7
Joined: Mon Dec 31 2007

Post by kpyancey »

Is there an older version available that I can use?
kpyancey
Posts: 7
Joined: Mon Dec 31 2007

Post by kpyancey »

Joan,

Did you find anything out?

Also, the red boxes appear to be a watermark that is supposed to read "Copyright Amyuni ...". The red boxes might indicate that a font is missing or something.

But, that still doesn't explain why I can't import the XPS document.

Sincerely,

Kevin P. Yancey
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello,

This issue is resolved and the new build is currently under testing.

Joanna
Custom Brand the Amyuni PDF Printer Driver http://www.amyuni.com/en/developer/branding/index.html

Amyuni PDF Converter tested for true PDF performance. View results - http://www.amyuni.com/benchmark
kpyancey
Posts: 7
Joined: Mon Dec 31 2007

Post by kpyancey »

Any idea when it will be available (a few days, weeks, or months)?
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

If you wish to have a release build it will be maximum for two months or maybe less.

If you wish to have a patch, you can contact support@amyuni.com and have a patch in 2 weeks maybe.

Hope this helps.
Custom Brand the Amyuni PDF Printer Driver http://www.amyuni.com/en/developer/branding/index.html

Amyuni PDF Converter tested for true PDF performance. View results - http://www.amyuni.com/benchmark
kpyancey
Posts: 7
Joined: Mon Dec 31 2007

Post by kpyancey »

I've sent a couple of emails asking about the patch over the past couple months, and there has been no reply.
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello,

Please forward me one of the e-mails you sent to forum@amyuni.com I will follow up on this with our Technical Team.
Custom Brand the Amyuni PDF Printer Driver http://www.amyuni.com/en/developer/branding/index.html

Amyuni PDF Converter tested for true PDF performance. View results - http://www.amyuni.com/benchmark
augur
Posts: 1
Joined: Wed Apr 23 2008

Post by augur »

Hello,
I am evaluating the PDF Creator for the purpose to convert .xps to .pdf and it seems that it still does not working for me. (I have downloaded the PDF Creator yesterday.)

I have tried this part of code mentioned here andeverything goes OK up to document.Open() and Save(), where the output stream is very short (590 bytes, compared to about 39000 bytes of xps stream) and saved pdf file cannot be opened by acrobat reader (it reports an error).

I have also tried to open xps from file, but document.Open() returns false there (without any other information). The xps file used is valid.
My code used:

Code: Select all

            outputStream = new FileStream("d:\\baarr.pdf", FileMode.Create);
            Stream xpsStream2 = new FileStream("d:\\xpsrr.xps", FileMode.Open, FileAccess.Read, FileShare.Read);
            //xpsStream = new FileStream("d:\\rrr.pdf", FileMode.Open);
            IacDocument pdfDocument2 = new IacDocument();
            licen = pdfDocument2.Open(xpsStream2, string.Empty);
            licen = pdfDocument2.Save(outputStream, IacFileSaveOption.acFileSaveAll);
            outputStream.Flush();
            outputStream.Close();
If I use the .pdf file for input instead of .xps, the conversion goes OK.
Have I missed something somewhere, please?

Thank you,

Tomas Hejny
Post Reply