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// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6#import <OBJC/PDFNetOBJC.h>
7#import <Foundation/Foundation.h>
8
9void BulkConvertRandomFilesToXod();
10
11//---------------------------------------------------------------------------------------
12// The following sample illustrates how to convert PDF, XPS, image, MS Office, and
13// other image document formats to XOD format.
14//
15// Certain file formats such as PDF, generic XPS, EMF, and raster image formats can
16// be directly converted to XOD. Other formats such as MS Office
17// (Word, Excel, Publisher, Powerpoint, etc) can be directly converted via interop.
18// These types of conversions guarantee optimal output, while preserving important
19// information such as document metadata, intra document links and hyper-links,
20// bookmarks etc.
21//
22// In case there is no direct conversion available, PDFNet can still convert from
23// any printable document to XOD using a virtual printer driver. To check
24// if a virtual printer is required use Convert::RequiresPrinter(filename). In this
25// case the installing application must be run as administrator. The manifest for this
26// sample specifies appropriate the UAC elevation. The administrator privileges are
27// not required for direct or interop conversions.
28//
29// Please note that PDFNet Publisher (i.e. 'pdftron.PDF.Convert.ToXod') is an
30// optionally licensable add-on to PDFNet Core SDK. For details, please see
31// https://apryse.com/pricing.
32//---------------------------------------------------------------------------------------
33
34int main(int argc, char *argv[])
35{
36 @autoreleasepool {
37
38 int err = 0;
39 @try
40 {
41 [PTPDFNet Initialize: 0];
42 {
43 // Sample 1:
44 // Directly convert from PDF to XOD.
45 [PTConvert ToXod: @"../../TestFiles/newsletter.pdf" out_filename: @"../../TestFiles/Output/from_pdf.xod"];
46
47 // Sample 2:
48 // Directly convert from generic XPS to XOD.
49 [PTConvert ToXod: @"../../TestFiles/simple-xps.xps" out_filename: @"../../TestFiles/Output/from_xps.xod"];
50
51 // Sample 3:
52 // Convert from MS Office (does not require printer driver for Office 2007+)
53 // and other document formats to XOD.
54 BulkConvertRandomFilesToXod();
55 }
56 }
57 @catch(NSException *e)
58 {
59 NSLog(@"%@", e.reason);
60 err = 1;
61 }
62
63 NSLog(@"Done.");
64 [PTPDFNet Terminate: 0];
65 return err;
66 }
67}
68
69
70
71void BulkConvertRandomFilesToXod()
72{
73
74 NSArray* testFiles = @[@"butterfly.png", @"numbered.pdf", @"dice.jpg", @"simple-xps.xps"];
75
76 NSString *inputPath = @"../../TestFiles/";
77 NSString *outputPath = @"../../TestFiles/Output/";
78
79 int err = 0;
80
81 for(NSString* testFile in testFiles)
82 {
83 @try
84 {
85 NSString* outputFileName = [[[testFile lastPathComponent] stringByDeletingPathExtension] stringByAppendingPathExtension:@"xod"];
86 NSString *inputFilePath = [inputPath stringByAppendingPathComponent: testFile];
87 NSString *outputFilePath = [outputPath stringByAppendingPathComponent:outputFileName];
88 [PTConvert ToXod: inputFilePath out_filename: outputFilePath];
89 NSLog(@"Converted file: %@ to: %@", testFile, outputFileName);
90 }
91 @catch(NSException *e)
92 {
93 NSLog(@"Unable to convert file %@", testFile);
94 NSLog(@"%@", e.reason);
95 err = 1;
96 }
97 }
98
99 if( err ) {
100 NSLog(@"ConvertFile failed");
101 }
102 else {
103 NSLog(@"ConvertFile succeeded");
104 }
105}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6import PDFNet
7import Foundation
8
9//---------------------------------------------------------------------------------------
10// The following sample illustrates how to convert PDF, XPS, image, MS Office, and
11// other image document formats to XOD format.
12//
13// Certain file formats such as PDF, generic XPS, EMF, and raster image formats can
14// be directly converted to XOD. Other formats such as MS Office
15// (Word, Excel, Publisher, Powerpoint, etc) can be directly converted via interop.
16// These types of conversions guarantee optimal output, while preserving important
17// information such as document metadata, intra document links and hyper-links,
18// bookmarks etc.
19//
20// In case there is no direct conversion available, PDFNet can still convert from
21// any printable document to XOD using a virtual printer driver. To check
22// if a virtual printer is required use Convert::RequiresPrinter(filename). In this
23// case the installing application must be run as administrator. The manifest for this
24// sample specifies appropriate the UAC elevation. The administrator privileges are
25// not required for direct or interop conversions.
26//
27// Please note that PDFNet Publisher (i.e. 'pdftron.PDF.Convert.ToXod') is an
28// optionally licensable add-on to PDFNet Core SDK. For details, please see
29// https://apryse.com/pricing.
30//---------------------------------------------------------------------------------------
31
32func runWebViewerConvertTest() -> Int {
33 return autoreleasepool {
34 var err: Int = 0
35
36
37 do {
38 try PTPDFNet.catchException {
39 // Sample 1:
40 // Directly convert from PDF to XOD.
41 PTConvert.toXod(Bundle.main.path(forResource: "newsletter", ofType: "pdf"), out_filename: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("from_pdf.xod").path)
42
43 // Sample 2:
44 // Directly convert from generic XPS to XOD.
45 PTConvert.toXod(Bundle.main.path(forResource: "simple-xps", ofType: "xps"), out_filename: URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]).appendingPathComponent("from_xps.xod").path)
46
47 // Sample 3:
48 // Convert from MS Office (does not require printer driver for Office 2007+)
49 // and other document formats to XOD.
50 BulkConvertRandomFilesToXod()
51 }
52 } catch let e as NSError {
53 print("\(e)")
54 err = 1
55 }
56
57 print("Done.")
58 return err
59 }
60}
61
62func BulkConvertRandomFilesToXod() {
63 let testFiles = ["butterfly.png", "numbered.pdf", "dice.jpg", "simple-xps.xps"]
64
65 let inputPathURL: URL! = Bundle.main.resourceURL
66 let outputPathURL = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])
67
68 var err: Int = 0
69 for testFile: String in testFiles {
70 do {
71 try PTPDFNet.catchException {
72 let inputFilePath: String = inputPathURL.appendingPathComponent(testFile).path
73 let outputFilePath: String = outputPathURL.appendingPathComponent(testFile).appendingPathExtension("xod").path
74
75 PTConvert.toXod(inputFilePath, out_filename: outputFilePath)
76 print("Converted file: \(inputFilePath)\n to: \(outputFilePath)")
77 }
78 } catch let e as NSError {
79 print("Unable to convert file \(testFile)")
80 print("\(e)")
81 err = 1
82 }
83 }
84
85 if err != 0 {
86 print("ConvertFile failed")
87 } else {
88 print("ConvertFile succeeded")
89 }
90}
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales