At the beginning you have to make sure that the "PDFreactor.dll" is available to your application. When hosting your .NET application via the Microsoft "Internet Information Service (IIS) Manager" the file should be located in the "bin" directory of the default "webApp".
Next you have to determine an appropriate page language which in this case would be "C#". Please refer to the example given below.
<%@ Page Language="C#" %>
In order to access the .NET API you have to import the following namespace:
<%@ import namespace="RealObjects.PDFreactor.Webservice.Client" %>
You can create a new PDFreactor instance now. Therefore you should store this instance in a new variable named similar to "pdfReactor". This variable will be used later on to convert your input document to the PDF document. Please refer to the example below.
PDFreactor pdfReactor = new PDFreactor();
Before you can create a PDF document using the PDFreactor .NET API you need to create the PDFreactor configuration object. All the information necessary about the resulting PDF is stored in this object.
RealObjects.PDFreactor.Webservice.Client.Configuration config =
new RealObjects.PDFreactor.Webservice.Client.Configuration(); config.Document = "<html><body><p>Hello World</p></body></html>"; config.Title = "Hello World sample"; config.ViewerPreferences.Add(ViewerPreferences.FIT_WINDOW); config.ViewerPreferences.Add(ViewerPreferences.PAGE_MODE_USE_THUMBS); Resource userStyleSheet = new Resource(); userStyleSheet.Content = "body {" + "margin: 1cm;" + "}"; config.UserStyleSheets .Add(userStyleSheet);
The example above describes the configuration object of a very simple "Hello World" document with the title "Hello World sample", a margin of 1cm on each side and some ViewerPreferences. It is of course possible to personalize the config object as needed. For further information about possible configuration properties please refer to the PDFreactor Manual.
Only the PDF conversion is left to successfully generate a PDF document using the PDFreactor .NET API. Therefore you could add something similar to the code snippet shown below to your .NET file.
try { // Render document and save result to result Result result = pdfReactor.Convert(config); if (result != null) { Response.ContentType = "application/pdf"; Response.BinaryWrite()result.Document); } } catch (PDFreactorWebserviceException e) { Result result = e.Result; Response.Write("<h1>An Error Has Occurred</h1>"); Response.Write("<h2>" + result.Error + "</h2>"); }
This code snippet performs a check whether the conversion was successful or not. If the conversion was unsuccessful an appropriate error warning will be displayed. For example a missing document property in the configuration object will trigger such an error message. If the conversion was successful the resulting PDF document will be displayed via the browsers PDF viewer plug-in.