Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Combining/Merging XPS files with F#
#r "ReachFramework.dll"
#r "WindowsBase.dll"
#r "PresentationFramework.dll"
#r "PresentationCore.dll"
#r "System.Xaml.dll"
#r "System.Printing.dll"
open System.Windows.Xps.Packaging
open System.Windows.Documents
open System.Windows.Markup
open System.IO
open System.IO.Packaging
The following code was translated from C#.
The original code can be found at
let AddXPSDocuments (sourceDocument : string) (seqNew : FixedDocumentSequence) =
let xpsOld = new XpsDocument(sourceDocument, FileAccess.Read)
let seqOld = xpsOld.GetFixedDocumentSequence()
for r in seqOld.References do
let newRef = new DocumentReference()
Background to box and :?>: Dynamic cast to Interface
((box newRef) :?> IUriContext).BaseUri <- ((box r) :?> IUriContext).BaseUri
newRef.Source <- r.Source;
let CreateXPSStream targetDocument list =
if File.Exists(targetDocument)
then File.Delete(targetDocument)
let container = Package.Open(targetDocument, FileMode.Create)
let xpsDoc = new XpsDocument(container)
let seqNew = new FixedDocumentSequence()
for sourceDocument in list do
AddXPSDocuments sourceDocument seqNew
let xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc)
let list = [|@"d:\FSharp\The F# Survival Guide\00.xps"
@"d:\FSharp\The F# Survival Guide\01.xps"
@"d:\FSharp\The F# Survival Guide\02.xps"
@"d:\FSharp\The F# Survival Guide\03.xps"
@"d:\FSharp\The F# Survival Guide\04.xps"
@"d:\FSharp\The F# Survival Guide\05.xps"
@"d:\FSharp\The F# Survival Guide\06.xps"
@"d:\FSharp\The F# Survival Guide\07.xps"
@"d:\FSharp\The F# Survival Guide\08.xps"
@"d:\FSharp\The F# Survival Guide\09.xps"
@"d:\FSharp\The F# Survival Guide\10.xps"
@"d:\FSharp\The F# Survival Guide\11.xps"
@"d:\FSharp\The F# Survival Guide\12.xps"
@"d:\FSharp\The F# Survival Guide\13.xps"
@"d:\FSharp\The F# Survival Guide\14.xps"
@"d:\FSharp\The F# Survival Guide\15.xps"
@"d:\FSharp\The F# Survival Guide\16.xps"
@"d:\FSharp\The F# Survival Guide\17.xps"|]
CreateXPSStream @"c:\The F# Survival Guide.xps" list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.