XAML to PDF and back to XAML

Q:

We develop a WPF/XAML based document reporting product. We export our documents from XAML to XPS and then to PDF using another library, however we had some issues with this lib and are looking forward to switch to PDFTron which was successful in our tests.

I also want to check if we can use PDFNet for the following scenario:

  1. Create report in our tools → xaml representation of report seen as a canvas of a page for the user where she can move objects around and add/delete objects.

  2. Save xaml representation (FixedDocument) into a pdf.

  3. Later open the pdf and restore the (FixedDocument) into xaml representation

  4. Continue editing in xaml representation of report seen as a canvas of a page for the user where she can move objects around and add/delete objects.

Is this possible to achieve using PDFNet SDK?

A:

Yes, you can implement this type of workflow with PDFNet.

To convert Xaml/FixedDocument to PDF you would use pdftron.PDF.Convert.FromXps() - as shown in Xaml2Pdf sample project (http://www.pdftron.com/pdfnet/samplecode/Xaml2PdfTestCS.cs).

To preserve equitability of the document you could embed your XAML in the generated PDF (as a custom stream). For example:

pdftron.PDF.Convert.FromXps(doc, …);

StdFile embed_file = new StdFile(input_path + “my.xaml”, StdFile.OpenMode.e_read_mode);

FilterReader mystm = new FilterReader(embed_file);

doc.GetRoot().Put(“My XAML”, doc.CreateIndirectStream(mystm));

doc.Save(…)

Similarly you can extract the embedded XAML from PDF as follows

PDFDoc doc = new PDFDoc(…);

Obj xaml = doc.GetRoot().FindObj(“My XAML”);

if (xaml != null) {

Filter stm = xaml.GetDecodedStream();

FilterReader reader = new FilterReader(stm);

reader.Read(…); … extract embedded XAML …

}

For more samples how to work with low-level SDF API please see: http://www.pdftron.com/pdfnet/samplecode/SDFTest.cs