WebViewer

These samples shows how to integrate PDFNet WebViewer into any HTML5, Silverlight, or Flash web application. The sample is using 'pdftron.PDF.Convert.ToXod()' to convert/stream PDF, XPS, MS Office, RTF, HTML and other document formats to WebViewer 'pdftron.PDF.Convert.ToXod()' is an optional Add-On to the Core SDK and is part of PDFNet WebViewer Publishing Platform.

1//
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3//
4
5using System;
6using System.Drawing;
7using System.Drawing.Drawing2D;
8
9using pdftron;
10using pdftron.Common;
11using pdftron.Filters;
12using pdftron.SDF;
13using pdftron.PDF;
14
15namespace WebViewerConvertCS
16{
17 /// <summary>
18 /// The following sample illustrates how to convert PDF, XPS, image, MS Office, and
19 /// other image document formats to XOD format.
20 ///
21 /// Certain file formats such as PDF, generic XPS, EMF, and raster image formats can
22 /// be directly converted to XOD. Other formats such as MS Office
23 /// (Word, Excel, Publisher, Powerpoint, etc) can be directly converted via interop.
24 /// These types of conversions guarantee optimal output, while preserving important
25 /// information such as document metadata, intra document links and hyper-links,
26 /// bookmarks etc.
27 ///
28 /// In case there is no direct conversion available, PDFNet can still convert from
29 /// any printable document to XOD using a virtual printer driver. To check
30 /// if a virtual printer is required use Convert::RequiresPrinter(filename). In this
31 /// case the installing application must be run as administrator. The manifest for this
32 /// sample specifies appropriate the UAC elevation. The administrator privileges are
33 /// not required for direct or interop conversions.
34 ///
35 /// Please note that PDFNet Publisher (i.e. 'pdftron.PDF.Convert.ToXod') is an
36 /// optionally licensable add-on to PDFNet Core SDK. For details, please see
37 /// https://apryse.com/pricing
38 /// </summary>
39 class Testfile
40 {
41 public string inputFile, outputFile;
42 public Testfile(string inFile, string outFile)
43 {
44 inputFile = inFile;
45 outputFile = outFile;
46 }
47 };
48
49 class Class1
50 {
51 // Relative path to the folder containing test files.
52 const string inputPath = "../../../../TestFiles/";
53 const string outputPath = "../../../../TestFiles/Output/";
54
55 static void BulkConvertRandomFilesToXod()
56 {
57 int err = 0;
58 System.Collections.ArrayList testfiles = new System.Collections.ArrayList();
59 testfiles.Add(new WebViewerConvertCS.Testfile("simple-powerpoint_2007.pptx", "simple-powerpoint_2007.xod"));
60 testfiles.Add(new WebViewerConvertCS.Testfile("simple-word_2007.docx", "simple-word_2007.xod"));
61 testfiles.Add(new WebViewerConvertCS.Testfile("butterfly.png", "butterfly.xod"));
62 testfiles.Add(new WebViewerConvertCS.Testfile("numbered.pdf", "numbered.xod"));
63 testfiles.Add(new WebViewerConvertCS.Testfile("dice.jpg", "dice.xod"));
64 testfiles.Add(new WebViewerConvertCS.Testfile("simple-xps.xps", "simple-xps.xod"));
65
66 foreach (Testfile file in testfiles)
67 {
68 try
69 {
70 if (pdftron.PDF.Convert.RequiresPrinter(inputPath + file.inputFile))
71 {
72 Console.WriteLine("Using PDFNet printer to convert file " + file.inputFile);
73 }
74
75 pdftron.PDF.Convert.ToXod(inputPath + file.inputFile, outputPath + file.outputFile);
76 Console.WriteLine("Converted file: " + file.inputFile + " to: " + file.outputFile);
77 }
78 catch (PDFNetException e)
79 {
80 Console.WriteLine("ERROR: on input file " + file.inputFile);
81 Console.WriteLine(e.Message);
82 err = 1;
83 }
84 }
85 if (err == 1) {
86 Console.WriteLine("ConvertFile failed");
87 } else {
88 Console.WriteLine("ConvertFile succeeded");
89 }
90 }
91
92 private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
93 static Class1() {}
94
95 /// <summary>
96 /// </summary>
97 [STAThread]
98 static void Main(string[] args)
99 {
100 PDFNet.Initialize(PDFTronLicense.Key);
101
102 // Sample 1:
103 // Directly convert from PDF to XOD.
104 pdftron.PDF.Convert.ToXod(inputPath + "newsletter.pdf", outputPath + "from_pdf.xod");
105
106 // Sample 2:
107 // Directly convert from generic XPS to XOD.
108 pdftron.PDF.Convert.ToXod(inputPath + "simple-xps.xps", outputPath + "from_xps.xod");
109
110 // Sample 3:
111 // Convert from MS Office (does not require printer driver for Office 2007+)
112 // and other document formats to XOD.
113 BulkConvertRandomFilesToXod();
114 PDFNet.Terminate();
115 Console.WriteLine("Done.");
116 }
117 }
118}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales