Creating package reader from local path name

Dec 8, 2011 at 1:17 PM


I'm trying to create a package without using open dialog. It's working with open dialog but not like this :

FileInfo fi = new FileInfo(@"C:\xxx\TestDocument.xps");
Stream s = fi.OpenRead();
this.DataSource.PackageReader = new DefaultPackageReader(s);

So, do you know how to create a correct stream please ?

Dec 8, 2011 at 1:24 PM

You need to keep the stream open, remove the Close call. Document Toolkit needs access to an open stream to fetch the document parts. The underlying stream of a package reader is automatically closed when you change the value of the DataSource.PackageReader property (or when you dispose of the PackageReader yourself).

- koen

Dec 8, 2011 at 1:39 PM

Exactly, thank you very much !

Dec 30, 2011 at 1:30 PM



I need to open ( and view ) a PDF file stored on local file system. Can you help me to accomplish this task ?

Actually I wrote :

FileInfo fi = new FileInfo(@"C:\test.pdf");
                Stream s = fi.OpenRead();
                this.DataSource.PackageReader = new PdfDocumentReader(s);
I does not work ! :(
Pls help me, it's very important and urgent.

Tnx a lot


Dec 30, 2011 at 8:14 PM

What's the error message? Also keep in mind that the current PDF engine only implements parts of the PDF specification and errors may occur.

- Koen

Dec 30, 2011 at 8:47 PM

Hi Koen,


this.DataSource.PackageReader = new PdfDocumentReader(s);

pdf is correctly ( i hope ) loader into PackageReader, in fact, i can quickwatch it ( for example i see the correct number of page ).

When the method exits application goes in Appication_Exit event and rise:


Error Code :4004



I think this is not true, i think it's a sublayered error trapped in this one.


Can U help me via these infos ?


Tnx a lot,



Dec 30, 2011 at 9:29 PM

I Catch this message from the StackTrace, I hope is usefull to detect what is my error.

Could not load file or assembly 'System.Xml.Linq, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.   at FirstFloor.Documents.XpsDocument..ctor(IPackageReader , LoadXpsDocumentSettings )\n   at FirstFloor.Documents.IO.XpsClient.(IPackageReader , LoadXpsDocumentSettings )\n   at FirstFloor.Documents.IO.XpsClient..()\n   at FirstFloor.Documents.ComponentModel.AsyncOperationClient..(Object )\n   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)\n   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)\n   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()\n   at System.Threading.ThreadPoolWorkQueue.Dispatch()\n   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()


Tnx a lot,



Dec 30, 2011 at 9:37 PM

You need to reference System.Xml.Linq in your project, Document Toolkit depends on it.

Also, be aware of the fact that you can't access the C: root folder directly in SL4. There's a limited set of folders you may access. This limitation has been lifted in SL5. So, depending on the used SL version you may see a security error as well.

- Koen

Dec 30, 2011 at 9:45 PM

Tnx i solved with thi tips.

I have also a couple of questions for you.

1) Is it possible to remove the watermark from the renderd PDF ( I have to produce ASAP an important demo ) ?

2) I have on a pdf this kind of error: Failed to Render Page ( bold in red ). In stack trace I found ; '', hexadecimal value 0x01, is an invalid character.

It exists a way to avoid this kind of error ?





Dec 30, 2011 at 10:00 PM

The watermark is rendered by Document Toolkit evaluation version. To remove it, you'll need to purchase a license. More details at

The invalid character error is a known bug in the pdf parser. There is no known workaround at this moment, i'll need to fix this one.

- Koen