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// 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}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales