Click here to Skip to main content
15,442,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I created XPS document with the help of below code:
C#
XpsDocument xpsDocument = new XpsDocument(packageName, FileAccess.ReadWrite);

            XpsSerializationManager xpsSerializationManager = new XpsSerializationManager(new XpsPackagingPolicy(xpsDocument), false);

            DocumentPaginator documentPaginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;

            xpsSerializationManager.SaveAsXaml(documentPaginator);

            xpsDocument.Close();

Now I want to add some more data which is in another FlowDocument object to the same XPS document. Please let me know how to do it?
Posted
Updated 11-Sep-13 21:02pm
v2

1 solution

Hello,

If you already have 2 FlowDocuments then it is pretty easy.

All you need to do is add to the BlockCollection Blocks of your first flow document the Blocks of the second document.
Once merged export to XPS.

Here is a sample:

//create a flow document
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add("This is a bit of text");
FlowDocument document1 = new FlowDocument(paragraph);

//create another flow document
Paragraph paragraph2 = new Paragraph();
paragraph2.Inlines.Add("this is another one!");
FlowDocument document2 = new FlowDocument(paragraph2);

// append document2 to document1
for (int i = 0; i < document2.Blocks.Count; i++)
{
    document1.Blocks.Add(document2.Blocks.ElementAt(i));
}

//save to xps
XpsDocument xpsDocument = new XpsDocument(@"C:\temp\test.xps", FileAccess.ReadWrite);
XpsSerializationManager xpsSerializationManager = new XpsSerializationManager(new XpsPackagingPolicy(xpsDocument), false);
DocumentPaginator documentPaginator = ((IDocumentPaginatorSource)document1).DocumentPaginator;
xpsSerializationManager.SaveAsXaml(documentPaginator);
xpsDocument.Close();


Valery.
 
Share this answer
 
Comments
Udaya from Chennai 13-Sep-13 1:56am    
Thank you.. However my intention is to have both flow documents in single XPS so that page width of each flow document will be of different size. Like flow document 1 will be of portrait size and flow document 2 in landscape. Please suggest some solution to have different flow document sizes in single XPS document.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900