RasterEdge.NET Imaging SDK Developer s Guide

RasterEdge .NET Imaging SDK Developer’s Guide RasterEdge.DocImagingSDK 9.0 2015-4-15 Table of Contents Introduction..................................
Author: Juniper Rose
69 downloads 0 Views 834KB Size
RasterEdge .NET Imaging SDK Developer’s Guide

RasterEdge.DocImagingSDK 9.0

2015-4-15

Table of Contents Introduction.................................................................................................................... 8 About RasterEdge Document Imaging .................................................................................... 8 Deploy RasterEdge Imaging .................................................................................................. 10 Online Demo ......................................................................................................................... 10 Where to seek help .............................................................................................................. 11

Install SDK ................................................................................................................... 11 Install .................................................................................................................................... 11 F&Q ..................................................................................................................................... 11

License.......................................................................................................................... 14 Trial License ........................................................................................................................ 14 Purchase License ................................................................................................................... 14 Web Server License ........................................................................................................................ 14

HTML5 Document Viewer ........................................................................................... 15 Overview .............................................................................................................................. 15 Tutorial: Build Online Document Viewer .......................................................................... 16 Quick to Setup in IIS ...................................................................................................................... 16 F&Q .............................................................................................................................................. 16 Quick to Start ................................................................................................................................. 17 Setup Your ASP.NET Website in Visual Studio ......................................................................... 17 Add Document Viewer to Your ASPX Web Page ....................................................................... 18 Load and Display Your File in Document Viewer Control .......................................................... 21 Navigation ................................................................................................................................. 21 Draw Annotation........................................................................................................................ 22 Load and Save Annotation ......................................................................................................... 22 Save, Print, and Convert Your File ............................................................................................. 22 Deploy Your Project on IIS ........................................................................................................ 23 F&Q .......................................................................................................................................... 23 Advanced Settings.......................................................................................................................... 23 Document Viewer Width & Height ............................................................................................ 24 Display Format .......................................................................................................................... 24 View File from Your Content Management System .................................................................... 24 Annotations ............................................................................................................................... 25

Delete Cache Files ..................................................................................................................... 25

WinForm Document Viewer......................................................................................... 26 WinViewer Overview..................................................................................................................... 26 Feature List ................................................................................................................................ 26 Control APIs .............................................................................................................................. 26 Add a WinViewer to Your Project .................................................................................................. 27 Setting Up Your Project ............................................................................................................. 27 Open File from Specified Path .................................................................................................... 28 Draw Specified Annotation on Page ........................................................................................... 30 Customize WinViewer Control ....................................................................................................... 31 Customize Toolbar ..................................................................................................................... 31 Customize Annotation Style ....................................................................................................... 31 Customize the Way Open and Store Files ................................................................................... 33 Customize the Drop-down List ................................................................................................... 34

Programming with RasterEdge Document Imaging SDK ............................................ 35 Overview .............................................................................................................................. 35 Register Process ................................................................................................................... 37 TIFF ..................................................................................................................................... 38 TIFF File Overview........................................................................................................................ 38 Requirements ................................................................................................................................. 38 TIFF Programming Classes ............................................................................................................ 38 Construct, Load and Save a TIFFDocument ................................................................................... 39 Load or Create a TIFFDocument ................................................................................................ 39 Save a TIFF File ........................................................................................................................ 40 Clear Temp files generated in the process ....................................................................................... 40 Get preview of Tiff Document ....................................................................................................... 40 TIFF Rendering and Conversion ..................................................................................................... 41 Convert TIFF Document to Image Files...................................................................................... 41 Convert TIFFPage to Image File ................................................................................................ 41 Convert TIFFPage to Bitmap...................................................................................................... 42 Convert TIFFDocument to PDF ................................................................................................. 42 TIFF Annotation ............................................................................................................................ 43 Editing TIFF Metadata................................................................................................................... 44 Add, Delete, Update and Find a TIFF Field ................................................................................ 44 Add ,Delete ,Update and Find a EXIF Field ................................................................................ 45 Add ,Delete ,Update and Find a IPTC Field ................................................................................ 46 Get the XML Information .......................................................................................................... 46 Editing TIFF Document ................................................................................................................. 47 Re-Order Pages of TIFF File ...................................................................................................... 47 Swap two pages of TIFF File..................................................................................................... 47 Insert Pages to TIFF File ............................................................................................................ 47 Delete Pages from TIFF File ...................................................................................................... 47 Split TIFF File ........................................................................................................................... 48

Combine TIFF File .................................................................................................................... 48 Generate Barcode on TIFF ............................................................................................................. 48 Read Barcode Information from TIFF............................................................................................. 49 How to ........................................................................................................................................... 49 How to View Thumbnail Image of a TIFF Document ................................................................. 50 How to Generate Magnified Images of TIFFDocument ............................................................... 50 How to Add Watermark onto TIFF Document ............................................................................ 51

PDF ...................................................................................................................................... 53 Introduction to PDF Functions ........................................................................................................ 53 About PDF Programming Classes................................................................................................... 53 PDFDocument Object .................................................................................................................... 53 Get preview of PDF Document ....................................................................................................... 54 Save PDFDocument to File or Stream............................................................................................. 54 PDF Rendering and Conversion..................................................................................................... 55 Convert PDFDocument to Images ............................................................................................. 55 Convert a PDFPage to Image File............................................................................................... 55 Convert PDFPage to Bitmap ...................................................................................................... 56 Convert PDF to SVG ................................................................................................................. 57 Convert PDF Document to TIFF ................................................................................................ 58 Convert Other Document Types to PDF File............................................................................... 58 PDF Annotations............................................................................................................................ 59 Create Barcode in PDF ................................................................................................................... 59 Read Barcode from PDF................................................................................................................. 60 How to’s ........................................................................................................................................ 61 How to: Create an Image-only PDF Document ........................................................................... 61 How to: Create Thumbnail of PDF Document ............................................................................ 61 How to: Add WaterMark to PDFPage......................................................................................... 62 Introduction to Word Functions ...................................................................................................... 63 .docx and .doc file formats ............................................................................................................. 63 Load and Save Word Document ..................................................................................................... 63 About Word Programming Classes ............................................................................................. 63 Word Document Object.............................................................................................................. 64 Load Word document................................................................................................................. 64 Save Word Document ................................................................................................................ 65 Get preview of word Document ..................................................................................................... 65 Annotations on Word Document..................................................................................................... 65 Word Rendering and Conversions................................................................................................. 66 Convert DOCXDocument to Images .......................................................................................... 66 Convert DOCXPage to Image File.............................................................................................. 66 Convert DOCXPage to Bitmap................................................................................................... 67 Convert DOCXDocument to PDF or TIFF File ........................................................................... 68 Convert Word to SVG ................................................................................................................ 68 Create Barcode in Word ................................................................................................................. 69 Read Barcode from Word ............................................................................................................... 70 How to’s ........................................................................................................................................ 71

How to: Create Thumbnail of DOCXDocument.......................................................................... 71

Excel..................................................................................................................................... 72 Introduction to Excel Functions ...................................................................................................... 72 .xlsx and .xls file formats................................................................................................................ 72 About Excel Programming Classes ................................................................................................. 72 Excel Document Object .................................................................................................................. 73 Load Excel Document .................................................................................................................... 73 Save Excel Document .................................................................................................................... 73 Get preview of Excel Document .................................................................................................... 74 Annotations on Excel Document..................................................................................................... 74 Excel Rendering and Conversions .................................................................................................. 75 Convert XLSXDocument to Images ........................................................................................... 75 Convert XLSXPage to Image File .............................................................................................. 75 Convert XLSXPage to Bitmap.................................................................................................... 76 Convert XLSXDocument to PDF or TIFF File............................................................................ 77 Convert Excel To SVG .............................................................................................................. 77 Create Barcode in Excel ................................................................................................................. 78 Read Barcode from Excel ............................................................................................................... 79 How to’s ........................................................................................................................................ 80 How to: Create Thumbnail of Excel............................................................................................ 80

PowerPoint .......................................................................................................................... 81 Introduction to PoinerPoint Functions ............................................................................................. 81 .pptx and .ppt file formats ............................................................................................................... 81 About PowerPoint Programming Classes ........................................................................................ 81 PowerPoint Document Object ......................................................................................................... 82 Load PowerPoint Document ........................................................................................................... 82 Save PowerPoint Document ........................................................................................................... 82 Get preview of Powerpoint Document ........................................................................................... 83 Annotations on PowerPoint Document ........................................................................................... 83 PowerPoint Rendering and Conversions ........................................................................................ 84 Convert PPTXDocument to Images ............................................................................................ 84 Convert PPTXPage to Image File ............................................................................................... 84 Convert PPTXPage to Bitmap .................................................................................................... 85 Convert PPTXDocument to PDF or TIFF File ............................................................................ 85 Convert PPTX To SVG .............................................................................................................. 86 Create Barcode in PowerPoint ........................................................................................................ 87 Read Barcode from PowerPoint ...................................................................................................... 88 How to’s ........................................................................................................................................ 88 How to: Create Thumbnail of PowerPoint Document .................................................................. 88

DICOM ................................................................................................................................ 90 DICOM Overview.......................................................................................................................... 90 Programming with DICOM ............................................................................................................ 90 Load DICOM File .......................................................................................................................... 90 Convert DICOM to Image files...................................................................................................... 90

Convert DICOM to Bitmap ............................................................................................................ 92 Convert Dicom to Tiff or PDF file ................................................................................................. 92

JBIG2................................................................................................................................... 94 JBIG2 Codec Overview .................................................................................................................. 94 Feature List .................................................................................................................................... 94 How to Decode an JBIG2 Image..................................................................................................... 94

JPEG 2000 ........................................................................................................................... 95 JPEG 2000 Codec Overview .......................................................................................................... 95 Feature List .................................................................................................................................... 95 How to Decode a JPEG 2000 Image ............................................................................................... 95

RasterEdge OCR ................................................................................................................. 96 OCRHandle ................................................................................................................................... 96 OCRRecSetting .............................................................................................................................. 96 class OCRPage............................................................................................................................... 97 Multi-Language support ................................................................................................................. 97 Source Preparation ......................................................................................................................... 98 PDF and TIFF files OCR .............................................................................................................. 100 Image OCR .................................................................................................................................. 100 Zone Scanning ............................................................................................................................. 101 Exception: Resource Dictionary Preparation failed........................................................................ 102

RasterEdge RasterImage .................................................................................................. 103 RasterImage Overview ................................................................................................................. 103 Requirements ............................................................................................................................... 103 About RasterImage Programming Classes .................................................................................... 103 Convert Image ............................................................................................................................. 103 Load Image .................................................................................................................................. 104 Image Process .............................................................................................................................. 105

Programming with Images ......................................................................................... 106 Overview ............................................................................................................................ 106 Image Concept ................................................................................................................... 108 REImage, the Core Programming Class for Images ....................................................................... 108 Image Data................................................................................................................................... 108 Image Compressions .................................................................................................................... 108 Why Compression .................................................................................................................... 108 Types of Compression .............................................................................................................. 108 Image Codecs............................................................................................................................... 109 Supported Formats ................................................................................................................... 109

REImage the Core Image Class in RasterEdge Imaging SDK......................................... 110 Introduction ................................................................................................................................. 110 Requirements ............................................................................................................................... 110 How to Create REImage ............................................................................................................... 110

Create REImage from Image File, Stream & Byte Array ........................................................... 110 Create Image from Bitmap ....................................................................................................... 111 Imaging Conversion ..................................................................................................................... 111 Annotate on REImage .................................................................................................................. 111 Save REImage ............................................................................................................................. 112 Image Convert ............................................................................................................................. 112 How to Convert Between Raster Images ................................................................................... 113 How to Convert Raster Images to PDF or TIFF ........................................................................ 113

ImageProcessing ................................................................................................................ 115 Annotations........................................................................................................................ 116 Introduction to Annotations .......................................................................................................... 116 Requirements ............................................................................................................................... 117 Generate an AnnotationObject ...................................................................................................... 117 Burn Annotation to Document or Image ....................................................................................... 118 How to Burn Annotation Object to Document (PDF, TIFF, WORD, EXECEL, PPT) ................ 118 How to Burn Annotations on Imgaes ........................................................................................ 119 Annotations on ASP.NET DocumentViewer or Windows Form DocumentViewer ........................ 120 Annotation Assemblies................................................................................................................. 120

Metadata ............................................................................................................................ 122 Introduction to Metadata .............................................................................................................. 122 Supported Metadata Types ....................................................................................................... 122 Image Formats Supporting Metadata ........................................................................................ 123 EXIF Metadata............................................................................................................................. 123 Parse Exif Metadata from TIFF File ......................................................................................... 123 Embed Exif to TIFF ................................................................................................................. 123 Parse & Update Exif from File ................................................................................................. 123 XMP ............................................................................................................................................ 124

Barcode Read .................................................................................................................... 125 How to’s ...................................................................................................................................... 125 How to: Read Barcode from Image........................................................................................... 125 How to: Read Barcode from Document .................................................................................... 126 Advanced ReaderSettings ............................................................................................................. 128

Barcode Create .................................................................................................................. 129 How to’s ...................................................................................................................................... 129 How to: Draw Barcode on Image.............................................................................................. 129 How to: Create Barcode and Save as Image .............................................................................. 131 Advanced Settings ................................................................................................................... 132

TWAIN Scanning .............................................................................................................. 140 TWAIN Scanning Overview......................................................................................................... 140 Acquisition .............................................................................................................................. 140 TWAINDevice......................................................................................................................... 140 Getting Started with RETwain ...................................................................................................... 140 Setting Up Events .................................................................................................................... 141

Getting and Setting Properties .................................................................................................. 141 How to’s ..................................................................................................................................... 142 How to Do Console Based Scanning ........................................................................................ 142 How to Scan Many Pages into a PDF or TIFF file..................................................................... 143

Licensing RasterEdge Imaging ......................................................................................... 146 Purchasing License....................................................................................................................... 146

Introduction About RasterEdge Document Imaging RasterEdge Document Imaging is a powerful document imaging SDK and controls. With easy to use document imaging APIs, user can implement functions of loading, saving, converting, annotating and editing documents and images files. Supported Document formats include TIFF, PDF, Microsoft Word, Excel, PowerPoint and DICOM. Png, Jpeg, gif, Bitmap among other commonly used image formats are supported as well. The toolkit also includes a Windows Forms control library, a Zero footprint ASP.NET AJAX-Enabled Server-Side document Viewer, and a Twain library for Twain scanning. Annotation module is embedded in both Windows Form and ASP.NET Web Form controls. Please try our online demo at http://www.rasteredge.com/dotnetimaging/web-viewer-demo/ The product feature includes: Create document object from file, stream or byte array. Create PDF or TIFF using image source obtained from file, data base or scanning process. Load and parse Microsoft Word, Excel, and PowerPoint from file, stream Display PDF, TIFF, Word, Excel and PowerPoint with customized options. Batch conversion from supported documents to various image formats, such as JPEG, PNG, and GIF. Convert (print) TIFF, PDF, Microsoft Word, Excel, PowerPoint, and DICOM into PDF file format.

Generate thumbnails image of document by setting zoom factor or resolution. Draw and burn annotations on documents and images. Advanced Windows Form control to load, display, annotate, OCR and save above document formats. Zero footprint WebForms document viewer controls to load, display, annotate, convert, search and save above document formats with featured AJAX technology. Add or scan barcode image from documents. Add image (logo or watermark) to specified page in document. Document processing like inserting, deleting, and reordering PDF document pages or TIFF pages in multipage TIFF. APIs to combine, split, extract TIFF and PDF documents or pages and enable batch operations on document collection.

Deploy RasterEdge Imaging Because RasterEgde Imaging toolkit is a collection of assemblies, you need to add reference to specific assemblies in your project to use the APIs provided. To add reference to RasterEdge Imaging assemblies in your project using Visual Studio: a. In the Solution Explorer, right-click on References, and click Add Reference. You download from our server. b. Click the browse menu tab to locate RasterEdge.DocImageSDK8.x\Bin c. Choose dlls that you want to use in your project. d. Add using statement at the top of the code, for example using RasterEdge.Imaging.Basic;

Online Demo Using RasterEdge document sdk, you can build a project to enable document viewing, annotating, converting, and saving. We develop an online document viewer program to illustrate these features. You can not only try using our demo documents but upload your own documents as well. See the demo at http://www.rasteredge.com/dotnet-imaging/web-viewer-demo/

Where to seek help If you have any question, problems or concerns about RasterEdge products, please contact us at [email protected] or you can leave a message at our forum at forum.rasteredge.com

Install SDK Install RasterEdge SDK is designed to be easy to use. So no installation process is needed.

F&Q 1. Q: error: Cannot find RasterEdge name space occurs when adding reference A: right click on projects, select properties, under application tab, change target framework to frameworks other than Client Profile version. Rebuild you application 2. Q: Exception of assembly discripency occurred. A: Please check if your project setting matches the dll you referenced. If you are using an x64 operating system and choose AnyCPU as target platform, you should reference x64 dlls in the SDK Package.

3. Q: Exception of registered error thrown in run time. E.g. Image encoder TIFF is not registered A:

First please make sure that you download the latest version of the SDK at RasterEdge.com Then please add the line of code WorkRegistry.Reset() before you use RasterEdge dlls APIs, This code register all RasterEdge dlls referenced to your projects. This code need only to run only once. Please make sure that you have already referenced correct dlls to your project. For example if you want to convert word to pdf, you should add both pdf and word dlls to your project. If the problem persists, please check if the dll in your bin folder is blocked by your OS. Right click on the dlls, and select properties, then click unblock button.

After unblock all of the dlls you used, make sure to add reference to the unblocked ones and rebuild the project. If possible, move your project to hard drive other than C drive where you might not have the authority to read and write assembly files.

If the problem still yet solved, please see the following: If your project is a console or winform application. Make sure that the dlls you referenced are in the same folder as the .exe application. Or if it is an asp.net project, please make sure that the dlls you referenced are retrievable in the Bin folder of your asp.net project. Namely the dlls should be located under the path which is the result of this statement. string projectName = HttpRuntime.AppDomainAppPath.Replace("\\", "/") + "/Bin/";

If there is no such path/directory existed, please create one and copy paste dlls accordingly.

If you have any other questions or concerns about RasterEdge product, you can contact us [email protected].

4. Q: Error load program with incorrect format

A: This is often caused by incompatibility between plantform target property and the dlls build. Right click on projects and select properties. In build tab select proper platform target.

5. Q: In Asp.net project when testing web viewer control, get the error: Could not load file or assembly 'RasterEdge.Imaging.Annotation' or one of its dependencies. An attempt was made to load a program with an incorrect format. A: This is because Visual Studio uses a 32-bit web server internally. You can first debug with x86 webviewer dlls in Visual Studio which mimic IIS environment. Once done debugging with x86 dlls in Visual Studio, replace the x86 with x64 version of dlls and deploy the project to the IIS on the servers. 6. Q: When testing web viewer control, I can’t upload document successfully A: Don’t add reference to SVGWebViewer.dll to your project. Make sure the Default page to start is the Default.aspx. Append /Default.aspx in the address bar if necessary

License Trial License For users to better evaluate our Document Imaging toolkit, activation of trail license is not needed at user side. The trial license will be automatically expired 45 days after your first trial of the SDK functions. You can then request an extension of another 30 days by contacting us at [email protected].

Purchase License After you purchase the Developer License, we will send you a set of activated assemblies. For more information, please contact us at [email protected]. Web Server License If you want to deploy your projects which use our dlls on a server, you should buy a server license. For more information, please contact us at [email protected].

HTML5 Document Viewer Overview The Web Document Viewer for ASP.NET adopts the latest HTML5 technology and owns strong compatibility with most modern web browser environments. It is a JavaScript based image viewing control that can be created on the client side without additional add-ins and communicates directly with a WebHandler on the service side. A complete example of Web Document Viewer is included in the RasterEdge.DocImageSDK demo projects in download package. You can create Web Document Viewer with your own style, please see our “Quick to start” below, which is a step-by-step tutorial.

Product features: Support View, Annotate, Save, OCR, search and Convert various document file formats. Flexible annotations enable collaboration at ease. Zero footprint viewer no addition plug-in is needed. Supported Tiff, Pdf, Office word, excel, ppt, Dicom among other document and image formats. Wide range of web browsers support including IE9+, FireFox, Chrome, Safari, Opera Secured document displaying mechanism. The original document stay safe behind protection in server, only shallow copy of the documents is transmitted on the network for displaying purpose. Cache is implemented to avoid repeated process and transmission of original document files therefore maximizes the throughput of the system. The cached files are cleaned automatically when not needed. White label webviewer control, semeless integration to your own project.

Tutorial: Build Online Document Viewer Quick to Setup in IIS After you download the latest version of RasterEdge.DocImagSDK, you can build your own web using the following steps. 1. Unzip the download package and you can find a project named ReasterEdgeWebViewer in the “Demo projects” folder, which is used for testing. 2. Copy corresponding DLL(x86 or x64) in the download package to the bin folder of the test project. Note some versions of Visual Studio use a 32-bit internal server. If you want to debug your project in Visual Studio, please copy x86 dlls in your web project. After debugging, you can replace with x64 dlls to run on real IIS Server. 3. After adding relative dlls, you can deploy your project to IIS server. 1) Open Internet Information Services Manager; 2) Right-click “Sites” and select “Add Web Site”; 3) According to your situation, set the “Site name”, and set the “Physical path” to the place where you store WebViewerDemo. Last, set the “Port” that monitors the application. 4) Click ok to complete deploying your project; 5) Double-click on the “Default Document” options, and check if there is a “default.aspx” item. If not, add this item through "Add" on the right. If you configure IIS to run and 500.19 error occurs, then it may be caused by: 1. Not registered the .net framework to the iis. (One of reasons: install a .net framework before the installation of iis.) 2. The site configured in IIS has no sufficient authority to operate. (Modify permission) There are some solutions: 1. In the command line input cd C:\Windows\Microsoft.NET\Framework64\v2.0.50727 aspnet_regiis.exe –i

1. Right-click the correspond site-> Edit Permissions -> Security -> Group or user names -> Edit -> Add -> Add Everyone users given Full Control permissions. F&Q

When configure IIS to run 500.19 error occurs, it may be caused by: 1. Not registered the .net framework to the iis. (One of reasons: install a .net framework before the installation of iis.) 2. The site configured in IIS has no permission to operate. (Modify permission) Here are some solutions: In the command line input cd C:\Windows\Microsoft.NET\Framework64\v2.0.50727 aspnet_regiis.exe –i

Right-click the correspond site-> Edit Permissions -> Security -> Group or user names -> Edit -> Add -> Add Everyone usersgiven Full Control permissions.

If the uploading document is not successful, please pay attention to the following: 1. Make sure the Default page is the Default. aspx, If not sure in the address bar add /Default. aspx 2. Don’t add SVGWebViewer dll to the project. Q: In Asp.net project when testing web viewer control, I get the error: Could not load file or assembly 'RasterEdge.Imaging.Annotation' or one of its dependencies. An attempt was made to load a program with an incorrect format. A: This is because Visual Studio uses a 32-bit web server internally. You can first debug with x86 webviewer dlls in Visual Studio mimic IIS environment. Once done debugging with x86 dlls, replace the x86 with x64 version of dlls to run in real IIS on the servers.

Quick to Start This part will guide you to set up a web page containing an embedded Web Document Viewer. Setup Your ASP.NET Website in Visual Studio Create a new website or open your existing one. It is ready to run from Visual Studio. 1.

Add references: Right-click the project, select “Add Reference…” locate the RasterEdge.DocImagSDK(version)\bin in the download package, and add a new reference called RasterEdge.Imaging.WebViewer.dll to the project. Once you do this, dependencies

2.

3.

will automatically be included in your project. Note some versions of Visual Studio use a 32bit internal server. If that is the case please add x86 version of RasterEdge.Imaging.WebViewer.dll in your web project. After debugging, you may replace the x86 version with x64 WebViewer dll to run your project on real IIS Server. Modify your configuration file: Copy the content of Web.config in the download package to your configuration file which is supposed to be Web.config. Your project will need a copy of the Web Document Viewer resources, which includes client side javascript and styles. These resources folder called RasterEdge_Resource_Files, RasterEdge_Demo_Docs and RasterEdge_Cache located in the download package. The WebHandler.ashx file has been included in RasterEdge_Resource_Files. Copy these directories to the root of your project. Server-side file system and cache files are stored in the RasterEdge_Cache folder. You can rename the folder, but at same time you should change the appsetting node in the web.config. The default content is as follows:

Add Document Viewer to Your ASPX Web Page In your web application, you will want to insert the web document viewer into your own web page, but for this example we will work with a new page. Add a new Web Form to your project. We assume that you name this file Default.aspx and Visual Studio will automatically create a code behind for this file, called Default.aspx.cs. 1. First, copy the following lines of C# code to the head of Default.aspx. _msgToClient = ""; _cacheFolder = ""; _viewer = new RasterEdgeViewer({ _serverUrl: "/RasterEdge_Resource_Files/WebHandler.ashx", //Set the default page _defaultPage:”Default.aspx”, //0 represent png, 1 represent svg

_pdfViewer: 1, _wordViewer: 1, _excelViewer:1, //Set width and height of the webViewer(pixel) _viewerWidth: 1024, _viewerHeight: 730, }); //You can add a new Tab, delete a tab that you don't need ,also you can adjust the tab order…… //add Tab "File" var _tabFile = new ToolbarTab("File"); _tabFile.addCommand(new CommandFile("upload")); _tabFile.addCommand(new CommandFile("print")); _tabFile.addCommand(new CommandFile("save")); _tabFile.addCommand(new CommandFile("convert")); _viewerTopToolbar.addTab(_tabFile); //add Tab "Annotation" var _tabAnnotations = new ToolbarTab("Annotation"); //TextFont:Arial/Calibri/Verdana //TextStyle:italic/oblique/normal //TextColor:Hexadecimal color can be used //Transparency:1 on behalf of saturated, 0 represents completely transparent _tabAnnotations.addCommand(new CommandAnnotation("text",new AnnoStyle({OutLineWidth:3.0,OutLineColor:"#FFFFFF",FillColor: "#FFFFFF", ShowedText: "double click to edit", TextColor: "#000000", TextFont: "Arial", TextSize: 18,TextStyle :"bold",Transparency:0.8}))); _tabAnnotations.addCommand(new CommandAnnotation("line",new AnnoStyle({OutLineColor: "Red", OutLineWidth: 5.0,Transparency:1}))); _tabAnnotations.addCommand(new CommandAnnotation("arrow",new AnnoStyle({OutLineColor: "Red", OutLineWidth: 5.0, FillColor: "Red",Transparency:0.8}))); _tabAnnotations.addCommand(new CommandAnnotation("appearance")); _tabAnnotations.addCommand(new CommandAnnotation("delete")); _tabAnnotations.addCommand(new CommandAnnotation("loadAnnos")); _tabAnnotations.addCommand(new CommandAnnotation("saveAnnos")); _viewerTopToolbar.addTab(_tabAnnotations); //add Tab "Sample Files" var _tabDemoFiles = new ToolbarTab("Sample Files"); //Scenario 1:ID and events take RE default var _userCmdDemoPdf = new REUserCommand("pdf"); _userCmdDemoPdf.addCSS(new customStyle({background:"url('RasterEdge_Resource_Files/images/demo.png') no-repeat 0px 0px",width:"31px",height:"40px",marginRight:"15px"})); _userCmdDemoPdf.addParameter(new customCmd({RECommand:"userDefined",FileName:"/RasterEdge_Demo_Docs/pdf/demo_1.pdf"})); _tabDemoFiles.addCommand(_userCmdDemoPdf); //Scenario 2:Custom ID and Event. But you should define the event in customViewer.js and define style in RasterEdge.css. var _userCmdDemoTiff = new REUserCommand("tiff"); _userCmdDemoTiff.addId("_tiff"); _userCmdDemoTiff.addEvent(tiffClickEvent); _tabDemoFiles.addCommand(_userCmdDemoTiff); //Scenario 3:In addition to the div element,If you need button,input,checkbox......,you can

call addHtmlDOM(). //excelHtmlDom defined in customViewer.js var _userCmdDemoDicom = new REUserCommand("dicom"); _userCmdDemoDicom.addHtmlDOM(dcmHtmlDom); _tabDemoFiles.addCommand(_userCmdDemoDicom); _viewerTopToolbar.addTab(_tabDemoFiles);

The first five lines of code are to load the necessary resources for creating web document viewer objects. And the remaining code is to initialize your viewer. 2. Next, add the following HTML into your document’s body to create the document viewing area.

3. Here are some snippets of Default.aspx. In order to use certain functions, you may select some codes below to Default.aspx.cs file in your project. LoadFileFromUpload is an API for you to handle uploads documents.LoadFileFromUrl is an API for you to handle the specified file in server file system or another website through the url. ProcessUserDefinedFileSave is an API for you to handle the saved document which you can customize.ProcessUserDefinedFileLoad is an example of a user-defined function. public string MsgToClient = ""; public string cacheFolder = WebConfigurationManager.AppSettings.Get("cacheFolder"); protected void Page_Load(object sender, EventArgs e) { RequestServerceHandler(); } private void RequestServerceHandler() { string command = Request.Form["RECommand"]; if (command == null || command.Equals("")) { if (Request.Files.Count > 0) LoadFileFromUpload(); else LoadFileFromUrl(); } else if (command.Equals("FileSave")) { ProcessUserDefinedFileSave(); } else if (command.Equals("userDefined")) { ProcessUserDefinedFileLoad(); } }

Load and Display Your File in Document Viewer Control RasterEdge demo project provides you three ways to load document: One is through the url to open the specified file in server file system, for example ”…./?file=/RasterEdge_Demo_Docs/pdf/demo_1.pdf”, which will open the demo_1.pdf in the pdf folder under RasterEdge_demo_Docs folder. Or you can use an absolute file path.Like “…./?file=c:/test/demo.pdf”. Another one is through the url to open the file on another web site, eg. “…./?src= http://....... /demo.docx”. But one thing you should pay attention to is rasterEdge only supports urls begin with “http” or “https”. The last one is by clicking the upload button to open the local document . Navigation

RasterEdge document web viewer provides three ways to navigate throw the document you read. First one is the thumbnail image, a thumbnail image is generated for each page in the document, by clicking the thumbnail you are redirect to the corresponding pages.

Moreover to get a thumbnail image of a document page, you can call the API Bitmap BasePage.GetBitmap(float zoomValue) set the zoom value to somewhere between and 1. This API can be called from any document page object for which the document types are supported by RasterEdge Doc Imaging SDK, for example PDFPage, DOCXPage, TIFFPage and DCMPage. Another way is to set the specific size for the thumbnail image using the API, REImage BasePage.ConvertToImage(Size targetSize) the returning REImage object can be converted to different image formats. Seconde way to navigate through the document is by outlines. Most of the well-formed documents contain outline information. For Word document an automatic document outline is generate for navigation purpose. For documents like PDF, outline information is extracted from document if it is included. If you want to obtain outlines programmatically, you can use the API BaseDocument.GetOutline();

Last way to navigate through the document is by searchResults. If you want to Search the document content , you can use the API BaseDocument.CacheSearchInfo(string cacheFile); BaseDocument.Search(string cacheFile,RESearchOption option,SearchResult result);

Draw Annotation RasterEdge viewer provides you all kinds of annotation buttons on the toolbar. By create, load, and modify annotations, you can collaborate with your colleguges and peers on the same document file. There are two ways to save the annotations. One is to save annotations separately from the original document as xml files. Another way is to burn the annotations into the original document as native graphics. The default style of annotation can be changed. Please refer to “Advanced settings” part for more details.Also you can dynamically change the style. When an annotation is selected, the corresponding style icon will appear clickable state. Click on the corresponding icon changes these properties. Load and Save Annotation In addition, annotations can be saved to xml document.You can load the saved xml annotations next time you view the same document.

Save, Print, and Convert Your File You can convert all kinds of documents to PDF by clicking on “print to pdf” button, but you also can transform all kinds of documents to tiff by clicking on “convert to Tiff file” button. In case some document formats do not support annotations, convert to PDF or tiff after you annotate or redact the documents and download them in PDF or Tiff format. Note: You may find the following code in the Default.aspx.cs file.

This code snippet is user-defined. You can call the API you need. There are 4 APIs available. GetSaveFileRelativePath (GetSaveFileAbsolutePath) get the relative(absolute) path of the saved file.

GetSaveFileByteArray get the byte array of the saved file and GetSaveFileStream get the stream of the saved file. You can carry additional operations using the data you get here.

Deploy Your Project on IIS Follow a similar workflow as deploy the demo in IIS

See Also Tutorial: Quick to setup in IIS F&Q

When configure IIS to run 500.19 error occurs, it may be caused by: 1. 2.

Not registered the .net framework to the iis. (One of reasons: install a .net framework before the installation of iis.) The site configured in IIS has no permission to operate. (Modify permission) Here are some solutions: In the command line input cd C:\Windows\Microsoft.NET\Framework64\v2.0.50727 aspnet_regiis.exe –i

Right-click the correspond site-> Edit Permissions -> Security -> Group or user names -> Edit -> Add -> Add Everyone usersgiven Full Control permissions.

If the uploading document is not successful, please pay attention to the following: 1. Make sure the Default page is the Default. aspx, If not sure in the address bar add /Default. aspx 2. Don’t add SVGWebViewer dll to the project.

Q: In Asp.net project when testing web viewer control, error load program with incorrect format appears in Visual Studio A: This is caused by limitation of some versions of Visual studio. You can debug with x86 dlls of webviewer in Visual Studio. Once done debugging with x86 dlls, replace the x86 dlls for x64 version. The x64 build and dlls run perfectly in real IIS on your server.

Advanced Settings

Document Viewer Width

Height

You can change width and height of the Viewer. Change the corresponding attribute values of _viewer object in default. aspx page. _viewerWidth: A float number representing the width of REWebViewer control in pixel _viewerHeight: A float number representing the height of REWebViewer control in pixel Following part is the default setting of RasterEdge viewer. _viewer = new RasterEdgeViewer({ _viewerWidth: 1024, _viewerHeight: 730, });

Display Format RasterEdge can convert PDF, Word, and Excel format files into Bitmap, as well as SVG files at the same time. In this case, you can determine to display the document as SVG or Bitmap. _pdfViewer, _wordViewer and _excelViewer are corresponding to setting PDF, Word, and Excel. These properties have two values, in which 1 represents you choose to use SVG, and 0 represents Bitmap is chosen. View File from Your Content Management System RasterEdge Webviewer control offers you five APIs to load file, namely CreateWebDocFromUpload(HttpRequest request), CreateWebDocFromServer(string filePath), CreateWebDocFromOnLine(string src,string fileName), CreateWebDocFromStream(Stream stream,string fileName) and CreateWebDocFromByte(byte[] array,string fileName). You can call different APIs according to your situation. The function in the Default.aspx.cs provides you with solutions in three situations that may arise when you load file. You can follow the code that RasterEdge gives you, and customize your own needs. //load the selected file in the server file folder through url string path = REDocumentControl.GetAbsolutePath(file); REWebDocument webDoc = REDocumentControl.CreateWebDocFromServer(path); MsgToClient = webDoc.MsgToClient; //load the file just uploaded to the RasterEdge_Cache folder in the server REWebDocument webDoc = REDocumentControl.CreateWebDocFromUpload(Request); REDocumentControl.ResponseToClient(webDoc.MsgToClient, Response);

//load the specified file on another website REWebDocument webDoc = REDocumentControl.CreateWebDocFromOnLine(src, ""); MsgToClient = webDoc.MsgToClient;

REWebDocDocument is an Object that contains information about a document. Such as NameId. NameId stores the file name and fid.(note:the variable fid is a unique ID that server assigns to the document).Such as _fileObject. _fileObject is a BaseDocument object or a REImage object which contain information parsed. Annotations RasterEdge allows you to customize the style of annotations. It is simple and straightforward. Copy and modify the following properties in the Default.aspx file. //define annotation style _tabAnnotations.addCommand(new CommandAnnotation("text",new AnnoStyle({OutLineWidth:3.0,OutLineColor:"#FFFFFF",FillColor: "#FFFFFF", ShowedText: "double click to edit", TextColor: "#000000", TextFont: "Arial", TextSize: 18,TextStyle :"bold",Transparency:0.8})));

Delete Cache Files RasterEdge provides you two ways to delete cache files. One is to clean up files in RasterEdge_ Cache folder every certain amount of time. IntervalTime is a class define this time interval. Here are some code snippets of Global.asax: //Clean Cache every 20 minites Scheduler.inervalJobTask = new IntervalJob(new IntervalTime(0, 0, 0, 20), directory); Scheduler scheduler = new Scheduler(); System.Threading.ThreadStart myThreadStart = new System.Threading.ThreadStart(scheduler.IntervalJobStart);

Another way is to delete file after the same time. Change the code as follows: Scheduler scheduler = new Scheduler(); System.Threading.ThreadStart myThreadStart = new System.Threading.ThreadStart(scheduler.SameTimeJobStart);

And the additional need to do is whenever locate a document you should add the following code: SameTimeJob job = new SameTimeJob(FileDirectory, fid, new IntervalTime(0,0,0,20)); lock (Scheduler.sameTimeJobList) { Scheduler.sameTimeJobList.Add(job); } Of course, If you does not need this feature, you can just commente out the follow code in the Global.asax. //TimerTask();

WinForm Document Viewer WinViewer Overview

The WinViewer is a .NET imaging control used for Windows Forms applications, providing professional document solutions for users and making images & documents viewing, manipulation, annotation and saving an easy task. The WinViewer Control supports most common document and image formats (PDF, MS Word, Excel, Ppt, Tiff, Png…). A complete example of WinViewerDemo is included in the RasterEdge.DocImageSDK demo projects in download package. This complete example is implementing default RasterEdge style, if you want to create WinViewerDemo with your own style, please see our “Add a WinViewer to Your Project” below this part for a step-by-step tutorial. Feature List Perfectly work with Microsoft Visual Studio 2005 and above verison Create high-quality document images. Repaint at zoom operations to maintain high fidelity document imaging Automatically Generate thumbnails for document and provide navigation using thumbnails viewer. Easy to view, edit, annotate and save document Zoom, pan, or select document page with mouse to fit width, height, or both Support tiff, pdf, office word, excel, ppt, medical image(dicom) and other commonly used image formats. Control APIs The WinViewer control provides developers many APIs to be invoked. The following will give you a broad overview of these functions. APIs LoadFromFile(String filePath) SaveFile(String filePath) UpPage DownPage ZoomIn

Description Accept the path of the file that you want to open. Save the file to a specified path. Scroll to previous visible page in the currently open document. Scroll to next visible page in the currently open document. Increase current zoom percentage of the WinViewer.

ZoomOut FitWidth FitHeight ShowOneToOne AddPage DeletePage Roate90 Rotate180 Rotate270

Decrease current zoom percentage of the WinViewer. Reset size of the currently displayed page. Prior to the currently displayed page to add a blank page. Delete the currently displayed page. Rotate the currently displayed page 90 degrees clockwise. Rotate the currently displayed page 180 degrees clockwise. Rotate the currently displayed page 90 degrees counterclockwise.

DrawText, DrawFreehand DrawLine, DrawPolygonLines DrawFilledRectangle, Draw the specified type annotation on the page. DrawRectangle, DrawHighLight DrawEllipse, DrawPolygon DrawRubberStamp BurnAnnotation Burn all annotations to the page. DeleteAnnotation Delete all selected annotations. Add WinViewer to Your Project This part will guide you to add WinViewer control to your project and invoke APIs of this control. See detailed steps below: 1. Setting Up Your Project 2. Open File From Specified Path 3. Draw Specified Type Annotation on Page Setting Up Your Project In Visual Studio, create a new Windows Forms project called WinViewerDemo. If you already have a Windows Forms Project, this step can be omitted. Add control. Right-click on the Toolbox, select “Choose Items…”, locate the RasterEdge.DocImagSDK6.3\bin in download package, and browse to find and select RasterEdge.Imaging.WinformsControl.DocumentViewer.dll, then WinViewer Control will appear in Toolbox. See as below:

Once you do this, you will find a new reference called RasterEdge.Imaging.WinformsControl.DocumentViewer.dll has been added to your project.

Open File from Specified Path There may be other elements on your form, but in the following tutorial, we will take a blank form as an example. Drag a WinViewer control onto your WinForms application, and the form you created should look similar, in the design-time view, to the screen capture shown below.

Now, you only need several lines of C# code to open a document. The following code presents an open file dialog. You can select a file to be loaded into the WinViewer control. If the file format is not supported by WinViewer control, there will prompt a window “cannot open your file”. private void OpenFile_Click(object sender, EventArgse) { OpenFileDialogofd = new OpenFileDialog(); ofd.Filter = "(*.*)|*.*"; ofd.Multiselect = false; if (ofd.ShowDialog() == DialogResult.OK) { this.winViewer1.LoadFromFile(ofd.FileName); }

} Draw Specified Annotation on Page Call a single method for each kind of annotation that you want to support from your toolbar button’s OnClick events. Resizing, burning, deleting and moving are all built in. private void HighLight_Click(object sender, EventArgse) { this.winViewer1.DrawHighLight(); } private void Text_Click(object sender, EventArgse) { this.winViewer1.DrawText(); }

Right-clicking on the created annotation, you will see the option to burn or delete. If you rightclick on the thumbnail, there is the option to “Add new page” or “delete page”. Using this WinViewer, there’s necessary for you to add some buttons to complete these operations. Customize WinViewer Control Customize Toolbar It’s easy to see from the above example. You can customize your toolbar, and the only thing you need to do is call the appropriate API. Customize Annotation Style RasterEdge gives you default Annotation Style, but allows you to modify the style according to your preferences.

Here we take the styles modification of HighLight annotation and Text annotation as examples. private void HighLight_Click(object sender, EventArgse) { this.winViewer1.HighLightAnnoStyle.FillColor = Color.Red; this.winViewer1.HighLightAnnoStyle.Transparency = 0.2f; this.winViewer1.DrawHighLight(); } private void Text_Click(object sender, EventArgse) { this.winViewer1.TextAnnoStyle.FillColor = Color.Yellow; this.winViewer1.TextAnnoStyle.AnnoText = "double click to edit your content"; this.winViewer1.TextAnnoStyle.TextFont = new Font("Arial", 15, FontStyle.Bold | FontStyle.Italic); this.winViewer1.TextAnnoStyle.Transparency = 0.8f; this.winViewer1.DrawText(); }

Note: For each annotation, the attributes that can be modified have been listed in the Form1. If not listed, after the annotation property changes, there is no corresponding effect. Customize the Way Open and Store Files The WinViewer control offers developers two APIs to LoadFile. One is LoadFromFile(string filePath), and the other is LoadFromFile(Stream stream). Developer can feel free to invoke different APIs. Here, RasterEdge just provides you sample code on how to load file from local and save file locally. Certainly, you can customize the way to open and store files.

Customize the Drop-down List There are several events in Form1, for example: OnFileAdded, PageIndexChanged and SelectedIndexChanged, etc. These events are available to be used to customize the drop-down list. If you don’t use the drop-down list, please omit these events. Events OnFileAdded PageIndexChanged SelectedIndexChanged

Description Mainly in order to obtain the total number of document pages. Click on thumbnail to change the drop-down list displayed value. According to the value of selected drop-down list to switch pages.

Users can choose to copy different codes according to their needs for project.

Programming with RasterEdge Document Imaging SDK Overview Introduction to RasterEdge Document Imaging RasterEdge Document Imaging SDK features in reliable and straight forward APIs to load, convert, annotate and save document file such as Office Word, Excel, PowerPoint, PDF, TIFF, and DICOM. You can build projects which provide functions of viewing, annotating, collaborating and managing documents at any time and any place. Developers can develop either client software or online ASP.NET application with Rasteredge Document Imaging SDK. You can find an online demo at http://www.rasteredge.com/dotnet-imaging/web-viewer-demo/. The main features of our product are: 1. Load and create document formats including PDF, TIFF, Dicom, Word, Excel, and PowerPoint. 2. Convert document pages to different image formats including raster images and vector image file such as SVG files which can be viewed directly in web browsers. With customized option such resolution and crop region. 3. Annotate on pages and save the annotation in native file format. 4. Page level processing for multi-page TIFF and PDF document including appending, inserting, deleting and sorting pages. 5. Combine, split or extract pages from PDF or TIFF document. 6. Burn barcode in document page. 7.

Scan barcode from documents.

8. Convert documents to PDF, TIFF and SVG file format. In RasterEdge Document Imaging toolkit, a document and its page content within is represented as a document class object in memory. These document classes of specific document types are all derived from BaseDocument Class which contains common interfaces for document operations. Similarly, Pages in document are represented as page objects derived from BasePage Class. For example, for PDF we use PDFDocument class object to reference a physical PDF document file or stream. You can construct a PDFDocument using the following constructor. PDFDocument doc = new PDFDocument(@"D:\sample1.pdf");

Or construct a word document.

DOCXDocument doc = new DOCXDocument(@"D:\BugList\sample1.docx");

You can get page from document object using the following code. PDFPage page = doc.GetPage(0);

PDFDocument and DOCXDocument Class both implement APIs from BaseDocument, while PDFPage and DOCXPage adapt APIs from BasePage.

Register Process You need to add the following line of code in the entry point of your project to use functions in the SDK.

WorkRegistry.Reset();

If you encounter Registry Exception when running the program, please refer to the solutions here.

TIFF TIFF File Overview The Tagged Image File Format (known as TIFF) is a bitmapped and lossless image format, which is often used to store large but high-quality images. RasterEdge Image provides the ability to manipulate with TIFF file from various aspects using TIFFDocument and TIFFPage classes located in RasterEdge.Imaging.TIFF namespace. And this part introduces functions of the TIFF assembly. Here are the features supported by the TIFF assembly. Load or create TIFF file from tiff file, stream or an image collection Provide six types of tiff compression. CCIT 1D, Group4Fax, Group3Fax, LZW, PackBits, JPEG. Retrieve and modify the IPTC, TIFF, EXIF filed and get the information of xml. Draw the specific part of page on a given graphics, scale operation is offered. Get preview of the first page for quick loading Convert TIFF file to bmp, gif, png, and jpeg image types Convert TIFF file to PDF Convert TIFF file to SVG file which can be displayed in web browsers. Add rich text and graphical annotations to TIFF file Rich APIs to process TIFF pages, like page extraction and adding image to page Add standard 1d & 2d barcodes to specified location of TIFF file Read barcodes information from Tiff file Requirements The APIs related to TIFF are located under: Assemblies: RasterEdge.Imaging.Basic.dll RasterEdge.Imaging.TIFF.dll NameSpace: RasterEdge.Imaging.Basic RasterEdge.Imaging.TIFF TIFF Programming Classes

TIFFDocument: This class is an extension of BaseDocument. It represents a high-level model of the pages within a TIFF file. When a TIFFDocument object is created from an existing TIFF file, it contains a collection of TIFFPage objects for each page within the file. It is easy to use TIFFDocument to retrieving information from the files. You can also reorder or remove pages from TIFF files. TIFFPage: This class uses BasePage as prototype. It is a high-level abstraction of a page within a TIFF file. You obtain images from TIFFPage object individually. Construct, Load and Save TIFFDocument Load or Create TIFFDocument You can load a Tiff file from a file path, stream or byte[]. APIs: TIFFDocument doc = new TIFFDocument(string filePath); TIFFDocument doc = new TIFFDocument(Stream s); TIFFDocument doc = new TIFFDocument(Byte[] byteArray); C# using RasterEdge.Imaging.TIFF; TIFFDocument doc = new TIFFDocument(filePath); TIFFDocument doc = new TIFFDocument(stream); TIFFDocument doc = new TIFFDocument(byteArray);

You can also create a TIFFDocument from Image Source. Like this C# public static void TestImageToTIFF() { //invoke this method only once at the beginning of your code register all assemblies you referenced to your project WorkRegistry.Reset(); //Construct image source from image files REImage img1 = new REImage(@"c:\samplePNG.png", ImageType.PNG); REImage img2 = new REImage(@"c:\samplePNGAnnotated1.jpg", ImageType.JPEG); REImage[] imageSource = new REImage[2]; imageSource[0] = img1; imageSource[1] = img2; // create a TIFF document using image source, one image per page TIFFDocument doc = new TIFFDocument(imageSource, TIFFCompression.JPEG); doc.Save(@"c:\sample.TIFF");

}

See also REImage programming Once you have a TIFFDocument object, you can get information about pages contained in this document. //get total page count in this document int pageCount = doc.GetPageCount(); // get the first page of this document, note that the page index starts at 0 TIFFPage page = (TIFFPage)doc.GetPage(0);

Save TIFF File After a TIFF file has been read, created or modified, you can save it by invoking the save methods in TIFFDocument class. This method takes in either an output Stream or an output filePath. Related APIs: void Save(string filePath); byte[] SaveToBytes(); void SaveToStream(Stream stream); Clear Temp files generated in the process Since tiff file might be too large to hold in memory, temp files are cached in the intermediate process. Use the following API to clear the temp files when the tiff processing task is done. Once this API is called, all cached files are deleted and you need to create new TIFFDocument object to do further processing. //clear temp files for processing this tiff file // this code should be exectuted after all operations on tiffs are done. TIFFDocument.ClearTmpFiles();

Get preview of Tiff Document RasterEdge document imaging sdk provide you with APIs to get a Bitmap of the first page in the tiff file. You are able to get a preview of this tiff document without load and process the whole document in memory. Related APIs:

static Bitmap GetPreviewImage(string file Size targetSize) static Bitmap GetPreviewImage(byte[] data,Size targetSize) static Bitmap GetPreviewImage(Stream s,Size targetSize)

TIFF Rendering and Conversion RasterEdge Document Imaging SDK supports converting TIFF Document to various image or document types with customized options. You can convert TIFF Document to PNG, JPEG, BMP, and GIF image formats. You can also convert TIFF Document to SVG, which is a vector image format that is supported by HTML5 standard and therefore supported by most of the up to date web browsers. TIFF document can be converted to PDF file as well. Convert TIFF Document to Image Files You can convert TIFF Document to a collection of image files with only one function. void ConvertToImages(ImageType targetType,String directory, String fileName) This method will automatically convert every page in the TIFF document to image file, with the page index append to fileName. Note that, the resolution is default to be 96 dpi for monitor displaying purpose. You can adjust to the resolution to enlarge the image dimension. Convert TIFFPage to Image File

You can get specific TIFFPage object from tiff document by BasePage GetPage(int index). After that you can render TIFFPage object to REImage or other common image formats with customized parameters. Related APIs: REImage ConvertToImage() REImage CropImage(Rectangle sourceRegion, Size targetSize) void ConvertToImage(ImageType toType,String filePath) For large TIFF images we recommend you to use CropImage API for methods with a REImage or Bitamp object to return. It processes tiff images in partition. You can convert the image in parts and then combine the partitions.

Convert TIFFPage to Bitmap In .Net framework Bitmap is a frequently used class in image processing. RasterEdge provide you with APIs to directly convert TIFFPage to Bitmap objects which then can be drew on graphics of for example win form controls. These APIs returning a Bitmap object are faster than return a REImage object taking into account that some additional operations needed with REImage. Bitmap GetBitmap() Bitmap GetBitmap(float zoomValue) Bitmap GetBitmap(Rectangle sourceRectangle, Size targetSize) Note that the resulting Bitmap cannot be too big to handle due to the restriction of system memory. You can divide the big page into parts and deal with them separately. Typically if an original tiff image or the resulting image magnified has a dimension product over 3000*3000, we recommend you deal with them in partitions. Bitmap GetBitmap(Rectangle sourceRectangle, Size targetSize) is a good choose.

Draw(Graphics g, PointF loaction) void Draw(Graphics g, PointF loaction, Size targetSize )

Convert TIFFDocument to PDF You can convert TIFFDocument to PDF with just a few lines of code: WorkRegistry.Reset();// invoke this static method only once at the beginning of codes //load source tiff file TIFFDocument tif = new TIFFDocument(tifPath); // convert tiff to PDF document tif.ConvertToDocument(DocumentType.PDF, pdfsTargetPath);

//clear temp files for processing this tiff file // this code should be exectuted after all operations on tiffs are done. TIFFDocument.ClearTmpFiles();

Convert Other Document to TIFF Document You can convert other document types to TIFFDocument object and save it to Tiff file. Using the default JPEG compression Sample code: WorkRegistry.Reset();// invoke this static method only once at the beginning of

codes // load the pdf document to convert //you can also convert documents in other types such as word,excel to TIFF use the same API PDFDocument pdf = new PDFDocument(@"c:\REImage.pdf"); // convert to tiff file using default JPEG compression. pdf.ConvertToDocument(DocumentType.TIFF, @"c:\pdfToTiff.tiff");

If you need generate the tiff file with a greater resolution (or bigger size) you can use the following code to generate an x2 resolution tiff.

pdf.ConvertToDocument(DocumentType.TIFF, 2.0f, @"C:\pdftoTiffx1.tif");

You can specify compression type using the following code. For example you want to generate a Black and White tiff you should use CCITID compression. Please note that the default JPEG compression will in most cases produce the best performance in speed Sample code: // load the pdf document to convert PDFDocument pdfDoc = new PDFDocument(@"F:\sample.pdf"); int pageCount = pdfDoc.GetPageCount(); REImage[] reImages = new REImage[pageCount]; ColorReduction colorReduction = new ColorReduction(); //Use ColorReduction utility to reduce the image’s color depth to 8bpp(colorDepth is 256) 4bpp colorDepth is 16 or 1bpp(colorDepth is 2). Please note, to apply the compression of CCIT1D Group3Fax and Group4Fax,the image must be at a color depth of 2 for (int i = 0; i < reImages.Length; i++) { Bitmap bm = pdfDoc.GetPage(i).GetBitmap(); reImages[i] = colorReduction.GetREImage(bm, 2); } TIFFDocument tifDoc = new TIFFDocument(reImages, TIFFCompression.CCITT1D); tifDoc.Save(@"F:\Test.tif");

TIFF Annotation You can add annotations like text and highlight on TIFF page. For detailed information about annotation objects, please refer to Annotation section. You need the following dll(s) to implement this feature. RasterEdge.Imaging.TIFF.dll RasterEdge.Imaging.Annotation.dll RasterEdge.Imaging.Basic.dll Sample code:

// generate the annotation object AnnotationHandler anno = AnnotationGenerator.CreateLineAnnotation(new RasterEdge.Imaging.Annotation.Basic.LinePoint(0, 0), new RasterEdge.Imaging.Annotation.Basic.LinePoint(100, 100)); // create a line annotation starting at point (0.0) and end with point(100,100) note only the relative position of the start and end point is used. TIFFDocument doc = new TIFFDocument(@"c:\sample.tif"); TIFFPage page = (TIFFPage)doc.GetPage(0); //add the line at point (100,100) on the tiff page. The position is measured at default 96 resolution with respect to the tiff image.And therefore subject to the change of the size of the tiff image page.AddAnnotation(anno); doc.Save(@"c:\annotatedSample.tif");

See also Annotations Editing TIFF Metadata You can get the tag collection of the specific tiff page, which is comprised of EXIF Fields, TIFF Fields and IPTC Fields. Every EXIF and TIFF Field is made up of a “tag”, a “dataType” and a “values”. The IPTC field is made up of a“ID”, a “Section” and a “value”. Sample code: C# Public TagCollection GetTagCollection(int pageIndex, TIFFDocument doc) { return tifDoc.GetTagCollection(pageIndex); }

Get the specific page’s XML information return as a string: C# publicstring GetXmpString(int pageIndex, TIFFDocument doc) { Return doc.GetXMPMetadata(0);//pageIndex = 0 }

Add, Delete, Update and Find TIFF Field Assume you have retrieved the tag collection already, then you can edit the TIFF Field, we provide 8 constructors to create a TIFF Field, and you can choose the field’s data type easily. Note there are some important fields which can’t be removed. Otherwise the tiff file would be corrupted. The TagID must be a hexadecimal. C# TIFF Field Constructor: public TIFFField(int tagID, byte value);

public public public public public public public

TIFFField(int TIFFField(int TIFFField(int TIFFField(int TIFFField(int TIFFField(int TIFFField(int

tagID, tagID, tagID, tagID, tagID, tagID, tagID,

byte[] values); string str); uint value); uint[] values); ushort value); ushort[] values); uint frac, uint deno);

Add TIFF Field:

Note: the tagID must be hexadecimal and add a tiff field with an existing id is not permitted void AddTifField(int pageIndex, TIFFDocument tifDoc, TagCollection tagCol) { tagCol.AddTifTag(new TIFFField(0x1111, 123)); tagCol.AddTifTag(new TIFFField(0x2222, new byte[3] { 0, 1, 2 })); tagCol.AddTifTag(new TIFFField(0x3333, new ushort[3] { 0, 1, 2 })); tagCol.AddTifTag(new TIFFField(0x4444, 3, 5)); tagCol.AddTifTag(new TIFFField((int)TIFFTag.Artist, "www.RasterEdge.com")); } Delete TIFF Field:

Remove a TIFF Field form the specific page. Note: there are some significant fields can’t be removed, if so, the document would be corrupted. The tagID must be a hexadecimal void DeleteTifField(int pageIndex, TIFFDocument tifDoc,TagCollection tagCol) { tagCol.DeleteTifTag(0x1111);//you can define a tag ID like this tagCol.DeleteTifTag((int)TIFFTag.Artist);//or use our TIFFTag Enum } Update TIFF Field:

Find the field which tagID is 0x1111,and change it’s value to 456, find the field which tagID is Artist,and change it’s value to”Welcome to RasterEdge” void UpdateTifField(int pageIndex, TIFFDocument tifDoc,TagCollection tagCo) { tagCol.UpdateTifTag(new TIFFField(0x1111, 456)); tagCol.UpdateTifTag(new TIFFField((int)TIFFTag.Artist, "Welcome to RasterEdge")); } Find TIFF Field:

If there is a tiff field which tagID is Artist, then it willed be returned TIFFField FindTifField(int pageIndex, TIFFDocument tifDoc, TagCollection tagCol) { return tagCol.FindTifTag((int)TIFFTag.Artist); }

Add ,Delete ,Update and Find EXIF Field The manipulation of EXIF Fields is just as same as TIFF Fields

Add ,Delete ,Update and Find C#

IPTC Field

IPTC Field Constructor: public IPTCField(byte section, byte id, byte[] data); public IPTCField(byte section, byte id, string str); Add IPTC Field: void AddIptcField(int pageIndex, TIFFDocument tifDoc, TagCollection tagCol) { tagCol.AddIPTCTag(new IPTCField(2, 2, new byte[3] { 0, 1, 2 })); tagCol.AddIPTCTag(new IPTCField(2, 3, "www.RasterEdge.com")); } Delete IPTC Field: void DeleteIptcField(int pageIndex, TIFFDocument tifDoc, TagCollection tagCol) { tagCol.DeleteIPTCTag(new IPTCField(2, 2, new byte[3] { 0, 1, 2 })); tagCol.DeleteIPTCTag(new IPTCField(2, 3, "www.RasterEdge.com")); } Updata IPTC Field: void UpdateIptcField(int pageIndex, TIFFDocument tifDoc, TagCollection tagCol) { //find theIPTC Field, which section is 2 and id is 2,then change it’s value to byte[]{4,5,6} //find the IPTC Field,which section is 2 and id is 2,then change it’s value to “Welcome to RasterEdge” tagCol.UpdateIPTCTag(new IPTCField(2, 2, new byte[3] { 4, 5, 6 })); tagCol.UpdateIPTCTag(new IPTCField(2, 3, "Welcome to RasterEdge")); } Finde IPTC Field: ListFindIptcField(int pageIndex, TIFFDocument tifDoc, TagCollection tagCol) { //if there is a iptc field,which section is 2 and id is 3, then it will be returned //note: a iptc field has the same section and id as another is permmited return tagCol.FindIPTCTag(2,3); }

Get the XML Information The xml information is parsed from the tiff tag named XmpData C# String GetXmpString(int pageIndex, TIFFDocument tifDoc) { return tifDoc.GetXMPMetadata(0); }

Editing TIFF Document Re-Order Pages of TIFF File With TIFF processing dll, it is easy for you to re-order pages of a TIFF document as long as you provide a new order sequence. See the sample code below: C# public void SortPages(String filePath, int[] pageOrder) { TIFFDocument doc = new TIFFDocument(filePath); doc.SortPage(pageOrder); }

Swap two pages of TIFF File You can swap two pages of the tiff file, suppose you have a TIFFDocument object already. C# PublicvoidSwapPages(int pageIdxF, int pageIdxB, TIFFDocument tifDoc)

{ tifDoc.SwapTwoPages(pageIdxF, pageIdxB); }

Insert Pages to TIFF File You can also insert pages to TIFF document. Suppose you have a TIFFPage class object named page, you can do something like this, C# public void InsertPageToFile(Stream s, int index, TIFFPage page) { TIFFDocument doc = new TIFFDocument(s); doc.InsertPage(page, index); }

Delete Pages from TIFF File Now you can delete pages of the TIFF file, Input is page index list that you want to delete. Suppose you have a TIFFDocument class object named document. C#

public void DeletePageFromDocument(TIFFDocument document, int pageIdx) { document.DeletePage(pageIdx); } public void DeletePagesFromDocument(TIFFDocument document, int[] pageIdxs) { document.DeletePages(pageIdxs); }

Split TIFF File To split TIFF document, you can use TIFFDocument class. There is a static method called SplitDocument, which takes either an input Stream or an input path, an input index and a list of output paths or output Streams. For example, if the target file has eight pages and you input two as the page index using SplitDocument, then the first three pages(index starts at 0) will be included in one TIFF document and the rest of five pages will be included in the other TIFF file. C# public void splitTIFFDocument(string sourceFilePath, int pageIdx, string[] destnsPath) { TIFFDocument.SplitDocument(sourceFilePath, pageIdx, destnsPath); }

Combine TIFF File Using TIFFDocument class, you can also combine TIFF documents. There is a static method called Combine, which takes either an output Stream or an output path and any number of input paths or input Streams. The input TIFF documents are combined in order to create one output TIFF document. C# public void CombineDocumentAndSaveItToFile(string[] docList, string destnFilePath) { TIFFDocument.CombineDocument(docList, destnFilePath); }

Generate Barcode on TIFF RasterEdge Barcode processing dll offers comprehensive functions for developers to generate and design both 1d & 2d barcode images on TIFF file. Sample Code:

//generate an code39 barcode Linear linearBarcode = new Linear(); linearBarcode.Type = BarcodeType.CODE39; linearBarcode.Data = "123456789"; linearBarcode.Resolution = 96; linearBarcode.Rotate = Rotate.Rotate0; // load tiff document, you can also load document like tiff, word, excel, ppt TIFFDocument tiff = new TIFFDocument(@"c:\sample.tiff"); // get the first page BasePage page = tiff.GetPage(0); // generate reimage of this barcode REImage barcodeImage = linearBarcode.ToImage(); //add barcode image to the first page page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f)); // save changes to the tiff tiff.Save(@"c:\sample.tiff");

Read Barcode Information from TIFF You can read barcode information from tiff document. Sample code: public static void ReadBarcodeFromTIFF(string filename, int pageIndex) { //generate tiff document TIFFDocument doc = new TIFFDocument(filename); //get the page you want to read barcode from BasePage page = doc.GetPage(pageIndex); //set reader setting ReaderSettings setting = new ReaderSettings(); setting.AddTypesToRead(BarcodeType.Code39); // read out barcode information Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page); //output barcode information foreach (Barcode barcode in barcodes) { Console.WriteLine(barcode.DataString); } }

How to

How to View Thumbnail Image of

TIFF Document

With RasterEdge document Imaging APIs, you can generate image out of document with proper image size set. To view thumbnail images of a tiff document, you can set a smaller image size. WorkRegistry.Reset();// invoke this static method only once at the beginning of codes TIFFDocument doc = new TIFFDocument(@"c:\sample.tif"); string thumbnailDirectory = @"c:\thumbnail"; int pageCount = doc.GetPageCount(); for (int i = 0; i < pageCount; i++) { // get tiff page TIFFPage page = (TIFFPage)doc.GetPage(i); //generate thumbnail image of 50 pixel wide and 100 pixel high REImage img = page.ConvertToImage(new Size(50, 100)); // save the thumnail image under the directory img.Save(ImageType.PNG, thumbnailDirectory + @"\sample" + i + @".png"); }

How to Generate Magnified Images of TIFFDocument You can set the zoom factor of the target image. WorkRegistry.Reset();// invoke this static method only once at the beginning of codes //load TIFF document TIFFDocument doc = new TIFFDocument(@"c:\sample.tif"); // Set directory to store the zoomed image string Image2X = @"c:\Sample2X"; // convert TIFF to png images with a zoom factor of 2f remember to set the factor to be a float number doc.ConvertToImages(ImageType.PNG, 2f, Image2X, "sample"); //or if you know the desired resolution to generate the image you can set the resolution doc.ConvertToImages(ImageType.PNG, 192, Image2X, "sample");

Because in some cases you only need to show part of the image magnified, we provide you with API to crop the TIFF image. This API costs fewer resources and less process time. WorkRegistry.Reset();// invoke this static method only once at the beginning of codes //load tiff page TIFFDocument doc = new TIFFDocument(@"c:\sample.tif"); //get the first page of the tiff document TIFFPage page = (TIFFPage)doc.GetPage(0); // set the part of the original tiff image that you want to crop. //The size and postion is measured at 96 resolution, which is the normal resolution

for desktop monitor Rectangle sourceRect = new Rectangle(0,0,100,100); // the target size of the REImage generated, note that the width and height is 2 times as large as the source rectangle // which means the source region is magnified by a factor of 2 Size targetSize = new Size(200,200); // crop the desired region from the original TIFF image REImage image =page.CropImage(sourceRect, targetSize); image.Save(ImageType.PNG, @"c:\cropped.png");

How to Add Watermark onto TIFF Document You can use annotation of Embedded Image, Text or RubberStamp to add annotation(Water Mark) onto Tiff image. Sample code: // set annotation size //the position of the annotation relative to its potential container float x = 120.0f; float y = 120.0f; float width = 300.0f; float height = 100.0f; string text = "this is RubberStamp Water Mark"; Font font = new Font("Arial", 12.0F, FontStyle.Italic); AnnotationBrush fontBrush = new AnnotationBrush(); fontBrush.FillType = FillType.Solid; fontBrush.Solid_Color = REColor.FromArgb(System.Drawing.Color.Blue.ToArgb()); RubberStampAnnotation anno = AnnotationGenerator.CreateRubberStampAnnotation(x, y, width, height, text, font, fontBrush); anno.OutLine = new LinePen(); anno.OutLine.Brush = new AnnotationBrush(); anno.OutLine.Brush.FillType = FillType.Solid; anno.OutLine.Brush.Solid_Color = new REColor(255, 10, 100, 100); anno.OutLine.Width = 2.0f; anno.Fill = new AnnotationBrush(); anno.Fill.FillType = FillType.Solid; anno.Fill.Solid_Color = new REColor(255, 20, 20, 20); anno.CornerRadius = 1000f; //set the overall transparency, this value has an overall impact on all //colors related to this annotation. Note the default value is 1 which // is complete transparency anno.SetTransparency(0.4f); // create a line annotation starting at point (0.0) and end with point(100,100) note

only the relative position of the start and end point is used. TIFFDocument doc = new TIFFDocument(@"c:\sample.tif"); TIFFPage page = (TIFFPage)doc.GetPage(0); //add the line at point (100,100) on the tiff page. The position is measured at default 96 resolution with respect to the tiff image.And therefore subject to the change of the size of the tiff image page.AddAnnotation( anno); doc.Save(@"c:\annotatedSample.tif");

PDF Introduction to PDF Functions RasterEdge Image provides users with reliable PDF technology with the following features. Open or load a PDF document from local file or byte array from database Create and save PDF document file Render PDF document to raster images Convert PDF to TIFF Add Rich text and graphical annotations to PDF file Add image to PDF page Convert tiff, word, excel, ppt, dicom document to pdf document. 1d & 2d barcodes generating and reading in pdf document Before using these functions above, you should reference our PDF processing dll (RasterEdge.Imaging.PDF.dll) and other necessary assemblies (like RasterEdge.Imaging.Basic) to you project. About PDF Programming Classes PDF document assembly provides two main processing classes, PDFDocument and PDFPage. PDFDocument: This class refers to a PDF document and it contains all document information of the PDF file. It is an extension of BaseDocument. You can use PDFDocument object to do bulk operations like load, save, convert to images/document and lookup metadata. PDFPage: This class refers to PDF document page contains in PDFDocument and use BasePage as prototype. Store page information, you can get images or svg file out of PDFPage. Also you can add annotations onto the PDFPage and save it in the document file format. PDFDocument Object PDFDocument represents the main structure of a document and the pages it contains. When a PDFDocument object is created, we can easily extract information about pages and other document structures. The example that follows shows how to use different sources to create a PDFDocument object.

C# Generate a PDFDocument object from stream. PDFDocument doc = new PDFDocument(Stream s);

Generate a PDFDocument object from file path. PDFDocument doc = new PDFDocument(@"D:\BugList\sample1.pdf");

You can also generate a PDFDocument from image collection. Related APIs public PDFDocument(REImage[] imageSource);

See also REImage programming

Get preview of PDF Document RasterEdge PDF SDK provides you with APIs to get a Bitmap of the first page in the pdf file. You are able to get a preview of this pdf document without load and process the whole document in memory. Related APIs: static Bitmap GetPreviewImage(string file Size targetSize) static Bitmap GetPreviewImage(byte[] data,Size targetSize) static Bitmap GetPreviewImage(Stream s,Size targetSize)

The sample code below tells you how to get the number of pages of this object. C# public int GetPageCount(Stream s) { PDFDocument document = new PDFDocument(s); return document.GetPageCount(); }

Save PDFDocument to File or Stream

Once you have a PDFDocument object and have done modification onto it (for example add annotations to page in the document), you can save it back to pdf file. Related APIs: void Save(String fileName) void SaveToStream(Stream stream) byte[] SaveToBytes() PDF Rendering and Conversion RasterEdge Document Imaging SDK supports converting PDF document and pages within to various image and document types with customized options. You can convert PDF Document to PNG, JPEG, BMP, and GIF image formats to view as in RasterEdge document WebViewer and Win form document viewer. You can also convert PDF Document and pages to SVG. SVG is a vector image format that is supported by HTML5 standard and therefore supported by most of the up to date web browsers. PDF document can also be converted to tiff file. Convert PDFDocument to Images You can convert PDFDocument to raster images collection. This is a bulk operation with customized options. Related APIs: void ConvertToImages(ImageType targetType, int resolution, String directory, String fileName) void ConvertToImages(ImageType targetType, float zoomValue, String directory, String fileName) These methods will automatically convert every page in PDF document to image files, with the page index append to fileName. Note that, the resolution is default to be 96 dpi for monitor displaying purpose. You can adjust resolution to enlarge or reduce the size of image file. You can also specify the zoomValue to adjust image size.You can get the original image with zoomValue set to be 1. Convert

PDFPage to Image File

To get full control over the rendering process, you can work with PDFPage object. First, get specific PDFPage object from pdf document by BasePage GetPage(int index), and then you can

render PDFPage object to REImage or other common image formats with customized parameters. Related APIs: REImage CropImage(Rectangle sourceRegion, Size targetSize) REImage ConvertToImage() void ConvertToImage(ImageType toType,String filePath) void ConvertToImage(ImageType toType,int resolution, String filePath) If you want to zoom in the page with a large factor, say 8x and paint the whole page. This will cost not only high usage of memory resource but also a considerable amount of time to proceed. The common practice is to convert part of the page with a zoom in factor at a time. And CropImage API is designed for this purpose. Convert PDFPage to Bitmap In .Net framework Bitmap is a frequently used class in image processing. RasterEdge provide you with APIs to directly convert PDFPage to Bitmap objects which then can be drew on graphics of for example win form controls. These APIs returning a Bitmap object are faster than return a REImage object taking into account that additional operations needed with REImage.

Bitmap GetBitmap() Bitmap GetBitmap(float zoomValue) Bitmap GetBitmap(float zoomValue) Bitmap GetBitmap(Rectangle sourceRectangle, Size targetSize) Note that the resulting Bitmap cannot be too big to handle due to the restriction of system memory. Typically if a resulting pdf page magnified with a zoom in factor has a dimension product over 3000*3000, we recommend you deal with them in partitions. Bitmap GetBitmap(Rectangle sourceRectangle, Size targetSize) is a good choose // load pdf document PDFDocument doc = new PDFDocument(@"d:\sample.pdf"); //get the first page PDFPage page = (PDFPage)doc.GetPage(0);

// the orignal page dimension in pixel measured in 96 dpi float orignalWidth = page.GetWidth() * 96; float orignalHeight = page.GetHeight() * 96; //zoom in with a factor of 8, and divide the orignal pictures into 64 partitions // each partition has a size of the orignal page in 96 dpi // get the left top part Bitmap bmp = page.GetBitmap(new Rectangle(0, 0, (int)(orignalWidth / 8), (int)(orignalHeight / 8)), new Size((int)orignalWidth, (int)orignalHeight));.

You can also draw the page directly onto a graphics using the following APIs Draw(Graphics g, PointF loaction) void Draw(Graphics g, PointF loaction, Size targetSize )

Convert PDF to SVG SVG part of HTML5 standard, therefore it can viewed directly using most of the modern browsers without installing additional plugin or add-on on the end user’s computer. Related APIs: PDFDocument.ConvertToVectorImages(ContextType targetType, String directory, String fileName,RelativeType type); PDFPage.ConvertToVectorImage(ContextType targetType, String directory, String fileName,RelativeType type);

SVG file generated can be used in one of the two ways: 1. Svg file can be used as a stand-alone external resource of a web page. In this case the resources such as font and image files referenced by svg file are mapped by a relative path with respect to the svg file itself. Choose RelativeType.SVG as input parameter when you use svg file as an external resource. 2. The content of svg file may be extracted and then embedded into html code in a web application. If this is the case the resources referenced are mapped through a relative path to the web project working directory. Choose RelativeType.ASP as input parameter in this situation. C# sample code string filePath = @"c\sample.pdf"; //directory to store the svg file and resources string svgfileDirectory = @"c\sample\ ";

// load pdf file to creat PDFDocument object PDFDocument doc = new PDFDocument(filePath);

// you can convert the whole document to a list of svg files // each page of the document is renderd to a svg file with page index //appended //to the name doc.ConvertToVectorImages(ContextType.SVG, svgfileDirectory,"SampleSVG",RelativeType.SVG);

// or you can convert specific page to svg file // Get the first page of pdf document and convert it to svg file PDFPage page = (PDFPage)doc.GetPage(0); page.ConvertToVectorImage(ContextType.SVG, svgfileDirectory, "SampleSVG", RelativeType.SVG); // if you want to embed the svg content into html code in your web application // the relative path is to your web project working directory, change the //parameter of relative type to ASP doc.ConvertToVectorImages(ContextType.SVG, svgfileDirectory, "SampleSVG", RelativeType.ASP);

Convert PDF Document to TIFF You can convert PDF document to TIFF file through the following code. WorkRegistry.Reset();// invoke this static method only once at the beginning of codes: //load pdf document PDFDocument doc = new PDFDocument(@"c:\sample.pdf"); //convert PDF to TIFF file and save it to specified file path doc.ConvertToDocument(DocumentType.TIFF, @"PDFToTIFF.tiff"); If you need generate the tiff file with a greater resolution (or bigger size) you can use the following code to generate an x2 resolution tiff. doc.ConvertToDocument(DocumentType.TIFF, 2.0f, @"C:\x2.tif");

Convert Other Document Types to PDF File You may also convert Word, Excel and TIFF document to PDF file. //load Word document DOCXDocument doc = new DOCXDocument(@"c:\sampleword.docx"); //// load Excel document //XLSXDocument doc = new XLSXDocument(@"c:\samplexl.xlsx"); //// load Tiff document //TIFFDocument doc = new TIFFDocument(@"c:\sampleTiff.xlsx"); //convert document to PDF file and save it to specified file path doc.ConvertToDocument(DocumentType.PDF, @"pdfConverted.pdf");

PDF Annotations RasterEdge Image enables developers to add annotations to PDF document page for collaboration purpose. These annotation objects include text, free hand, line, lines, ellipse, rectangle, rubber stamp, hotspot and embedded image. With PDF dll and Annotation dll provided by RasterEdge Image, developers can: Add rich annotations to pages in PDF document. Added annotations can be flexibly and easily edited as independent objects Free to resize, move, rotate and reshape annotation on PDF page Adjust the font style of created text annotation on PDF document enable to burn generated image annotations onto the native file format as embedded images You can find an online annotation demo at http://www.rasteredge.com/dotnet-imaging/webviewer-demo/. To use functions above, the required assemblies are: RasterEdge.Imaging.PDF.dll RasterEdge.Imaging.Annotation.dll RasterEdge.Imaging.Basic.dll Sample code: // generate the annotation object // create a line annotation starting at point (0.0) and end with //point(100,100). The position may be adjusted according to the resolution at //measurement with the default resolution to be 96 dpi. AnnotationHandler anno = AnnotationGenerator.CreateLineAnnotation(new RasterEdge.Imaging.Annotation.Basic.LinePoint(0, 0), new RasterEdge.Imaging.Annotation.Basic.LinePoint(100, 100)); PDFDocument doc = new PDFDocument(@"c:\sample.pdf"); PDFPage page = (PDFPage)doc.GetPage(0); //add the line annotation on the pdf page. page.AddAnnotation(anno); doc.Save(@"c:\annotatedSample.pdf");

See Also Annotation Create Barcode in PDF

RasterEdge Barcode processing dll offers comprehensive functions for developers to generate and design both 1d & 2d barcode images on PDF file. Sample Code: //generate a code39 barcode Linear linearBarcode = new Linear(); linearBarcode.Type = BarcodeType.CODE39; linearBarcode.Data = "123456789"; linearBarcode.Resolution = 96; linearBarcode.Rotate = Rotate.Rotate0; // load pdf document, you can also load document like tiff, word, excel,ppt PDFDocument doc = new PDFDocument(@"c:\sample.pdf"); // get the first page BasePage page = doc.GetPage(0); // generate reimage of this barcode REImage barcodeImage = linearBarcode.ToImage(); //add barcode image to the first page the top left vertex of barcode image rectangle is at point(100,100) page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f)); // save changes to the pdf doc.Save(@"c:\sample. pdf ");

See Also Barcode Create Read Barcode from PDF You can read barcode information from pdf document. Sample code: public static void ReadBarcodeFromPDF(string filename, int pageIndex) { //generate pdf document PDFDocument doc = new PDFDocument(filename); //get the page you want to read barcode from BasePage page = doc.GetPage(pageIndex); //set reader setting ReaderSettings setting = new ReaderSettings(); setting.AddTypesToRead(BarcodeType.Code39); // read out barcode information Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page); //output barcode information foreach (Barcode barcode in barcodes) { Console.WriteLine(barcode.DataString);

} }

See also Barcode read How to’s How to: Create an Image-only PDF Document You can construct a PDFDocument object from images files. //invoke this method only once at the beginning of your code to register all assemblies you referenced to your project WorkRegistry.Reset(); // construct image source, you can create REImage from under a directory with different image formats REImage img1 = new REImage(@"c:\sample1.png"); REImage img2 = new REImage(@"c:\sample2.jpg"); REImage[] imageSource = new REImage[2]; imageSource[0] = img1; imageSource[1] = img2; // create a word document using image source, one image per page PDFDocument doc = new PDFDocument(imageSource); doc.Save(@"c:\sample.pdf");

How to: Create Thumbnail of PDF Document You can convert PDFDocument to image files with a zoom factor suitable for thumbnail image. // load PDF document PDFDocument doc = new PDFDocument(@"c:\sample.pdf"); // compute zoom out factor // get the first page as sample page PDFPage page =(PDFPage)doc.GetPage(0); // the original height and width are measured at 96 dpi float originalWidth = page.GetWidth()*96; // assume you want a thumbnail is 100 pixel in width, compute the scale factor //the height will scale accordingly with a fixed width/height ratio float scaleFactor = 100f/originalWidth; string directory = @"c:\Thumbnail"; // construct thumbnail image under the directory with a file name thumail01.png,

//thumnail02.png doc.ConvertToImages(ImageType.PNG, scaleFactor,directory,"thumbnail");

How to: Add WaterMark to PDFPage You can add transparent WaterMark to PDFPage using annotation of Embedded Image, Text or RubberStamp

// set annotation size //the position of the annotation reletive to its potiential container float x = 120.0f; float y = 120.0f; float width = 300.0f; float height = 100.0f; string text = "this is RubberStamp annotation"; Font font = new Font("Arial", 12.0F, FontStyle.Italic); AnnotationBrush fontBrush = new AnnotationBrush(); fontBrush.FillType = FillType.Solid; fontBrush.Solid_Color = new REColor(100, 255, 0, 0); RubberStampAnnotation anno = AnnotationGenerator.CreateRubberStampAnnotation(x, y, width, height, text, font, fontBrush); anno.OutLine = new LinePen(); anno.OutLine.Brush = new AnnotationBrush(); anno.OutLine.Brush.FillType = FillType.Solid; anno.OutLine.Brush.Solid_Color = new REColor(255, 10, 100, 100); anno.OutLine.Width = 2.0f; anno.Fill = new AnnotationBrush(); anno.Fill.FillType = FillType.Solid; anno.Fill.Solid_Color = new REColor(0, 20, 20, 20); anno.CornerRadius = 1000f; //set the overal transprency, this value has an overal impact on all //colors related to this annotation. Note the default value is 1 which // is complete transparency anno.SetTransparency(0.9f); // create a line annotation starting at point (0.0) and end with point(100,100) note only the relative position of the start and end point is used. PDFDocument doc = new PDFDocument(@"c:\sample.pdf"); PDFPage page = (PDFPage)doc.GetPage(0); //add the line at point (100,100) on the word page. The position is measured at default 96 resolution with respect to the word image.And therefore subject to the change of the size of the word image page.AddAnnotation(anno); doc.Save(@"c:\annotatedSample.pdf");

Word Introduction to Word Functions With RasterEdge.Imaging.MSWordDocx.dll, you can do the following Load an existing Word(docx, doc) file Convert the pages of Word file to image Convert word file to PDF, TIFF or SVG file Annotate on word file, and save changes in native file format Prerequisite for using these functions is to reference our Word processing dll (RasterEdge.Imaging.MSWordDocx.dll) to you project. .docx and .doc file formats RasterEdge Word SDK support .docx and .doc word file formats. .doc is the older format of the word files supported by 2003 or earlier version of MS Word .docx is the spreedsheet supported by 2007 or later version of MS Word Here is a table showing two file formats and their corresponding RasterEdge Progamming Class .docx

.doc

DOCXDocument

DOCDocument

DOCXPage

DOCPage

Because two kinds of programming Classes inherit the same Supper Classes (BaseDocument and BasePage), the APIs are identical. Thus all the demo code snippets in the following sections are applicable to both docx and doc files. Please choose corresponding programming class with respect to different file formats.

Load and Save Word Document About Word Programming Classes Word document assembly provides two Word document processing classes, which are DOCXDocument and DOCXPage.

DOCXDocument: This class refers to Word document file represented in memory and it contains all document information of aWord file. It is an extension of BaseDocument. DOCXPage: This class refers to Word document page contained in DOCXDocument. It uses BasePage as prototype. Word Document Object DOCXDocument represents the main structure of a document and the pages it contains. When a DOCXDocument object is created, you can obtain information about the pages and other document structures. Load Word document The example that follows shows how to load a Word file into DOCXDocument. Generate a DOCXDocumentobject from stream. DOCXDocument doc = new DOCXDocument(Stream s); Or for file with .doc suffix DOCDocument doc = new DOCDocument(Stream s);

Generate a DOCXDocument object from local file path. DOCXDocumentdoc = new DOCXDocument(@"D: \sample1.docx"); Or for file with .doc suffix DOCDocumentdoc = new DOCDocument(@"D: \sample1.doc");

Once you have created a document object, you can obtain information about this document, and get page object out of it by calling GetPage(int pageIndex). C# public int GetPageCount(Stream s) { DOCXDocumentdocument = new DOCXDocument(s);

return document.GetPageCount(); }

Save Word Document You can save DOCXDocument to file after modifications, like adding annotations on Word. Related APIs: void Save(String fileName) void SaveToStream(Stream stream) byte[] SaveToBytes() Get preview of word Document RasterEdge document imaging sdk provide you with APIs to get a Bitmap of the first page in the word document file. You are able to get a preview of this word document without load and process the entire document in memory. Related APIs: static Bitmap GetPreviewImage(string file Size targetSize) static Bitmap GetPreviewImage(byte[] data,Size targetSize) static Bitmap GetPreviewImage(Stream s,Size targetSize) Annotations on Word Document You can add different types of annotations onto DOCXPage object and save the changes back in .docx file format. You can find an online annotation demo at http://www.rasteredge.com/dotnet-imaging/webviewer-demo/. To use functions above, the required assemblies are: RasterEdge.Imaging.MSWordDocx.dll RasterEdge.Imaging.Annotation.dll RasterEdge.Imaging.Basic.dll Sample code: // generate the annotation object // create a line annotation starting at point (0.0) and end with point(100,100). AnnotationHandler anno = AnnotationGenerator.CreateLineAnnotation(new RasterEdge.Imaging.Annotation.Basic.LinePoint(0, 0), new RasterEdge.Imaging.Annotation.Basic.LinePoint(100, 100));

// load Word document DOCXDocument doc = new DOCXDocument(@"c:\sampleword.docx"); DOCXPage page = (DOCXPage)doc.GetPage(0); //add the line at point (100,100) on Word page. The position is measured at //default 96 resolution with respect to word image.And therefore subject to the change of //the size of Word image page.AddAnnotation(anno); // save the modified Word back to file doc.Save(@"c:\annotatedSample.docx");

See also Annotation Word Rendering and Conversions RasterEdge Document Imaging SDK supports converting Word document to various image and document types with customized options. You can convert Word Document to PNG, JPEG, BMP, and GIF image formats. You can also convert Word Document to other document types including TIFF, PDF and SVG. SVG is a vector image format that is supported by HTML5 standard and therefore can be viewed at most of the up to date web browsers. Convert DOCXDocument to Images You can convert DOCXDocument to raster images collection. This is a batch operation with customized options. Related APIs: void ConvertToImages(ImageType targetType, int resolution, String directory, String fileName) void ConvertToImages(ImageType targetType, float zoomValue, String directory, String fileName) These methods will automatically convert every page in DOCXDocument to an image file, with the page index append to fileName. Note that, the resolution is default to be 96 dpi for monitor displaying purpose. You can adjust to resolution to enlarge or reduce the size of image file. You can also specify the zoomValue to adjust image size.You can get the original image with zoomValue set to be 1. Convert DOCXPage to Image File

To get full control over the rendering process, you can work with DOCXPage object. First, get specific DOCXPage object from word document by BasePage GetPage(int index), and then you can render DOCXPage object to REImage or other common image formats with customized parameters. Related APIs: REImage CropImage(Rectangle sourceRegion, Size targetSize) REImage ConvertToImage() void ConvertToImage(ImageType toType, String filePath) void ConvertToImage(ImageType toType, int resolution, String filePath) If you want to zoom in page with a large factor, say 8x and paint the whole page. This will cost not only a very high usage of memory resource but also a considerable amount of time to proceed. The common practice is to show part of page with a zoom in factor at a time. And the CropImage API is designed for this purpose. Convert DOCXPage to Bitmap In .Net framework Bitmap is a frequently used class in image processing. RasterEdge provide you with APIs to directly convert DOCXPage to Bitmap objects which then can be drew on graphics of for example win form controls. These APIs returning a Bitmap object are faster than return a REImage object taking into account that additional operations are needed with REImage.

Bitmap GetBitmap() Bitmap GetBitmap(float zoomValue) Bitmap GetBitmap(Rectangle sourceRectangle, Size targetSize) Note that the resulting Bitmap cannot be too big to handle due to the restriction of system memory. You can divide the big page (often zoomed in with a factor) into parts and deal with them separately. Typically if a word page image zoomed or not resulted in a dimension product over 3000*3000, we recommend you deal with them in partitions.

// load word document DOCXDocument doc = new DOCXDocument(@"d:\sample.word"); //get the first page DOCXPage page = (DOCXPage)doc.GetPage(0);

// the orignal page dimension in pixel measured in 96 dpi float orignalWidth = page.GetWidth() * 96; float orignalHeight = page.GetHeight() * 96; //zoom in with a factor of 8, and divide the orignal pictures into 64 partitions // each partition has a size of the orignal page in 96 dpi

// get the left top part Bitmap bmp = page.GetBitmap(new Rectangle(0, 0, (int)(orignalWidth / 8), (int)(orignalHeight / 8)), new Size((int)orignalWidth, (int)orignalHeight));

You can also draw the page directly onto a graphics using the following APIs Draw(Graphics g, PointF loaction) void Draw(Graphics g, PointF loaction, Size targetSize )

Convert DOCXDocument to PDF or TIFF File Sample code: public static void ConvertWordToPDF(string sourceFilePath, string targetFilePath) { // load word document DOCXDocument doc = new DOCXDocument(sourceFilePath); //convert word to pdf and save to target file path doc.ConvertToDocument(DocumentType.PDF, targetFilePath); ////convert word to tiff and save to target file path //doc.ConvertToDocument(DocumentType.TIFF, targetFilePath); } If you need generate the tiff file with a greater resolution (or bigger size) you can use the following code to generate an x2 resolution tiff. doc.ConvertToDocument(DocumentType.TIFF, 2.0f, @"C:\x2.tif");

Convert Word to SVG SVG is part of HTML5 standard, therefore it can be viewed directly using most of the modern browsers without installing additional plugin or add-on on the end user’s computer. Related APIs: DOCXDocument.ConvertToVectorImages(ContextType targetType, String directory, String fileName,RelativeType type); DOCXPage.ConvertToVectorImage(ContextType targetType, String directory, String fileName,RelativeType type);

SVG file generated can be used in one of the two ways: 1. Svg file can be used as a stand-alone external resource of a web page. In this case the resources such as font and image files referenced by svg file are mapped by a relative path with respect to the svg file itself. Choose RelativeType.SVG as input parameter when you use svg file as an external resource. 2. The content of svg file may be extracted from it and embedded into html code in a web application. If this is the case the resources referenced is mapped through a relative path to the web project working directory. Choose RelativeType.ASP as input parameter in this situation. C# sample code string filePath = @"c\sample.docx"; //directory to store the svg file and resources string svgfileDirectory = @"c\sample\ ";

// load word file to creat DOCXDocument object DOCXDocument doc = new DOCXDocument (filePath); // you can convert the whole document to a list of svg files // each page of the document is renderd to a svg file with page index //appended //to the file name doc.ConvertToVectorImages(ContextType.SVG,svgfileDirectory, "SampleSVG", RelativeType.SVG); // or you can convert specific page to svg file // Get the first page of document and convert it to svg file DOCXPage page = (DOCXPage)doc.GetPage(0); page.ConvertToVectorImage(ContextType.SVG,svgfileDirectory, "SampleSVG", RelativeType.SVG); // if you want to embed the svg content into html code in your web application // the relative path is to your web project working directory, change the //parameter of relative type to ASP doc.ConvertToVectorImages(ContextType.SVG,svgfileDirectory, "SampleSVG", RelativeType.ASP);

}

Create Barcode in Word

RasterEdge Barcode processing dll offers comprehensive functions for developers to generate and design both 1d & 2d barcode images on word file. Sample Code: public staticvoid CreateBarcodeInWord() { //generate a code39 barcode Linear linearBarcode = newLinear(); linearBarcode.Type = RasterEdge.Imaging.Barcode.Creator.BarcodeType.CODE39; linearBarcode.Data = "123456789"; linearBarcode.Resolution = 96; linearBarcode.Rotate = Rotate.Rotate0; // load word document, you can also load document like tiff, pdf, excel, ppt DOCXDocument doc = new DOCXDocument(@"c:\sample.docx"); // get the first page BasePage page = doc.GetPage(0); // generate reimage of this barcode REImage barcodeImage = linearBarcode.ToImage(); //add barcode image to the first page page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f)); // save changes to the word doc.Save(@"c:\sample.docx"); }

See Also Barcode Create Read Barcode from Word You can read barcode information from Word document. Sample code: public static void ReadBarcodeFromWord(string filename, int pageIndex) { //generate word document DOCXDocument doc = new DOCXDocument(filename); //get the page you want to read barcode from BasePage page = doc.GetPage(pageIndex); //set reader setting ReaderSettings setting = new ReaderSettings(); setting.AddTypesToRead(RasterEdge.Imaging.Barcode.Scanner.BarcodeType.Code39); // read out barcode information Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page);

//output barcode information foreach (Barcode barcode in barcodes) { Console.WriteLine(barcode.DataString); } }

See also Barcode Read How to’s How to: Create Thumbnail of DOCXDocument You can convert DOCXDocument to image files with a zoom factor suitable for thumbnail image. // load word document DOCXDocument doc = new DOCXDocument(@"c:\sample.docx"); // compute zoom out factor // get the first page as sample page DOCXPage page =(DOCXPage)doc.GetPage(0); // the original height and width are measured at 96 dpi float originalWidth = page.GetWidth()*96; // assume you want a thumbnail size of 500 pixel in width and compute the zoomfactor float zoomFactor = 500f/originalWidth; string directory = @"c:\Thumbnail"; // construct thumbnail image under the directory with a file name thumail01.png, thumnail02.png doc.ConvertToImages(ImageType.PNG,zoomFactor,directory,"thumbnail");

Excel Introduction to Excel Functions With RasterEdge.Imaging.MSExcel.dll, programmers are provided with APIs to do the following: Load an existing Excel (xlsx and xls) file Convert the pages of Excel file to image Convert Excel file to PDF, TIFF or SVG file Annotate on Excel file, and save changes in native file format Prerequisite for using these functions is to reference our Excel processing dll (RasterEdge.Imaging.MSExcel.dll) to your project. .xlsx and .xls file formats RasterEdge Excel SDK support .xlsx and .xls Excel file formats. .xls is the older format of the spreedsheet supported by 2003 or earlier version of MS Excel .xlsx is the spreedsheet supported by 2007 or later version of MS Excel Here is a table showing two file format and their corresponidng RasterEdge Progamming Class .XLSX

.XLS

XLSXDocument

XLSDocument

XLSXPage

XLSPage

Because two kinds of programming Classes inherit the same Supper Classes (BaseDocument and BasePage), the APIs are identical. Thus all the demo code snippets in the following sections are applicable to both xlsx and xls files. Please choose corresponding programming class with respect to different file formats. About Excel Programming Classes Excel document assembly provides two document processing classes, which are XLSXDocument/XLSDocument and XLSXPage/XLSPage. XLSXDocument/XLSDocument: This class refers to Excel document and it contains all document information of Excel file. It is an extension of BaseDocument. XLSXPage: This class refers to Excel sheet contained in XLSXDocument/XLSDocument and uses BasePage as prototype.

Excel Document Object XLSXDocument/XLSDocument represents the main structure of a xls/xlsx file and the sheet/pages it contains. When a XLSXDocument/XLSDocument object is created, we can easily extract information about the pages/sheet and other document structures. Load Excel Document The example that follows shows how to load an Excel file into XLSXDocument/XLSDocument. Generate a XLSXDocument/XLSDocument object from stream. XLSXDocument doc = new XLSXDocument (Stream s); XLSDocument doc = new XLSDocument (Stream s);

Generate a XLSXDocument/XLSDocumentobject from file path. XLSXDocument doc = new XLSXDocument(@"D:\BugList\sample1.xlsx "); XLSDocument doc = new XLSDocument(@"D:\BugList\sample1.xlsx ");

Once you have created a document object, you can obtain information about this document, and get page object out of it by calling GetPage(int pageIndex). C# public int GetPageCount(Stream s) { XLSXDocument document = new XLSXDocument(s); return document.GetPageCount(); }

Save Excel Document You can save XLSXDocument to file after modifications like adding annotations have been done. Related APIs: void Save(String fileName) void SaveToStream(Stream stream) byte[] SaveToBytes()

Get preview of Excel Document RasterEdge excel-add on provide you with APIs to get a Bitmap of the first page/sheet in the excel document file. You are able to get a preview of this excel document without load and process the entire document in memory. Note that for excel sheet/page in large size, the image may be cropped for better presentation. Related APIs: static Bitmap GetPreviewImage(string file Size targetSize) static Bitmap GetPreviewImage(byte[] data,Size targetSize) static Bitmap GetPreviewImage(Stream s,Size targetSize) Annotations on Excel Document You can add different types of annotations onto XLSXPage object and save the changes back in .xlsx native file format. You can find an online annotation demo at http://www.rasteredge.com/dotnet-imaging/webviewer-demo/. To use functions above, the required assemblies are: RasterEdge.Imaging.MSExcel.dll RasterEdge.Imaging.Annotation.dll RasterEdge.Imaging.Basic.dll Sample code: // create a line annotation starting at point (0.0) and end with point(100,100). AnnotationHandler anno = AnnotationGenerator.CreateLineAnnotation(new RasterEdge.Imaging.Annotation.Basic.LinePoint(0, 0), new RasterEdge.Imaging.Annotation.Basic.LinePoint(100, 100)); // load excel document XLSXDocument doc = new XLSXDocument(@"c:\sample.xlsx "); XLSXPage page = (XLSXPage)doc.GetPage(0); //add the line at point (100,100) on the excel page. The position is measured at default 96 resolution with respect to the excel page image.And therefore subject to the change of the size of the excel image page.AddAnnotation(anno); // save the modified excel back to file doc.Save(@"c:\annotatedSample.xlsx");

Excel Rendering and Conversions RasterEdge Document Imaging SDK supports converting Excel document to various image and document types with customized options. You can convert Excel Document to PNG, JPEG, BMP, and GIF image formats. You can also convert Excel Document to other document types including TIFF, PDF and SVG. SVG is a vector image format that is supported by HTML5 standard and therefore can be viewed at most of the up to date web browsers. Convert XLSXDocument to Images You can convert XLSXDocument to raster images collection. This is a batch operation with customized options. Related APIs: void ConvertToImages(ImageType targetType, String directory, String fileName) These methods will automatically convert every page in XLSXDocument to an image file, with the page index append to fileName. Note that, the resolution is default to be 96 dpi for monitor displaying purpose. You can adjust resolution to enlarge or reduce the size of image file. You can also specify the zoomValue to adjust image size. You can get the original image with zoomValue set to be 1. Please note that Excel sheet can be quite big in dimension, in that case we recommend you to use CropImage(Rectangle sourceRegion, Size targetSize) to handle the sheet in division. Convert XLSXPage to Image File To get full control over the rendering process, you can work with XLSXPage object. First get specific XLSXPage object from exel document by BasePage GetPage(int index),and then you can render XLSXPage object to REImage or other common image formats with customized parameters. Related APIs: REImage CropImage(Rectangle sourceRegion, Size targetSize) REImage ConvertToImage() void ConvertToImage(ImageType toType,String filePath) void ConvertToImage(ImageType toType,int resolution, String filePath)

If you want to zoom in page with a large factor, say 8x and paint the whole page. This will cost not only a very high usage of memory resource but also a considerable amount of time to proceed. The common practice is to show part of page with a zoom in factor at a time. And the CropImage API is designed for this purpose.

Convert XLSXPage to Bitmap In .Net framework Bitmap is a frequently used class in image processing. RasterEdge provide you with APIs to directly convert DOCXPage to Bitmap objects which then can be drew on graphics of for example win form controls. These APIs returning a Bitmap object are faster than those returning a REImage object taking into account that additional operations are needed with REImage.

Bitmap GetBitmap() Bitmap GetBitmap(float zoomValue) Bitmap GetBitmap(Rectangle sourceRectangle, Size targetSize) Note that the Excel sheet could be too big to deal with using a single bitmap due to the restriction of system memory. You can divide the big page image (zoomed in with a factor or not) into parts and deal with them separately. Typically if an excel page image zoomed or not resulted in a dimension product over 3000*3000, we recommend you deal with them in partitions. Bitmap GetBitmap(Rectangle sourceRectangle, Size targetSize) is a good choose. sample code: // load excel document XLSXDocument doc = new XLSXDocument(@"c:\sample.docx");

// get the first page as sample page XLSXPage page = (XLSXPage)doc.GetPage(0); // the orignial height and width are measured at 96 dpi of this page float originalWidth = page.GetWidth() * 96; float originalHeight = page.GetHeight() * 96; // if the dimension is too big, divide it into partitions //in this example divide excel sheet into 2 // get bitmap of top half of the sheet without resize. page.GetBitmap(new Rectangle(0, 0, (int)(originalWidth), (int)(originalHeight / 2)), new Size((int)(originalWidth ), (int)(originalHeight / 2)));

You can also draw the page directly onto a graphics using the following APIs Draw(Graphics g, PointF loaction) void Draw(Graphics g, PointF loaction, Size targetSize )

Convert XLSXDocument to PDF or TIFF File Sample code: public static void ConverExcelToPDF(string sourceFilePath, string targetFilePath) { // load excel document XLSXDocument doc = new XLSXDocument(sourceFilePath); //convert excel to pdf and save to target file path doc.ConvertToDocument(DocumentType.PDF, targetFilePath); ////convert excel to tiff and save to target file path //doc.ConvertToDocument(DocumentType.TIFF, targetFilePath); } If you need generate the tiff file with a greater resolution (or bigger size) you can use the following code to generate an x2 resolution tiff. doc.ConvertToDocument(DocumentType.TIFF, 2.0f, @"C:\x2.tif");

Convert Excel To SVG SVG part of HTML5 standard, therefore it can viewed directly using most of the modern browsers without installing additional plugin or add-on on the end user’s computer. Related APIs: DOCXDocument.ConvertToVectorImages(ContextType targetType, String directory, String fileName,RelativeType type); DOCXPage.ConvertToVectorImage(ContextType targetType, String directory, String fileName,RelativeType type);

SVG file generated can be used in one of the two ways:

1. Svg file can be used as a stand-alone external resource of a web page. In this case the resources such as font and image files referenced by svg file are mapped by a relative path with respect to the svg file itself. Choose RelativeType.SVG as input parameter when you use svg file as an external resource. 2. The content of svg file may be extracted from it and embedded into html code in a web application. If this is the case the resources referenced is mapped through a relative path to the web project working directory. Choose RelativeType.ASP as input parameter in this situation. C# sample code string filePath = @"c\sample.xlsx"; //directory to store the svg file and resources string svgfileDirectory = @"c\sample\ ";

// load word file to creat XLSXDocument object XLSXDocument doc = new XLSXDocument (filePath); // you can convert the whole document to a list of svg files // each page of the document is renderd to a svg file with page index //appended //to the file name doc.ConvertToVectorImages(ContextType.SVG,svgfileDirectory, "SampleSVG", RelativeType.SVG); // or you can convert specific page to svg file // Get the first page of document and convert it to svg file XLSXPage page = (XLSXPage)doc.GetPage(0); page.ConvertToVectorImage(ContextType.SVG,svgfileDirectory, "SampleSVG", RelativeType.SVG); // if you want to embed the svg content into html code in your web application // the relative path is to your web project working directory, change the //paramter like this doc.ConvertToVectorImages(ContextType.SVG,svgfileDirectory, "SampleSVG", RelativeType.ASP);

}

Create Barcode in Excel RasterEdge Barcode processing dll offers comprehensive functions for developers to generate and design both 1d & 2d barcode images on Excel file.

Sample Code: // generate a code39 barcode Linear linearBarcode = new Linear(); linearBarcode.Type = RasterEdge.Imaging.Barcode.Creator.BarcodeType.CODE39; linearBarcode.Data = "123456789"; linearBarcode.Resolution = 96; linearBarcode.Rotate = Rotate.Rotate0;

// load excel document, you can also load document like tiff, word, excel, ppt XLSXDocument doc = new XLSXDocument(@"c:\sample.xlsx"); // get the first page BasePage page = doc.GetPage(0);

// generate reimage of this barcode REImage barcodeImage = linearBarcode.ToImage(); //add barcode image to the first page page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f)); // save changes to the excel doc.Save(@"c:\sample.xlsx");

See Also Barcode Create Read Barcode from Excel You can read barcode information from Excel document. Sample code: public static void ReadBarcodeFromExcel(string filename, int pageIndex) { //generate excel document XLSXDocument doc = new XLSXDocument(filename); //get the page you want to read barcode from BasePage page = doc.GetPage(pageIndex); //set reader setting ReaderSettings setting = new ReaderSettings(); setting.AddTypesToRead(RasterEdge.Imaging.Barcode.Scanner.BarcodeType.Code39); // read out barcode information Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page); //output barcode information foreach (Barcode barcode in barcodes) { Console.WriteLine(barcode.DataString); }

}

See also Barcode read How to’s How to: Create Thumbnail of Excel You can convert Excel document to image files with a zoom factor suitable for thumbnail image. // load excel document XLSXDocument doc = new XLSXDocument(@"c:\sample.xlsx"); // create thumbnailImage of target size 100*130 // the original height and width are measured at 96 dpi for (int i = 0; i < doc.GetPageCount(); i++) { BasePage page = doc.GetPage(i); // create a thumbnail image that is cropped from the orignial image REImage img = page.CropImage(new Rectangle(0, 0, 100, 130), new Size(100, 130)); img.Save(ImageType.PNG, @"c:\thumbnail" + i + ".png"); }

PowerPoint Introduction to PoinerPoint Functions With RasterEdge.Imaging.MSPPT.dll, programmers are provided with APIs to do the following: Load an existing power point file (pptx, ppt) Convert the pages of PowerPoint file to images Convert PowerPoint file to PDF, TIFF or SVG file Annotate on PowerPoint file, and save changes in native file format Prerequisite for using these functions is to reference our PowerPoint processing dll (RasterEdge.Imaging. MSPPT.dll) to your project. .pptx and .ppt file formats RasterEdge Excel SDK support .pptx and .ppt Excel file formats. .pptx is the older format of the PowerPoint file supported by 2003 or earlier version of MS PowerPoint .ppt is the PowerPoint supported by 2007 or later version of MS PowerPoint Here is a table showing two file format and their corresponding RasterEdge Progamming Class .pptx

.ppt

PPTXDocument

PPTDocument

PPTXPage

PPTPage

Because two kinds of programming Classes inherit the same Supper Classes (BaseDocument and BasePage) the APIs are identical. Thus all the demo code snippets in the following sections are applicable to pptx and ppt files. Please choose corresponding programming class with respect to different file formats.

About PowerPoint Programming Classes PowerPoint document assembly provides two document processing classes, which are PPTXDocument and PPTXPage.

PPTXDocument: This class refers to PowerPoint document and it contains all document information of PowerPoint file. It is an extension of BaseDocument. PPTXPage: This class refers to PowerPoint document page contained in PPTXDocument and uses BasePage as prototype. PowerPoint Document Object PPTXDocument represents the main structure of a document and the pages it contains. When a PPTXDocument object is created, we can easily extract information about the pages and other document structures. Load PowerPoint Document The example that follows shows how to load an pptx file into PPTXDocument. Generate a PPTXDocument object from stream. PPTXDocument doc = new PPTXDocument (Stream s);

Generate a PPTXDocument object from file path. PPTXDocument doc = new PPTXDocument (@"c:\sample.pptx"); or for file with .ppt suffix PPTDocument doc = new PPTDocument (@"c:\sample.ppt");

Once you have created a document object, you can obtain information about this document, and get page object out of it by calling GetPage(int pageIndex). C# public int GetPageCount() { PPTXDocument doc = new PPTXDocument (@"c:\sample.pptx"); doc.GetPageCount(); }

Save PowerPoint Document

You can save PPTXDocument to file after modifications for example adding annotations have been done. Related APIs: void Save(String fileName) void SaveToStream(Stream stream) byte[] SaveToBytes()

Get preview of Powerpoint Document RasterEdge powerpoint-addon on provide you with APIs to get a Bitmap of the first page/slide in the powerpoint document file. You are able to get a preview of this powerpoint document without load and process the entire document in memory. Related APIs: static Bitmap GetPreviewImage(string file Size targetSize) static Bitmap GetPreviewImage(byte[] data,Size targetSize) static Bitmap GetPreviewImage(Stream s,Size targetSize) Annotations on PowerPoint Document You can add different types of annotations onto PPTXPage object and save the changes back in .pptx native file format. You can find an online annotation demo at http://www.rasteredge.com/dotnet-imaging/webviewer-demo/. To use functions above, the required assemblies are: RasterEdge.Imaging.MSPPT.dll RasterEdge.Imaging.Annotation.dll RasterEdge.Imaging.Basic.dll Sample code: // create a line annotation starting at point (0.0) and end with point(100,100). AnnotationHandler anno = AnnotationGenerator.CreateLineAnnotation(new RasterEdge.Imaging.Annotation.Basic.LinePoint(0, 0), new RasterEdge.Imaging.Annotation.Basic.LinePoint(100, 100)); // load powerpoint document PPTXDocument doc = new PPTXDocument(@"c:\sample.pptx "); PPTXPage page = (PPTXPage)doc.GetPage(0); //add the line at point (100,100) on the powerpoint page.

//The position is measured at default 96 resolution with respect to the powerpoint page rendered as image. page.AddAnnotation(anno); // save the modified pptx back to file doc.Save(@"c:\annotatedSample.pptx");

PowerPoint Rendering and Conversions RasterEdge Document Imaging SDK supports converting PowerPoint document to various image and document types with customized options. You can convert PowerPoint Document to PNG, JPEG, BMP, and GIF image formats. You can also convert PowerPoint Document to other document types including TIFF, PDF and SVG. SVG is a vector image format that is supported by HTML5 standard and therefore can be viewed at most of the up to date web browsers. Convert PPTXDocument to Images You can convert PPTXDocument to raster images collection. This is a batch operation with customized options. Related APIs: void ConvertToImages(ImageType targetType, String directory, String fileName) These methods will automatically convert every page in PPTXDocument to an image file, with the page index append to fileName. Note that, the resolution is default to be 96 dpi for monitor displaying purpose. You can adjust resolution to enlarge or reduce the size of image file. You can also specify the zoomValue to cause the same effect. Convert PPTXPage to Image File To get full control over the rendering process, you can work with PPTXPage object. First get specific PPTXPage object from ppt document by BasePage GetPage(int index),and then you can render PPTXPage object to REImage or other common image formats with customized parameters. Related APIs: REImage CropImage(Rectangle sourceRegion, Size targetSize) REImage ConvertToImage() void ConvertToImage(ImageType toType,String filePath) void ConvertToImage(ImageType toType,int resolution, String filePath)

If you want to zoom in page with a large factor, say 8x and generate an image out of the whole page. This will cost not only a very high usage of memory resource but also a considerable amount of time to proceed. The common practice is to show part of page with a zoom in factor (usually fit to your screen) at a time. And the CropImage API is designed for this purpose.

Convert PPTXPage to Bitmap In .Net framework Bitmap is a frequently used class in image processing. RasterEdge provide you with APIs to directly convert PPTXPage to Bitmap objects which then can be drew on graphics of for example win form controls. These APIs returning a Bitmap object are faster than those returning a REImage object taking into account that additional operations are needed with REImage.

Bitmap GetBitmap() Bitmap GetBitmap(float zoomValue) Bitmap GetBitmap(Rectangle sourceRectangle, Size targetSize) Note that the resulting Bitmap cannot be too big to handle due to the restriction of system memory. Typically if a resulting Bitmap zoomed or not has a dimension product over 3000*3000, we recommend you deal with it in partitions. The API Bitmap GetBitmap(Rectangle sourceRectangle, Size targetSize) is a good choose. You can also draw the page directly onto a graphics using the following APIs Draw(Graphics g, PointF loaction) void Draw(Graphics g, PointF loaction, Size targetSize )

Convert PPTXDocument to PDF or TIFF File Sample code: public static void TestConvertPPTXToPDF(string sourceFilePath, string targetFilePath) {

// load powerpoint document PPTXDocument doc = new PPTXDocument(sourceFilePath); //convert pptx to pdf and save to target file path doc.ConvertToDocument(DocumentType.PDF, targetFilePath); ////convert pptx to tiff and save to target file path //doc.ConvertToDocument(DocumentType.TIFF, targetFilePath);

} If you need generate the tiff file with a greater resolution (or bigger size) you can use the following code to generate an x2 resolution tiff. doc.ConvertToDocument(DocumentType.TIFF, 2.0f, @"C:\x2.tif");

Convert PPTX To SVG SVG part of HTML5 standard, therefore it can viewed directly using most of the modern browsers without installing additional plugin or add-on on the end user’s computer. Related APIs: DOCXDocument.ConvertToVectorImages(ContextType targetType, String directory, String fileName,RelativeType type); DOCXPage.ConvertToVectorImage(ContextType targetType, String directory, String fileName,RelativeType type);

SVG file generated can be used in one of the two ways: 1. Svg file can be used as a stand-alone external resource of a web page. In this case the resources such as font and image files referenced by svg file are mapped by a relative path with respect to the svg file itself. Choose RelativeType.SVG as input parameter when you use svg file as an external resource. 2. The content of svg file may be extracted from it and embedded into html code in a web application. If this is the case the resources referenced is mapped through a relative path to the web project working directory. Choose RelativeType.ASP as input parameter in this situation. C# sample code string filePath = @"c\sample.pptx"; //directory to store the svg file and resources string svgfileDirectory = @"c\sample\ ";

// load word file to creat PPTXDocument object PPTXDocument doc = new PPTXDocument (filePath);

// you can convert the whole document to a list of svg files // each page of the document is renderd to a svg file with page index //appended //to the file name doc.ConvertToVectorImages(ContextType.SVG,svgfileDirectory, "SampleSVG", RelativeType.SVG);

// or you can convert specific page to svg file // Get the first page of document and convert it to svg file PPTXPage page = (PPTXPage)doc.GetPage(0); page.ConvertToVectorImage(ContextType.SVG,svgfileDirectory, "SampleSVG", RelativeType.SVG); // if you want to embed the svg content into html code in your web application // the relative path is to your web project working directory, change the //paramter like this doc.ConvertToVectorImages(ContextType.SVG,svgfileDirectory, "SampleSVG", RelativeType.ASP);

}

Create Barcode in PowerPoint RasterEdge Barcode processing dll offers comprehensive functions for developers to generate and design both 1d & 2d barcode images on power point file. Sample Code: // generate a code39 barcode Linear linearBarcode = new Linear(); linearBarcode.Type = RasterEdge.Imaging.Barcode.Creator.BarcodeType.CODE39; linearBarcode.Data = "123456789"; linearBarcode.Resolution = 96; linearBarcode.Rotate = Rotate.Rotate0;

// load ppt document, you can also load document like tiff, word, excel,pdf PPTXDocument doc = new PPTXDocument(@"c:\sample.pptx"); // get the first page BasePage page = doc.GetPage(0);

// generate reimage of this barcode REImage barcodeImage = linearBarcode.ToImage(); //add barcode image to the first page

page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f)); // save changes to the powerpoint doc.Save(@"c:\sample.pptx");

See Also Barcode Create Read Barcode from PowerPoint You can read barcode information from powerpoint document. Sample code: public static void ReadBarcodeFromPPT(string filename, int pageIndex) { //generate powerpoint document PPTXDocument doc = new PPTXDocument(filename); //get the page you want to read barcode from BasePage page = doc.GetPage(pageIndex); //set reader setting ReaderSettings setting = new ReaderSettings(); setting.AddTypesToRead(RasterEdge.Imaging.Barcode.Scanner.BarcodeType.Code39); // read out barcode information Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page); //output barcode information foreach (Barcode barcode in barcodes) { Console.WriteLine(barcode.DataString); } }

See also Barcode read How to’s

How to: Create Thumbnail of PowerPoint Document You can convert powerpoint document to image files with a zoom factor suitable for thumbnail image. // load Power Point document PPTXDocument doc = new PPTXDocument(@"c:\sample.pptx"); // compute zoom out factor // get the first page as sample page PPTXPage page = (PPTXPage)doc.GetPage(0);

// the original height and width are measured at 96 dpi float originalWidth = page.GetWidth() * 96; // assume you want a thumbnail size of 100 pixel in width and compute the zoomfactor float zoomFactor = 100f / originalWidth; string directory = @"c:\Thumbnail"; // construct thumbnail image under the directory with files name of the pattern thumail01.png, thumnail02.png doc.ConvertToImages(ImageType.PNG, zoomFactor, directory, "thumbnail");

DICOM DICOM Overview DICOM (Digital imaging and Communications in Medicine) is an international standard (ISO 12052) respective to medical imaging and its related workflow & data management. It defines the file format that can be used for data exchange in clinical circumstances demand. Among tens of thousands of medical imaging devices, DICOM is one of the most widely used medical information standards. In 1993, ACR-NEMA Joint Commission released the third version of DICOM standard (DICOM 3.0) which is regarded as the international standard in the field of medical imaging informatics. It covers almost all information exchange protocols for medical digital image, like image acquisition, archiving, communication, display and search. The implementation of DICOM standard greatly simplifies the exchange of medical image information and promotes the research and development of teleradiology system and image management and communication system (PACS). In addition, openness and connectivity of DICOM makes it possible to be integrated with other medical application systems (HIS, RIS). Programming with DICOM There are two important classes in DICOM programming, DCMDocument and DCMPage. Every Dicom file is represented as a DCMDocument object, and the images and related information is represented as DCMPage object. Load DICOM File You can load a file, stream or byte[] containing a Dicom document as a DCMDocument object. DCMDocument doc = new DCMDocument(@"c:\a.dcm");

Convert DICOM to Image files You can convert Dicom document with one or multiple pages to images collection and save it to file. Sample code: //invoke this method only once at the beginning of your code to register all assemblies you referenced to your project WorkRegistry.Reset();

//load a DCMDocument DCMDocument doc = new DCMDocument(@"c:\a.dcm"); // convert dicom document to images in png format and save it under specified directory and name doc.ConvertToImages(RasterEdge.Imaging.Basic.ImageType.PNG, @"c:\dicom", "dicom");

Or You can get a specific page to convert sample code:

//load a DCMDocument DCMDocument doc = new DCMDocument(@"c:\a.dcm"); // get first page DCMPage page = (DCMPage)doc.GetPage(0); // convert the first page page.ConvertToImage(RasterEdge.Imaging.Basic.ImageType.PNG, @"c:\dicom1.png");

You can adjust window center and window width values for Dicom image. It is similar to the notions of contrast and brittleness in common image processing. //load a DCMDocument DCMDocument doc = new DCMDocument(@"c:\a.dcm"); // get first page DCMPage page = (DCMPage)doc.GetPage(0); //you can get recommended range for value of window width and window center int[] centerRange = page.GetRecommendedWindowCenter(); int[] widthRange = page.GetRecommendedWindowWidth(); // For illustration purpose we choose random value in the range Random randomGenerater = new Random(); int randomCenter = randomGenerater.Next(centerRange[0], centerRange[1]); int randomWidth = randomGenerater.Next(widthRange[0], widthRange[1]); // get REImage with specified values of width and center REImage img = page.GetModifiedREImage(randomWidth, randomCenter); //save the image in file img.Save(RasterEdge.Imaging.Basic.ImageType.PNG, @"c:\dicom.png");

Convert DICOM to Bitmap In .Net framework Bitmap is a frequently used class in image processing. If you don’t need to adjust the rendering parameters like window width and center, the method is returned with a better performance.

//load a DCMDocument DCMDocument doc = new DCMDocument(@"c:\a.dcm"); // get first page DCMPage page = (DCMPage)doc.GetPage(0); // convert the first page to bitmap Bitmap img = page.GetBitmap(); //// zoom in/out with a factor //Bitmap img1 = page.GetBitmap(2.0f); //// source part of the orignal page and rendered to a target size //int orignalWidth = (int)page.GetWidth(); //int orignalHeight = (int)page.GetHeight(); //Bitmap img2 = page.GetBitmap(new Rectangle(0, 0, orignalWidth / 2, orignalHeight), new Size(orignalWidth, orignalHeight));

Convert Dicom to Tiff or PDF file You can convert Dicom to tiff or pdf file. You can also add annotations to dicom file and saved them as pdf or tiff file. See annotation demo at http://www.rasteredge.com/dotnetimaging/web-viewer-demo/ Sample Code:

//invoke this method only once at the beginning of your code register all assemblies you referenced by your project WorkRegistry.Reset(); //load a DCMDocument DCMDocument doc = new DCMDocument(@"c:\a.dcm"); //convert dicom to pdf doc.ConvertToDocument(DocumentType.PDF, @"c:\sample.pdf"); ////convert dicom to tiff //doc.ConvertToDocument(DocumentType.PDF, @"c:\sample.tiff");

If you need generate the tiff file with a greater resolution (or bigger size) you can use the following code to generate an x2 resolution tiff. doc.ConvertToDocument(DocumentType.TIFF, 2.0f, @"C:\x2.tif");

JBIG2 JBIG2 Codec Overview RasterEdge Image JBIG2 codec can be used to decode and encode JBIG2 images using the Microsoft .NET Framework. JBIG2 compression is an open standard and can compress bitonal images 2-5 times more than the same image compressed with the industry standard TIFF CCIT Group4 compression. This codec is available as a plug-in that integrates with RasterEdge Image seamlessly. Feature List Able to decode any page from a 1-bit JBIG2 image Encode a single or multi-page document as JBIG2 image(s) or image only PDF document Support lossless and lossy compressions Support encoding and decoding from any stream Read a specified region from an existing JBIG2 image stream Generate image only PDF document with embedded JBIG2 image(s) Integrated with RasterEdge PDFEncoder to encode PDF images with other compression formats. How to Decode an JBIG2 Image Sample Code: // invoke this method only once in the beginning of your code register all assemblies you referenced to your project WorkRegistry.Reset(); //decode image in jbig2 format REImage img = new REImage(@"c:\sample.jb2", ImageType.JBIG2); // save the image in png format img.Save(ImageType.PNG, @"c:\sampleModified.png");

JPEG 2000 JPEG 2000 Codec Overview RasterEdge JPEG 2000 codec can be used to decode and encode JPEG 2000 images using the Microsoft .NET Framework. It uses wavelet compression technology to compress photo graphic images further than any other available compression schemes. This codec is available as a plugin and integrates with RasterEdge seamlessly. Feature List Able to decompress JPEG2000 images stored in any compatible jp2, j2k or code stream Support decoding JPEG2000 directly to 8-bit grayscale, 24-bit RGB, 16-bit grayscale, and 48-bit RGB Lossless compression How to Decode JPEG 2000 Image Sample Code: // invoke this method only once in the beginning of your code register all assemblies you referenced to your project WorkRegistry.Reset(); //decode image in jpeg2000 format REImage img = new REImage(@"c:\sample.jpx", ImageType.JPEG2000); // save the image in png format img.Save(ImageType.PNG, @"c:\sampleModified.png");

RasterEdge OCR RasterEdge OCR SDK provides you with the functions to recognize characters out of images and documents types that are supported by RasterEdge Document imaging SDK. OCRHandle This class is the utility class. Public methods Import(override +5) Reset SetTrainResourcePath

Translate(override +3)

Create an OCRDocument / OCRPage instance by input image. Reset recognizing setting and output setting to default values. Change the path of those training resource files, the recourse path should be the path of folder include those trained data files (with file extension ‘.traineddata’). Default: All trained data files should be put in a folder called "Source", and this “Source” folder MUST BE put in the same dictionary as the assemblies. Recognize all characters in images, and save the results into PDF/SVG/TXT file/stream.

Public Properties Settings

Sets/gets the settings applying in the recognizing process.

OCRRecSetting You can set the OCR recoginition setting of the OCR entities in any level, namely OCRHandler, OCRDocument, OCRPage and OCRZone. The setting in the lower level entity overrides that in the higher one. Below is a table to describe the attributes in OCRRecSetting Class Enabled LanguagesEnabled Tradeoff

DefaultFilter AdditionalFilters DefaultUnkownChar

Specifies if this setting is valid or not. Default is false for all OCR entities except for OCRHandler Specifies the languages used in the recognition. The value could be Default/Fast/Accurate. Fast: spends the least time to scan the source image. Accurate: gets the most accurate result. Default: balances between time consuming and accurate. These properties would define a set of valid characters. The result characters MUST BE in this set. If a character is not a valid character, it would be replaced by this

DefaultUnkownChar. Default: [space] class OCRPage OCRPage may contain a collection of OCRZone, the zones will not recognize unless the property RecognizeZoneOnly is true. You can get an instance by invoking OCRHanle.Import or OCRDocument.GetPage. Public Methods CreateZone GetZoneText Recognize SaveTo(override +2)

Create a zone in the page. Get recognition result of the zone by its index. Recognize the page. Returns 0 if recognition is success. Convert recognize results to PDF/SVG/TXT format and save into a file/stream. You MUST invoke Recognize before calling this method.

Public Properties RecSettings

OutputSettings Width Height RecognizeZoneOnly Zones

Sets/gets settings in page recognizing process. If this setting is disabled (property Enabled is false), it would use the settings defined in OCRHanle.setting during the page recognizing process. Sets/gets the settings of the output (Not Implemented Yet). Page width. Page height. If this property is true, only the zones in the page will be recognized during the page recognizing process. Otherwise, the whole page will be processed. Returns the zones in the page.

OCRZone will use OCRPage.RecSetting in recognize process if RecSetting.Enabled of themselves is false.

Multi-Language support RasterEdge OCR module support recognizing different languages, the table below illustrates the supported language types, the corresponding abbreviations (used in API as string parameter) and source (trained data) file name Supported Languages English Spanish French German

Abbreviation eng spa fra deu

traineddata eng.traineddata spa.traineddata fra.traineddata deu.traineddata

Italian Russian Portuguese Dutch Arabic Korean

ita rus por nld ara kor

ita.traineddata rus.traineddata por.traineddata nld.traineddata ara.traineddata kor.traineddata

Source Preparation

OCR Source files for different languages can be found in the download package under RasterEdge.DocImageSDK\Source

Before you use OCR functionality, you may specify the source directory using the following code (For APS.NET Project this is a must) public static int SetTrainResourcePath(string strResource);

By default, if your application is a desktop application the source directory is set to the directory of application. That is [applicationFolder]\Source\ For example if you want to recognize English characters, make sure the file eng.traineddata is retrivable in the following path [applicationFolder]\Source\ eng.traineddata The following pictures as an illustration

For ASP.NET project, you should set the source directory using the following code public static int SetTrainResourcePath(string strResource);

PDF and TIFF files OCR You can recognize characters from a pdf or tiff files. Sample code: //Set the training data path please put eng.traineddata (for english) //under the path specified OCRHandler.SetTrainResourcePath(@"c:\source"); // set supported language, you can also set this attribute in OCRPage or OCRZone OCRHandler.Settings.LanguagesEnabled.Add(Language.Fra); //load pdf or tiff document PDFDocument doc = new PDFDocument(@"C:\sample.pdf"); //TIFFDocument doc = new TIFFDocument(@"c:\sample.tif"); // load the first page to Recongnize PDFPage page = (PDFPage)doc.GetPage(0); //TIFFPage page = (TIFFPage)doc.GetPage(0); //rasterize the page with a resolution multipi Bitmap bmp = page.GetBitmap(1.5f); // import the page to recoginze OCRPage oPage = OCRHandler.Import(bmp); oPage.Recognize(); // save ocr result as other documet format(txt pdf, svg). oPage.SaveTo(MIMEType.TXT,@"c:\sample.txt"); //or you can output the text directly Console.WriteLine(oPage.GetText());

Image OCR You can recognize characters from common image formats such as png, jpeg, bmp, gif and other image formats supported by RasterEdge Imaging SDK Sample code:

//register all referenced RasterEdg dlls WorkRegistry.Reset();

//Set the training data path, please put eng.traineddata (for english) //under the directory you specified. OCRHandler.SetTrainResourcePath(@"c:\source");

REImage img = new REImage(@"C:\page.jpeg"); //resize image to improve accuracy if the image is clear enough skip this img = img.Resize(new Size((int)img.Width * 2, (int)img.Height * 2)); //recognize

characters from this image, default language is english

OCRPage page = OCRHandler.Import(img); page.Recognize(); Console.WriteLine(page.GetText());

Zone Scanning If you only want to scan part of the whole page/image, you can use zone scanning Sample code:

//Set the training data path please put eng.traineddata (for english) //under the path specified OCRHandler.SetTrainResourcePath(@"c:\source");

//load pdf or tiff document PDFDocument doc = new PDFDocument(@"C:\sample.pdf"); //get the third page to scan PDFPage page = (PDFPage)doc.GetPage(2); Bitmap bmp = page.GetBitmap(1.5f); OCRPage ocrPage = OCRHandler.Import(bmp); //create two zone to scan OCRZone zone1 = ocrPage.CreateZone(new Rectangle(0, 0, 800, 800));

OCRZone zone2 = ocrPage.CreateZone(new Rectangle(800, 800, 800, 800)); // enable the page scan settings ocrPage.RecSettings.Enabled = true; // accuracy over time cost ocrPage.RecSettings.Tradeoff = Tradeoff.Accurate; //add support to english

ocrPage.RecSettings.LanguagesEnabled.Add(Language.Eng); //enable zone scanning ocrPage.RecognizeZoneOnly = true;

if (ocrPage.Recognize() == 0) { //output the result of two zones Console.WriteLine(ocrPage.Zones[0].GetText()); Console.WriteLine(ocrPage.Zones[1].GetText()); ocrPage.Zones[0].SaveTo(MIMEType.PDF, @"zone1.pdf"); ocrPage.Zones[1].SaveTo(MIMEType.PDF, @"zone2.pdf");

}

Exception: Resource Dictionary Preparation failed If this Exception occurred, please do the following:

OCR Source files for different languages can be found in the download package under RasterEdge.DocImageSDK\Source

Before you use OCR functionality, you must specify the source directory using the this API public static int SetTrainResourcePath(string strResource); Sample Code: string inputPath = @"D:\TestDocument\OCR\OCR.bmp"; REImage img = new REImage(inputPath); //resize image to improve accuracy img = img.Resize(new Size((int)img.Width * 2, (int)img.Height * 2)); //Set the training data path please put eng.traineddata (for english) //under the path specified OCRHandler.SetTrainResourcePath(@"c:\source"); //recognize English characters from this image OCRPage page = OCRHandler.Import(img); page.Recognize(); Console.WriteLine(page.GetText());

In this example make sure the file xxx.traineddata (depending on the language you want to support) is retrivable in the path D:\bin\Source\

RasterEdge RasterImage RasterImage Overview RasterEdge Imaging SDK provides you functions to operate on over 100 raster image formats. You can load, convert, process and save different image formats

Requirements The APIs related to RasterImage are located under: Assemblies: RasterEdge.Imaging.Raster.dll NameSpace: RasterEdge.Imaging.Raster

About RasterImage Programming Classes RasterImage Object: This class will provide more Image Processing method. ConvertHandler: provide serval static methods for image conversion. (Support over 100 image format). ImageProcess Provide static methods for image process such as rotate, crop, resize, flip, trim, append and monochrome Convert Image C# sample code // The code convert emf image file to png file. ConvertHandler.Convert(@"C:\input.emf", @"C:\output.png"); // The code convert emf image file to png data stream. Stream outputStream = ConvertHandler.Convert(@"C:\input.emf", ".png"); Related APIs: public static int Convert(byte[] inputBytes, string outputFilePath); public static int Convert(Stream inputStream, string outputFilePath); public static int Convert(string inputFilePath, string outputFilePath);

public static Bitmap ConvertEMFtoBitmap(MemoryStream emfStream); public static byte[] ConvertToBytes(byte[] inputBytes, string ext); public static byte[] ConvertToBytes(Stream inputStream, string ext); public static byte[] ConvertToBytes(string inputFilePath, string ext); public static Stream ConvertToStream(byte[] inputBytes, string ext); public static Stream ConvertToStream(Stream inputStream, string ext); public static Stream ConvertToStream(string inputFilePath, string ext); Load Image C# //Construct a RasterImage RasterImage raster = new RasterImage(@”C:\input.tif”); Related APIs: public RasterImage(string imagePath) public RasterImage(byte[] imageDataBytes) public RasterImage(Stream imageStream) public RasterImage(Bitmap bmp) //ApplyColorSpace,destColorSpace = REColorSpace.GrayColorspace RasterImage raster = new RasterImage(@”C:\input.png”); raster.ApplyColorSpace(REColorSpaceType.GRAYColorspace); raster.Save(@”C:\output.png”);

Save Image Related APIs: //Extract pages from tiff and save to pdf file. RasterImage raster = new RasterImage(@"C:\input.tif"); int[] pageIndexs = new int[]{1,4}; Stream stream = raster.Save(REImageFormat.PDF, pageIndexs); FileStream fs = new FileStream(@"F:\output.pdf", FileMode.OpenOrCreate); byte[] data = StreamToBytes(stream); fs.Write(data, 0, data.Length); fs.Close(); //extract one page from tiff and save as an png image RasterImage raster = new RasterImage(@”C:\input.tif”); raster.Save(@”C:\output.png” 2);

public Stream Save(REImageFormat format)

public Stream Save(REImageFormat format, int pageIdx) public Stream Save(REImageFormat format, int[] pageIdxs) public void Save(string filePath) public void Save(string filePath,int[] pageIdxs) Image Process C# //rotate the image file , degree = 50 RasterImage raster = new RasterImage(@”C:\input.png”); ImageProcess.RotateImages(raster, 50); raster.Save(@”C:\output.png”); //resize image , destWidth = 500, destHeight = 500,interpolateMethod = //REInterpolateMethod.NearestNeighborInterpolatePixel RasterImage raster = new RasterImage(@”C:\input.png”); ImageProcess.ReSizeImages(raster, 500, 500, REInterpolateMethod.NearestNeighborInterpolatePixel); raster.Save(@”C:\output.png”); //AdaptiveResizeImages,destWidth = 500,destHeight = 500 //it’s a fast interpolative resize method using mesh interpolation. //Best performance when //|orgWidth -destWidth|< 50pixel && |orgHeight - destHeight|< 50pixle RasterImage raster = new RasterImage(@”C:\input.png”); ImageProcess.AdaptiveResizeImages(raster, 500, 500); raster.Save(@”C:\output.png”); //Crop Image,rect = new Rectangle(10,10,200,200),pageIndex = 0 RasterImage raster = new RasterImage(@”C:\input.png”); ImageProcess.CropImage(raster, new Rectangle(10, 10, 200, 200), 0); raster.Save(@”C:\output.png”); //FlipImages RasterImage raster = new RasterImage(@”C:\input.png”); ImageProcess.FlipImages(raster); raster.Save(@”C:\output.png”); //TrimImages RasterImage raster = new RasterImage(@”C:\input.png”); ImageProcess.TrimImages(raster); raster.Save(@”C:\output.png”); //MonochromeImages,convert input image to 1bpp image RasterImage raster = new RasterImage(@”C:\input.png”); ImageProcess.MonochromeImages(raster); raster.Save(@”C:\output.png”);

//AppendImages,direct = 0,append direction is Horizontal direction is Vertical RasterImage raster = new RasterImage(@”C:\input.png”); ImageProcess.AppendImages(raster, 1); raster.Save(@”C:\output.png”);

direct = 1,append

Related APIs: public static void RotateImage(RasterImage image, double degree, int pageIndex) public static void RotateImages(RasterImage image, double degree) public static void ReSizeImage(RasterImage imge, int width, int height, REInterpolateMethod polateMethod, int pageIndex) public static void ReSizeImages(RasterImage imge, int width, int height, REInterpolateMethod polateMethod) public static void AdaptiveResizeImageImage(RasterImage imge, int width, int height, int pageIndex) public static void AdaptiveResizeImages(RasterImage imge, int width, int height) public static void CropImage(RasterImage image, Rectangle rect, int pageindex) public static void FlipImage(RasterImage image, int pageIndex) public static void FlipImages(RasterImage image) public static void TrimImage(RasterImage image, int pageIndex) public static void TrimImages(RasterImage image) public static void MonochromeImage(RasterImage image, int pageIndex) public static void MonochromeImages(RasterImage image) public static void AppendImages(RasterImage image, int direction)

Programming with Images Overview RasetEdge Image toolkit is a powerful imaging solution for your desktop or web server side application. With a collection of controls for ASP.NET and Windows, you can integrate a light and powerful solution into your document imaging and image processing project. Licensing is straightforward and runtime royalty free on desktop. All RasterEdge imaging related assemblies are available as managed components and are natively built as .NET2.0 assemblies. Therefore, it is compatible for .NET 2.0 and higher platforms. And there are several add-on modules to meet your specific requirements. RasterEdge Imaging assembly(Core SDK)

PDF SDK

basic Including Codecs for basics image formats (Bitmap, GIF, PNG and JPEG) and image processing.

Fast and powerful Codec, imaging, annotating and editing for document of PDF format.

TIFF SDK Barcode Reader SDK Barcode Generator SDK DICOM Codec SDK JBIG2 Codec SDK JPEG2000 Codec SDK

Fast and powerful Codec, imaging, annotating and editing for document of TIFF format. Read barcode from an image (or document page) obtained. Write barcode to specific image (or document page). Codecs for DICOM image format. Codecs for JBIG2 image format. Codecs for JPEG2000 image format.

Image Concept REImage, the Core Programming Class for Images In RasterEdge Imaging SDK we represent a raster image which is described in sample or pixel as REImage. It is similar to the concept of Bitmap in .Net programming. Before discussing REImage Class in details, we would like to provide you with some optional knowledge that may help you understand the theory behind raster images. You can skip this section and learn REImage in programming. Image Data Image data contains color information for every pixel in image. REImage provides a property of ImageData from which you can use unsafe code to change/set image data directly. Image Compressions When you add images to certain file format, you may select different image compression schemes to reduce file size. Why Compression In a raw state, images can occupy a rather large amount of memory both in RAM and in storage. Image compression reduces the storage space required by an image and the bandwidth needed when streaming that image across a network. Types of Compression Compression Types There are two types of compression algorithms, namely lossless and lossy. Lossless compression grants the integrity of data which means the decompressed image is the same as the original, with no data lose. For lossy compression, some data in image will be lost during compression, so the resulting image is not identical to original one.

Compression Methods The following compression methods are available in RasterEdge Image.JPEG Compression. Deflate/PNG Compression LZW Compression CCIT Group 4 / Group 3 Compression RLE(Run Length Encoding) Compression JPEG2000 Compression JBIG2 Compression RasterEdge Imaging toolkit provides a number of codecs to encode and decode image in various compression modes. Different document types may support different compression schemes. Image Codecs An Image codec is a program that can encode and decode an image in specific format. REImage can read and write most common image formats. Images are read and written with BaseDecoders and BaseEncoders for specific type, for example PNGEncoder and PNGDecoder for encoding and decoding PNG images. Plug-ins for JPEG2000 and some other codecs are available separately. Supported Formats REImage natively supports image (document) formats listed in the table below. This table also shows the location of these codecs in particular assembly or plug-in. ImageType

ImageDecoder

ImageEncoder

Assembly

Jpeg

JPEGDecoder

JPEGEncoder

RasterEdge.Imaging.Basic.codec

Png

PNGDecoder

PNGEncoder

RasterEdge.Imaging.Basic.codec

Bmp

BMPDecoder

BMPEncoder

RasterEdge.Imaging.Basic.codec

Gif

GifDecoder

GifEncoder

RasterEdge.Imaging.Basic.codec

JBIG2

JBIG2Decoder

JBIG2Encoder

RasterEdge.Imaging.Basic.codec

Jpeg2000

Jpeg2000Decoder

JpegEncoder

RasterEdge.Imaging.JPEG2000

Dicom

DicomDecoder

DicomEncoder

RasterEdge.Imaging.DICOM

REImage the Core Image Class in RasterEdge Imaging SDK Introduction In RasterEdge Imaging SDK we represent raster image which is described in sample or pixel as REImage. It is similar to the concept of Bitmap in.Net programming and you can get bitmap object from a REImage object. Rasteredge Imaging sdk provides straightforward APIs to load, modify, convert, and save REImage object which encapsulate the concept of encoder or decoder. Below are example codes for loading and saving REImage from/to various image formats. Please note that you can make full use of REImage class when combined with functionalities from Document Imaging SDK. One typical example is to convert document page to REImage. Try our online demo at http://www.rasteredge.com/demo/online-document-viewer/ for more detailed information. Note: RasterEdge Document Imaging SDK represents PDF, TIFF, Dicom, Office Word, Excel, and PowerPoint as document object. You can get REImage from BaseDocument and BasePage. See Document Imaging for more Information. Requirements The APIs related to REImage are located under: Assemblies: RasterEdge.Imaging.Basic.dll NameSpace: RasterEdge.Imaging.Basic;

How to Create REImage

Create REImage from Image File, Stream

Byte Array

Create REImage from image file, stream & byte array that contain the image. Sample APIs in REImage Class are listed below. public REImage(String fileName, ImageType sourceType) public REImage(Stream stream, ImageType sourceType) public REImage(byte[] fileData,ImageType sourceType)

The parameter type ImageType can be chosen for any supported image format mentioned in previous section. You can also let your program choose the ImageType automatically using similar API as follows: public REImage(String filename) Demo code to construct an image source: List tmpImgList = new List(); DirectoryInfo d = new DirectoryInfo(filepath); foreach (FileInfo file in d.GetFiles()) { // construct image source from jpeg and png images if (file.Extension.ToLower().Contains("jpeg") || file.Extension.ToLower().Contains("png")) { REImage img = new REImage(file.FullName); tmpImgList.Add(img); } } REImage[] ImageSource = tmpImgList.ToArray();

Create Image from Bitmap public REImage (Bitmap image) Imaging Conversion You can apply image conversion among image types like JPEG, GIF and PNG using the following APIs in REImage Class. public static void ConvertImage( ImageType targetType, String sourcePath, String targetPath) static void ConvertImage(ImageType targetType,Stream srcStream,Stream targetStream)

Annotate on REImage You can draw different kinds of predefined annotations onto REImages, and save them to file or stream. Below is the sample code: public static void TestREImageAnnotation()

{

// invoke this method only once at the start of your project to register all assemblies you referenced to your project WorkRegistry.Reset(); //Load an PNG file to REImage object REImage img = new REImage(@"c:\samplePNG.png", ImageType.PNG); // create a line annotation starting at point (0.0) and end with point(100,100), note that only the relative position of the start and end point is used. LineAnnotation anno = AnnotationGenerator.CreateLineAnnotation(new LinePoint(0, 0), new LinePoint(100, 100));

// set line stroke color and style anno.LinePen = PenGenerator.CreateLinePen(new REColor(255, 0, 0, 255), 5.0F); anno.LinePen.StartCap = new LineCap(); anno.LinePen.StartCap.Cap_Width = 2.0f; anno.LinePen.StartCap.CapStyle = LineCapStyle.Diamond;

anno.SetTransparency(0.4f); // draw line annotation on the REImage, The position is measured at default 96 resolution with respect to the image.And therefore it is subject to the change of the size of the tiff image img.DrawAnnotation(new Point(100, 100), anno); img.Save(ImageType.PNG, @"c:\samplePNGAnnotated.png"); }

See also Annotation Save REImage You can save REImage to file, stream and byte array with specified image type. Useful APIs in REImage Class: void Save(ImageType targetType, String fileName) void Save(ImageType targetType, Stream stream byte[] Save(ImageType targetType) Image Convert

RasterEdge Imaging toolkit provides reliable encoding and decoding functions for raster images of different formats. With APIs provided, you can convert between different image formats with ease. You can also convert image source into PDF or TIFF Document using functions provided by the Document SDK. How to Convert Between Raster Images There are static APIs for you to implement image conversion. For example, you can convert a JPEG image file to PNG format using the following code. public static void TestREImageConversion() { //you need to invoke this method only once at the beginning of your code register all assemblies you referenced to your project WorkRegistry.Reset(); // Convert image in PNG format to image in JPEG(JPG) format and save it to target filePath REImage.ConvertImage(ImageType.JPEG, @"c:\samplePNGAnnotated.png", @"c:\samplePNGAnnotated1.jpg"); }

How to Convert Raster Images to PDF or TIFF You can convert REImage source to PDF or TIFF Document using the following code: public static void TestImageToPDF() { //you need to invoke this method only once at the beginning of your code register all assemblies you referenced to your project WorkRegistry.Reset(); //Construct image source REImage img1 = new REImage(@"c:\samplePNG.png", ImageType.PNG); REImage img2 = new REImage( @"c:\samplePNGAnnotated1.jpg", ImageType.JPEG); REImage[] imageSource = new REImage[2]; imageSource[0] = img1; imageSource[1] = img2; // create a pdf document using image source, one image per page PDFDocument doc = new PDFDocument(imageSource); doc.Save(@"c:\sample.pdf"); } public static void TestImageToTIFF() { //invoke this method only once at the beginning of your code register all assemblies you referenced to your project WorkRegistry.Reset();

//Construct image source REImage img1 = new REImage(@"c:\samplePNG.png", ImageType.PNG); REImage img2 = new REImage(@"c:\samplePNGAnnotated1.jpg", ImageType.JPEG); REImage[] imageSource = new REImage[2]; imageSource[0] = img1; imageSource[1] = img2; // create a TIFF document using image source, one image per page TIFFDocument doc = new TIFFDocument(imageSource); doc.Save(@"c:\sample.TIFF"); }

See Also Document Imaging.

ImageProcessing RasterEdge Imaging provides you with the ability to perform operations on existing REImage object to create a new REImage object. These functions are located under RasterEdge.Imaging.Processing Assmebly. Generally speaking, there are three kinds of image processing operations available for you. Category

Illustration

Channels Processing Effects Processing Filters Transforms

Operate on images with multiple components, like color images Perform visual effects on images like mosaic or beveling Perform mathematical filtering like high or low pass filtering Perform coordinate transforms or depth transforms like rotate or ripple

APIs to perform these operations are in the ImageProcessing Class located in RasterEdge.Imaging.Processing assembly.

Annotations Introduction to Annotations RasterEdge Annotation is a managed .NET Assembly that can perform annotation capabilities to markup, draw, and visualize objects on an image or document. Annotation objects include primitive shapes (lines, rectangle, polygon and ellipse), text, callout, rubber stamp, hotspot, Free HandEmbedded images and hot spots. You can set properties of these annotations, and add these annotations onto REImage and Document. With Windows Forms viewer control or ASP.NET AJAX driven Webviewer, these annotations can be independently resized, moved, rotated, and placed on different layers. Annotation can be imported or exported from/to an xml file. Try our online Demo at http://www.rasteredge.com/demo/online-document-viewer/ for more detailed information. Features of Annotation Assembly Draw an arbitrary number of annotation objects to an image or document Object Oriented Design for every annotation object Annotation objects can be moved, resized, and rotated independently from image or document GDI+ graphics allows any object to be rendered at variable transparency Save or load annotations as a separate XML file Annotations can be rotated along with image in 90 degree increments Individual points from annotations supporting points (Freehand, Polygon, etc.) can be repositioned Able to change shape of annotation object Annotations can be burned onto image with a single method Render annotation object to REImage for further operation Various properties can be set when creating an annotation object Following is a list of supported annotations by RasterEdge Annotation assembly. Rectangle Ellipse Line Freehand Freehand Lines Text Rectangular HotSpot Freehand HotSpot

Embedded Image Referenced Image Polygon Lines Rubber Stamp Callout Annotation Requirements Assemblies you need: RasterEdge.Imaging.Annotation.dll RasterEdge.Imaging.Basic.dll Namespace: using RasterEdge.Imaging.Annotation; using RasterEdge.Imaging.Basic;

Generate an AnnotationObject You can generate an Annotation object programmatically without using a graphics interface. When generating an annotation, a number of properties can be set. Following is an example to generate a hotspot annotation object. Note: In RasterEdge Imaging, Annotation is represented as an Annotation object derived from the supper class AnnotaionBasic. Since some APIs are inherited from this super class, a type conversion may be needed. First, add reference to RasterEdge.Imaging.Annotation. Example code: usingRasterEdge.Imaging.Annotation How to Generate an Annotation Object Programmatically C# // set annotation size // set xand y coordinate of the right top vertex of this annotation rectangle

// the actual shape of rubberStamp is contained in this rectangle. float x = 120.0f; float y = 120.0f; float width = 300.0f; float height = 100.0f; string text = "this is RubberStamp annotation"; Font font = new Font("Arial", 12.0F, FontStyle.Italic); AnnotationBrush fontBrush = new AnnotationBrush(); fontBrush.FillType = FillType.Solid; fontBrush.Solid_Color = REColor.FromArgb(System.Drawing.Color.Blue.ToArgb()); RubberStampAnnotation anno = AnnotationGenerator.CreateRubberStampAnnotation(x, y, width, height, text, font, fontBrush); anno.OutLine = new LinePen(); anno.OutLine.Brush = new AnnotationBrush(); anno.OutLine.Brush.FillType = FillType.Solid; anno.OutLine.Brush.Solid_Color = new REColor(255, 10, 100, 100); anno.OutLine.Width = 2.0f; anno.Fill = new AnnotationBrush(); anno.Fill.FillType = FillType.Solid; anno.Fill.Solid_Color = new REColor(255, 20, 20, 20); anno.CornerRadius = 1000f; //set the overall transparency, this value has an overall impact on all //colors related to this annotation. Note the default value is 1 which // is complete transparency anno.SetTransparency(0.4f);

Burn Annotation to Document or Image Once you generate an Annotation object, you can add and burn it onto documents like PDF, TIFF and Word, then save it in native file format. You can also burn annotation on to documents using REImage objects. How to Burn Annotation Object to Document (PDF, TIFF, WORD, EXECEL, PPT) Example Code: public static void TestPDFAddAnnotation() { //use code in previous section to generate a rubber starmp annotaion RubberStampAnnotation anno = TestAnnotation.addRubberStampAnnotation(); //load an PDF Document PDFDocument doc = new PDFDocument(@"c:\REImage.pdf"); // add this annotation in the first page doc.GetPage(0).AddAnnotation(new PointF(100f, 100f), anno);

// save this annotated pdf to file doc.Save(@"c:\annotated.pdf"); } public static void TestWordAnnotation() { //use code in previous section to generate a rubber starmp annotaion RubberStampAnnotation anno = TestAnnotation.addRubberStampAnnotation(); //load an Word Document DOCXDocument doc = new DOCXDocument(@"c:\TestWord.docx"); Console.WriteLine(doc.GetPageCount()); // add this annotation in the first page doc.GetPage(0).AddAnnotation(new PointF(100f, 100f), anno); // save this annotated word to file doc.Save(@"c:\annotated.docx");

} public static void TestTIFFAnnotation() { //use code in previous section to generate a rubber starmp annotaion RubberStampAnnotation anno = TestAnnotation.addRubberStampAnnotation(); //load a tiff Document TIFFDocument doc = new TIFFDocument(@"c:\sampleTiff.tiff"); Console.WriteLine(doc.GetPageCount()); // add this annotation in the first page of the tiff document doc.GetPage(0).AddAnnotation(new PointF(100f, 100f), anno); // save this annotated tiff to file doc.Save(@"c:\annotated.Tiff"); }

See Also PDF Annotation See Also TIFF Annotation See Also WORD Annotation

How to Burn Annotations on Imgaes Once you get a REImage object and an annotation object, you can draw annotations onto it and save it to different image types. Example code:

public static void TestREImageAnnotation() { // invoke this method only once in the beginning of your code register all assemblies you referenced to your project WorkRegistry.Reset(); //Load an PNG file to REImage object REImage img = new REImage(@"c:\samplePNG.png", ImageType.PNG); // create a line annotation starting at point (0.0) and end with point(100,100), note that only the relative position of the start and end point is used. LineAnnotation anno = AnnotationGenerator.CreateLineAnnotation(new LinePoint(0, 0), new LinePoint(100, 100));

// set line stroke color and style anno.LinePen = PenGenerator.CreateLinePen(new REColor(255, 0, 0, 255), 5.0F); anno.LinePen.StartCap = new LineCap(); anno.LinePen.StartCap.Cap_Width = 2.0f; anno.LinePen.StartCap.CapStyle = LineCapStyle.Diamond;

anno.SetTransparency(0.4f); // draw line annotation on the REImage, The position is measured at default 96 resolution with respect to the image.And therefore it is subject to the change of the size of the tiff image img.DrawAnnotation(new Point(100, 100), anno); img.Save(ImageType.PNG, @"c:\samplePNGAnnotated.png");

}

Annotations on ASP.NET DocumentViewer or Windows Form DocumentViewer Using our ASP.NET or Windows Form Document Viewer, you can annotate on a document with graphics interface. RasterEdge.Imaging.WebViewer assembly contains web controls that you can embed in your ASP.NET project by copying a couple of lines of JavaScript. Try our online demo at http://www.rasteredge.com/demo/online-document-viewer/ for more detailed information. For WinForm project, there are controls located in RasterEdge.Imaging.WinControl assembly and you can add to your own project. Annotation Assemblies

To implement full functions of RasterEdge Imaging Annotation, three assemblies may be needed:

Assembly

Description

RasterEdge.Imaging.Annotation.dll

Annotation Classes, all you need to generate an Annotation object programmatically. Include Web controls you can integrate into your own ASP.NET project. You can draw, add, and burn annotations to document or image using graphics interface powered by JavaScript.

RasterEdge.Imaging.WebViewer.dll

RasterEdge.Imaging.WinControl.dll

See Also Web Viewer

Include Windows Form viewer controls that you can integrate into your own WinForm project. You can draw, edit, and burn annotations to document or image using graphics interface provided in these viewer controls.

Metadata BaseMetadata Class This class can be used as a collection of Metadata. For detailed usage, please see corresponding Metadata SampleCode. BaseMetadataItem class As an abstract class, it is used to record the implementation of each element of Metadata. And each Metadata type will be illustrated in detail. There’s a limitation to the supportive Metadata types. You may use BaseMetadataType to check whether your desired Metadata is supported or not. Introduction to Metadata Metadata is data that describes other data. RasterEdge Imaging allow viewing and manipulation of metadata stored in an image. The RasterEdge.Imaging.Codec namespace contains classes that handle image metadata. Metadata is a convenient way to store textual information in an image. RasterEdge Image allows this information to be accessed and manipulated. For example, it is possible to store the metadata information in a database, build a metadata viewer application, and to add your own metadata in the form of EXIF, IPTC, XMP, or COM markers. See the Metadata Demo installed with RasterEdge Image for an example of metadata use. Supported Metadata Types RasterEdge Image supports the following metadata types. EXIF tags IIM(IPTC) XMP data TIFF Tags In JPEG images, metadata is stored in "APPn markers". EXIF information is stored in an "APP1 marker", and IPTC and Photoshop Resource information is stored in an "APP13"marker. These

markers are created automatically when a JPEG image is encoded. Alternatively, you can use a method to copy metadata without re-compressing JPEG images. Image Formats Supporting Metadata The following Image Formats support Metadata. Metadata types

Operations

Image Format

EXIF

JPEG/Exif/TIFF

XMP

GIF89a/JPEG/JPEG2000/PNG/TIFF/ProstScript/SVG/PDF/ Html/DNG/Adobe Illustrator

IIM(IPTC)

JPEG/Exif/TIFF/Jpeg2000/PNG

EXIF Metadata Parse Exif Metadata from TIFF File Exchangeable image file format (officially Exif, not EXIF according to JEIDA/JEITA/CIPA specifications) is a standard that specifies the formats for images, sound, and ancillary tags used by digital cameras (including smartphones), scanners and other systems handling image and sound files recorded by digital cameras. Embed Exif to TIFF So far, embedding Exif information into TIFF file is supported. If you have a TIFFDocument object and want to embed Exif information, you may do as follows. Parse

Update Exif from File

Support parsing Exif Tag from TIFF file and modifying Exif value. We represent Exif Tag as EXIFDefine. For more Tag information, please refer to the International Standard Exif 2.0 or visithttp://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif.html. You can get the accurate Exif information from a TIFDocument with the following method.

EXIFMetadata exif = (EXIFMetadata)doc.GetEXIFMetadata(1);//Get EXIF information of the first TIF page Console.WriteLine(metadata[0].ExifItemValue.Values[0]);//Have access to specific Tag value

Below is the method to add an EXIF. TIFFTag tag = (TIFFTag)0x8888; TIFFField field = new TIFFField(tag, TIFFDataType.ASCII); Field.Value.Add(new TIFFAscii(“RasterEdge”);

EXIFMetadataItem item = new EXIFMetadataItem(field); Metadata.Add(item); Doc.AddEXIFMetadataItem(item, 1);

Then, EXIF information is successfully embedded into TIFF file (more image formats are also supported). You can freely customize your own data as well. Certainly, the deletion of EXIF is easy to achieve.

XMP Extract XMP from supportive file format as Stream or byte[] array. We currently support getting XMP data from TIFF, TIFFEP, and DNG files, and you can use the following code. TIFFDoucment doc = (TIFFDocument)REFile.OpenDocuemntFile(@“1.tif”, new TIFDecoder()); String xmp = doc.GetXMPMetadata(0);//0 represents XMPData of the first page

Another method: Byte[] xmp = doc. GetXMPMetadataAsArray(1);

Barcode Read Developed as powerful linear & 2d barcodes recognition SDK, this Barcode Reader Add-on can be easily combined with .NET Imaging SDK and available in any .NET applications. It supports detecting and reading barcodes from .NET project images or documents. More than 20 linear and 2d barcodes are supported. Linear Barcodes

2DBarcodes

Australia Post

EAN-13

ISSN

POSTNET

Data Matrix

Codabar

Identcode

ITF-14

RM4SCC

PDF-417

Code 39

Intelligent Mail

Leitcode

UPC-A

QR Code

Code 128

Interleaved 2 of 5

Patch Code

UPC-E

EAN-8

ISBN

PLANET

If you want to test our Barcode Reader Add-on in .NET, C#, VB.NET applications, please firstly do as follows: Integrate package dlls into Visual Studio (2005 or later) project by adding reference; In all, you need these dlls: RasterEdge.Imaging.Basic.dll, RasterEdge.Imaging.Basic.Codec.dll, and RasterEdge.Imaging.Barcode.Scanner.dll. Now, you may easily read barcodes in C# and VB.NET Classes. How to’s How to: Read Barcode from Image To read barcode from image file, you may directly refer to the following demo codes in C# and VB.NET. In details, codes below allow you to load an image file containing barcode into a REImage object and read barcode information out of that REImage object. Also, you can set and scan a specific region of REImage. If you want to read a barcode image file, our barcode reader add-on can also help with that. In C# Class Demo Code:

public static void ReadBarcodeFromImage(string filename) { // invoke this static method only once at the beginning of codes WorkRegistry.Reset(); //load an image containing the barcode image on it. REImage reImage = new REImage(filename); // set reader setting ReaderSettings setting = new ReaderSettings(); // read qr code setting.AddTypesToRead(BarcodeType.QRCode); // read also code128 setting.AddTypesToRead(BarcodeType.Code128); // read image Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, reImage); foreach (Barcode barcode in barcodes) { // output barcode data onto the screen Console.WriteLine(barcode.DataString); } }

In VB.NET Class Demo Code: Public Shared Sub ReadBarcodeFromImage(filename As String) WorkRegistry.Reset() ' invoke this static method only once at the beginning of codes 'load an image containing the barcode image on it. Dim reImage As New REImage(filename) ' set reader setting Dim setting As New ReaderSettings() ' read qr code setting.AddTypesToRead(BarcodeType.QRCode) ' read also code128 setting.AddTypesToRead(BarcodeType.Code128) ' read image Dim barcodes As Barcode() = BarcodeReader.ReadBarcodes(setting, reImage) For Each barcode As Barcode In barcodes ' output barcode data onto the screen Console.WriteLine(barcode.DataString) Next End Sub

How to: Read Barcode from Document

Besides images, RasterEdge .NET barcode reader add-on also empowers you to read barcodes from several document files, like TIFF, PDF, Word and Excel. In the following parts, you will get the demo codes for barcode reading from these documents. Please note that, for each document barcode scanning, you also need to add corresponding dll into your project, including RasterEdge.Imaging.TIFF.dll, RasterEdge.Imaging.PDF.dll, RasterEdge.Imaging.MSWordDocx.dll, and RasterEdge.Imaging.MSExcel.dll. In C# Class Demo Code: For Barcode Reading from PDF public static void ReadBarcodeFromPdf(string filename, int pageIndex) { // invoke this static method only once at the beginning of codes WorkRegistry.Reset(); //generate pdf document BaseDocument doc = new PDFDocument(filename); //get the page you want to read barcode from BasePage page = doc.GetPage(pageIndex); //set reader setting ReaderSettings setting = new ReaderSettings(); setting.AddTypesToRead(BarcodeType.Code39); // read out barcode information Barcode[] barcodes = BarcodeReader.ReadBarcodes(setting, page); //output barcode information foreach (Barcode barcode in barcodes) { Console.WriteLine(barcode.DataString); } }

In VB.NET Class Demo Code: For Barcode Reading from PDF Public Shared Sub ReadBarcodeFromPdf(filename As String, pageIndex As Integer) WorkRegistry.Reset() ' invoke this static method only once at the beginning of codes 'generate pdf document Dim doc As BaseDocument = New PDFDocument(filename) 'get the page you want to read barcode from Dim page As BasePage = doc.GetPage(pageIndex) 'set reader setting Dim setting As New ReaderSettings() setting.AddTypesToRead(BarcodeType.Code39) ' read out barcode information Dim barcodes As Barcode() = BarcodeReader.ReadBarcodes(setting, page) 'output barcode information For Each barcode As Barcode In barcodes Console.WriteLine(barcode.DataString) Next End Sub

Advanced ReaderSettings Below is a table list of settings that you can control in .NET barcode reading applications. Parameters in ReaderSettings

Description

Direction

Used to control the direction of whole barcode reading process. Valid values: BottomToTop, LeftToRight, RightToLeft, TopToBottom, Undefined.

NumberOfBarcodeToRead

Used to define the numbers of barcodes that you want to read from image or document. This can be used to save barcode scanning time. For instance, there’s one barcode on your image, you may set this to be 1. Then our reader will scan it only and save time from scanning the whole image.

ReadingQuality

Used to determine which is the priority, speed when set to false or quality of reading when set to true.

RegionOfInterest

Used to define a rectangle for specific area barcode reading. To achieve this, you can set the region of interest as (start point horizontal, start point vertical, stop point horizontal, stop point vertical). Please note that, the points values should be in percentage. For example, (0, 0, 50, 50) means to scan left top quarter of the image.

ScanInterval

Used to control intervals between two scans.

SkipValidation

Used to validate accuracy of barcode scanning.

Type

Used to define a barcode type for scanning from your image. This is suggested to be set if you need to scan a specific barcode type. If it is “All”, the scanning process will be slowed down.

Barcode Create Barcode Creator Add-on is an advanced control, seamlessly integrating with RasterEdge DocImageSDK for .NET. This Barcode Creator Add-on can be easily used in .NET Framework 2.0 and above for high-quality linear and 2d barcodes creation and customization. More than 20 barcodes can be created. See as below. Linear Barcodes

2DBarcodes

Codabar

Code 128

Identcode

ITF-14

RM4SCC

Data Matrix

Code 11

EAN-8

Intelligent Mail

Leitcode

UPC-A

PDF-417

Code 2 of 5

EAN-13

Interleaved 2 of 5

MSI Plessey

UPC-E

Micro PDF-417

Code 39

EAN-128

ISBN

PLANET

QR Code

Code 93

GS1 DataBar

ISSN

POSTNET

Micro QR Code

To test our Barcode Creator Add-on in .NET, C#, VB.NET applications, you need to: Integrate package dlls into Visual Studio (2005 or later) project by adding reference; In all, you need these dlls: RasterEdge.Imaging.Basic.dll, RasterEdge.Imaging.Basic.Codec.dll, and RasterEdge.Imaging.Barcode.Creator.dll. Ready to create barcodes in C# and VB.NET Classes. How to’s How to: Draw Barcode on Image The demos below can help you draw barcodes on images and the supported image formats include png, gif, jpeg, bmp and tiff. Here, we take QR Code drawing in C# and VB.NET Classes as examples. In C# Class Demo Code: WorkRegistry.Reset();// invoke this static method only once at the beginning of codes // create an REImage you want to draw on

REImage reImage = new REImage(@"c:\samplePNG.png", ImageType.PNG); //Create a QR Code barcode QRCode barcode = new QRCode(); barcode.Data = "test123456789"; //Input encodable data barcode.X = 20.0F; //Set module size //set the qr code margin which for qr code should be 4 times the width of X module barcode.LeftMargin = barcode.RightMargin = barcode.TopMargin = barcode.BottomMargin = 20.0f * 4; barcode.Resolution = 96; //Set QR Code barcode printing resolution barcode.Rotate = Rotate.Rotate0; //Set rotate barcode.DrawBarcode(reImage, 0, 0); //Draw barcode on REImage with location x and y reImage.Save(ImageType.PNG, @"c:\qr.png");

You can not only draw barcode on image but also on document page. Demo Code: WorkRegistry.Reset();// invoke this static method only once at the beginning of codes Linear linearBarcode = new Linear(); linearBarcode.Type = BarcodeType.CODE39; linearBarcode.Data = "123456789"; linearBarcode.Resolution = 96; linearBarcode.Rotate = Rotate.Rotate0; // load pdf document, you can also load document like tiff, word, excel, ppt PDFDocument pdf = new PDFDocument(@"c:\REImage.pdf"); // get the first page BasePage page = pdf.GetPage(0); // create barcode image from barcode Object REImage barcodeImage = linearBarcode.ToImage(); // add barcode image to the desired location page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f)); pdf.Save(@"c:\REImageBarcoded.pdf");

In VB.NET Class Demo Code: WorkRegistry.Reset() ' invoke this static method only once at the beginning of codes ' create an REImage you want to draw on Dim reImage As New REImage("c:\samplePNG.png", ImageType.PNG) 'Create a QR Code barcode Dim barcode As New QRCode() barcode.Data = "test123456789" 'Input encodable data barcode.X = 20F

'set the qr code margin which for qr code should be 4 times the width of X module barcode.LeftMargin = barcode.RightMargin = barcode.TopMargin = barcode.BottomMargin = 20.0f * 4 'Set module size barcode.Resolution = 96 'Set QR Code barcode printing resolution barcode.Rotate = Rotate.Rotate0 'Set rotate barcode.DrawBarcode(reImage, 0, 0) 'Draw barcode on REImage with location x and y reImage.Save(ImageType.PNG, "c:\qr.png")

Besides drawing barcode on image, you can also draw it on document page. Demo Code: WorkRegistry.Reset() ' invoke this static method only once at the beginning of codes Dim linearBarcode As New Linear() linearBarcode.Type = BarcodeType.CODE39 linearBarcode.Data = "123456789" linearBarcode.Resolution = 96 linearBarcode.Rotate = Rotate.Rotate0 ' load pdf document, you can also load document like tiff, word, excel, ppt Dim pdf As New PDFDocument("c:\REImage.pdf") ' get the first page Dim page As BasePage = pdf.GetPage(0) ' create barcode image from barcode Object Dim barcodeImage As REImage = linearBarcode.ToImage() ' add barcode image to the desired location page.AddImage(barcodeImage, New System.Drawing.PointF(100F, 100F)) pdf.Save("c:\REImageBarcoded.pdf")

How to: Create Barcode and Save as Image If you want to directly create a barcode and save it as image in C# or VB.NET Class, the following demo codes may help you. In C# Class Demo Code: Linear barcode = new Linear();//Create a barcode barcode.Type = BarcodeType.CODE128;//Select barcode type barcode.Data = "123456789";//Set barcode data

barcode.X = 1.0F;//Set x barcode.Y = 60.0F;//Set y barcode.Resolution = 96;//Set resolution barcode.Rotate = Rotate.Rotate0;//Set rotate REImage reImage = barcode.ToImage(); reImage.Save(ImageType.PNG, @"c:\qr.png");

In VB.NET Class Demo Code: Dim barcode As New Linear() 'Create a barcode barcode.Type = BarcodeType.CODE128 'Select barcode type barcode.Data = "123456789" 'Set barcode data barcode.X = 1F 'Set x barcode.Y = 60F 'Set y barcode.Resolution = 96 'Set resolution barcode.Rotate = Rotate.Rotate0 'Set rotate Dim reImage As REImage = barcode.ToImage() reImage.Save(ImageType.PNG, "c:\qr.png")

Advanced Settings Below is a table of all supportive barcodes properties. You may free to customize all the properties in your .NET project. ClassAttribute

Value

Description

AddCheckSum

Type: bool; Default: false

Enabled to add barcode checksum at the end.

AutoResize

Type: bool; Default: false

Enabled to automatically resize the created barcode image.

BackColor

Type: Color; Default: white

Used to set the background color of barcode image.

Barcode Type All linear barcodes. For Intelligent Mail, this property is not applied. All barcodes All barcodes

BarAlignment

Type: int Default: Center

BarcodeHeight

Type: float Default: 0

BarcodeWidth

Type: float Default: 0

BearerBarHori

Type: float Default: 1

BearerBarVert

Type: float Default: 1

BottomMargin

Type: float Default: 0

CodabarStartCh ar

CodabarStopCh ar

ColumnCount

Type: CodabarStartStopCh ar Default: A Type: CodabarStartStopCh ar Default: A Type: int Default: 5

Used to set the horizontal alignment of barcode inside the image. Valid values: Left, Center, Right. Used to set the height of barcode image. If setting is smaller than required minimum height, the barcode image will be automatically reset. Used to set the width of barcode image. If setting is smaller than required minimum width, the barcode image will be automatically reset. Used to set the value of top and bottom bars (horizontal bearer bars). Valid values: 0 to 10, which should be a multiple of X. Used to set the value of left and right bars (vertical bearer bars). Valid values: 0 to 10, which should be a multiple of X. Used to set the size of bottom margin. For linear barcodes, 10X is recommended. For Data Matrix, PDF417, Micro PDF417, QR Code, Micro QR Code, X/2X/4X, 2X, X, 4X, 2X are recommended respectively. Used to set the start character of Codabar. Valid values: CodabarStartStopChar.A, B, C, D. Used to set the stop character of Codabar. Valid values: CodabarStartStopChar.A, B, C, D. Used to set the number of columns and this should be increased according to your data size. Valid values: 1 to 30.

All barcodes

All barcodes

All barcodes

ITF14

ITF14

All barcodes

CODABAR

CODABAR

PDF417

Data

Type: string Default: ""

Type: DataMatrixDataMod e Default: DataMatrixDataMod e.ASCII

DataMode

Type:PDF417DataM ode Default: PDF417DataMode.T ext

Type: QRCodeDataMode Default: QRCodeDataMode.A uto

ECI

ECL

Type: int Default: 3 Type: PDF417ECL Default: PDF417ECL.Level_2 Type: QRCodeECL Default: QRCodeECL.L

Used to input the data value that will be encoded in barcode. Valid values vary from different barcode types. Used to set the data encoding mode of Data Matrix. Valid values: DataMatrixDataMode.Auto, ataMatrixDataMode.ASCII, DataMatrixDataMode.C40, DataMatrixDataMode.Text, DataMatrixDataMode.X12, DataMatrixDataMode.Edifact, DataMatrixDataMode.Base256. Used to set the data encoding mode of (Micro) PDF417. Valid values: PDF417DataMode.Auto, PDF417DataMode.Text, PDF417DataMode.Byte, PDF417DataMode.Numeric, PDF417DataMode.Customer. Used to set the data encoding mode of (Micro) QR Code. Valid values: QRCodeDataMode.Auto, QRCodeDataMode.AlphaNumer ic, QRCodeDataMode.Byte, QRCodeDataMode.Numeric, QRCodeDataMode.Kanji. Used to enable the output data stream to have different interpretations that differ from the default character set. Used to set the error correction level of PDF417. Valid values: PDF417ECL.Level_0 to PDF417ECL.Level_8. Used to set the error correction level of QR Code. Valid values: QRCodeECL.L, QRCodeECL.M, QRCodeECL.Q, QRCodeECL.H.

All barcodes

DataMatrix

PDF417, MicroPDF417

QRCode, MicroQRCode

QRCode

PDF417

QRCode

FileId FNC1 ForeColor

FormatMode

I

LeftMargin

Type: int Default: 0

Use to set FileId property to be identified to the same file.

DataMatrix

Type: FNC1 Default: FNC1. FNC1_NONE Type: Color Default: black

Used to encode GS1 compatible barcode and FNC1 value should be set to FNC1.FNC1_1ST_POS. Used to set the foreground color of barcode image.

EAN128, DataMatrix, QRCode All barcodes

Type: DataMatrixFormatM ode Default: DataMatrixFormatM ode. Format_10X10 Type: float Default: 1.0f

Used to define the format of Data Matrix to use on that symbology. Valid values: please directly see enum DataMatrixFormatMode.Forma t_*X*.

Type: float Default: 0

Macro

Type: bool Default: false

MacroSegmentI ndex

Type: int Default: 0

MacroSegment Count

Type: int Default: 0

MacroFileIndex

Type: int Default: 0

N

Parity

Used to set the space between two characters of barcode. Valid value: a multiple of X. Used to set the size of left margin. For linear barcodes, 10X is recommended. For Data Matrix, PDF417, Micro PDF417, QR Code, Micro QR Code, X/2X/4X, 2X, X, 4X, 2X are recommended respectively. Enabled to apply Macro PDF417 function. Used to set the position of current symbol in the sequence, which begins with 0. Used to set the number of total symbols which consist of the sequence. Be identified to the same file.

Type: float Default: 2.0f

Used to set the ratio of wide bar to narrow bar. Valid values: 2.0 to 3.0 inclusive.

Type: int Default: 0

Used to set Parity property of QR Code.

DataMatrix

CODE39

All barcodes

PDF417, MicroPDF417 PDF417, MicroPDF417 PDF417, MicroPDF417 PDF417, MicroPDF417 CODABAR, CODE2OF5, CODE39, INTERLEAVED25, ITF14 QRCode

ProcessTilde

Type: bool Default: false(for linear barcodes)/true (for 2d barcodes)

Resolution

Type: int Default: 72

RightMargin

Type: float Default: 0

Rotate

Type: Rotate Default: Rotate0

Enabled to use the tilde character "~" to specify special characters in input data.

RowCount

Type: int Default: 3

Used to set the barcode image resolution (in DPI, Dots per inch). Used to set the size of right margin. For linear barcodes, 10X is recommended. For Data Matrix, PDF417, Micro PDF417, QR Code, Micro QR Code, X/2X/4X, 2X, X, 4X, 2X are recommended respectively. Used to rotate barcode image to a desired position. Valid values: Rotate.Rotate0, Rotate.Rotate90, Rotate.Rotate180, Rotate.Rotate270. Used to set the number of rows. Valid values: 3 to 90.

ShortTallRatio

Type: float Default: 0.4f

Used to set the ratio of short bar to tall bar (Y).

ShowCheckSum Char

Type: bool Default: true

Enabled to show the check digit(s) at the end of barcode text.

ShowStartStopI nText

Type: bool Default: true

ShowText

Type: bool Default: true

Enabled to show a * at the beginning and end of barcode text. Enabled to show barcode text under the barcode bars.

StructuredAppe nd

Type: bool Default: false

Enabled to apply Structured Append function to barcode.

CODE39, CODE128, EAN128, DataMatrix, QRCode, MicroQRCode, PDF417, MicroPDF417 All barcodes

All barcodes

All barcodes

PDF417 PLANET, POSTNET All linear barcodes. For Intelligent Mail, this property is not applied. CODE39 All linear barcodes DataMatrix, QRCode

SymbolCount

Type: int Default: 0

SymbolIndex

Type: int Default: 0

Used to set the number of total symbols which consist of the sequence. Used to set the position of current symbol in the sequence, which begins with 0.

SupData

Type: string Default: ""

Used to input the supplement data to encode in add-on barcode. Valid values: 2 or 5 digits.

SupHeight

Type: float Default: 0.8f

Used to set the height of addon barcode bar. Valid value: a multiplicator of Y.

SupSpace

Type: float Default: 15

Used to set the space between the main barcode and its addon barcode.

Type: Color Default: black

Used to set the color of barcode text.

TextColor

TextFont

TextMargin

Type: Font Default: new Font("Arial", 9f, FontStyle.Regular) Type: float Default: 6

Used to set the font style of barcode text. Used to set the space between barcode bar and data text.

DataMatrix, QRCode DataMatrix, QRCode EAN8_2, EAN8_5, EAN13_2, EAN13_5, ISBN_2, ISBN_5, ISSN_2, ISSN_5, UPCA_2, UPCA_5, UPCE_2, UPCE_5 EAN8_2, EAN8_5, EAN13_2, EAN13_5, ISBN_2, ISBN_5, ISSN_2, ISSN_5, UPCA_2, UPCA_5, UPCE_2, UPCE_5 EAN8_2, EAN8_5, EAN13_2, EAN13_5, ISBN_2, ISBN_5, ISSN_2, ISSN_5, UPCA_2, UPCA_5, UPCE_2, UPCE_5 All linear barcodes

All linear barcodes

All linear barcodes

TopMargin

TopTextColor

TopTextFont

Truncated

Type

UOM

UPCENumber

Version

Type: float Default: 0

Type: Color Default: black Type: Font Default: new Font("Arial", 9f, FontStyle.Regular)

Type: bool Default: false

Type: BarcodeType Default: CODE128

Used to set the size of top margin. For linear barcodes, 10X is recommended. For Data Matrix, PDF417, Micro PDF417, QR Code, Micro QR Code, X/2X/4X, 2X, X, 4X, 2X are recommended respectively. Used to set the color of text above barcode. Used to set the font style of text above barcode.

Enabled to apply Truncated PDF417 function, which may be used if space considerations are the primary concern and symbol damage is unlikely. Used to set the linear barcode type.

Type: int Default: 0

Use to set the unit of measure for all size related settings. Valid values: UnitOfMeasure.PIXEL, UnitOfMeasure.CM, UnitOfMeasure.INCH. Used to set the number system of UPC-E. Valid values: 0, 1.

Type: MicroPDF417Versio n Default: Version_3X08.

Used to set the version of Micro PDF417. Valid values: please directly see enum MicroPDF417Version Version_*X*.

Type: UnitOfMeasure Default: PIXEL

Type: QRCodeVersion Default: QRCodeVersion.V1

Used to set the version of QR Code. Valid values: V1 to V40.

All barcodes

ISBN, ISSN

ISBN, ISSN

PDF417

All linear barcodes

All barcodes

UPCE

MicroPDF417

QRCode

Type: MicroQRCodeVersio n Default: Version.M4_L. Type: float Default: 1

Used to set the version of Micro QR Code. Valid values: M1 to M4_Q.

XtoYRatio

Type: float Default: 0.3333333f

Used to set the width of barcode bar module (narrow bar). Used to set the ratio of bar width to bar height.

Y

Type: float Default: 60

Used to set the height of barcode bar module.

X

MicroQRCode

All barcodes PDF417, Micro PDF417 All linear barcodes

TWAIN Scanning TWAIN Scanning Overview With RasterEdge.Imaging.Twain assembly you can acquire raw images from input devices such as scanner and camera. You can query the capacities supported by the device. You may set or alter scanning properties, if supported, for the acquisition process. Since RasterEdge.Imaging.Twain is a dll that is built on official Twain driver. Please install the official TWAINDSM.dll (provided in our dlls collection) manually before using RasterEdge.Imaging.Twain. Simply put TWAINDSM.DLL in x86 folder under the Windows System directory (normally C:\Windows\System32). On a 64bit system, make sure TWAINDSM.DLL in x64 folder ends up in the WOW64 System directory (normally C:\Windows\SysWOW64) Following are the basic classes you need to know about to gain image from scanning process. Acquisition The Acquisition object is the primary class in RETwain. You can drop this component onto aForm after adding it to the toolbox, or you can instantiate it directly. This is the only class you need to add standard image acquisition capabilities to an application.For greater control over the acquire process, this class contains a collection of Device objects that control numerous properties used for the image acquisition. TWAINDevice The TWAINDevice object provides full access to a TWAIN compatible source on the system. Use it to open a connection to the device, to get and set properties, and then to acquire one or more images. Because this class represents a system device resource, you cannot create an instance of it. You can obtain an instance to a Device object by calling GetAvailbleDevices, or from the Devices collection in the Acquisition object. Getting Started with RETwain If you do not want to set and query properties of the Device or customize your acquisition, an instance of the Acquisition class is enough for basic scanning process. Call the acquire method for the scanning process. Default property and device are used.

Note: You need to add reference to RasterEdge.Imaging.Twain.dll if you want to use RETwain. Example code Public void Scanning() { Acquisition acq = newAcquisition(); acq.ImageAcquired += new ImageAcquiredEventHandler(acq_ImageAcquired); acq.Aquire();

}

Setting Up Events You need to use events when acquiring images. When an image is acquired, the ImageAcquiredevent fires, providing an ImageAcquiredEventArgs object that contains the image. At the very least,the ImageAcquired event must be handled, and it is recommended that the AcquireCanceled and AcquireCompleted events also be handled. The following code shows how the image is handled. this.acquisition.ImageAcquired += new ImageAcquiredEventHandler (OnImageAcquired); private void OnImageAcquired(object sender, ImageAcquiredEventArgs args) { // If the image exists,save it to local file or do some operation if(args.OutputImage != null) { args.OutputImage.Save(RasterEdge.Imaging.Basic.ImageType.PNG, @"C:\test.png");

} }

Getting and Setting Properties To get or set a device property,you must open a connection to the device using the Open() method. Whenever the Open() method is invoked, the Close() method must be invoked to close the connection. Closing aconnection resets all of the device properties to their default values and therefore a device should be closed after the image or all desired properties have been acquired. Note: To get a device object you must get it through an Acquisition Instance.

The code below opens a connection to the device in order to retrieve the default Resolution values of the device, and then closes the connection. This technique can be useful if you are looking for a device of choices with specific default properties or capabilities. C# device.Open(); int res = device.ScanSetting.Resolution; int bitDepth = device.ScanSetting.BitDepth; device.Close();

How to’s How to Do Console Based Scanning Scanning from the Console is done similarly to scanning in a WinForms application

public class AcquisitionClass { static void Main(string[] args) { Acquisition acquisition = new Acquisition(); AddEvents(acquisition); count = 0; List names = acquisition.GetAvailbleDevicesName(); string deviceName = names[0]; TWAINDevice device = acquisition.GetDevice(deviceName); Console.Out.WriteLine("---Beginning Scan---"); device.Open(); //scan all availble pages device.ScanSetting.ShouldTransferAllPages = true; device.Acquire(); Console.Out.WriteLine("---Ending Scan---\n Press Enter To Quit"); Console.In.Peek(); } private static void AddEvents(Acquisition acquisition) {

acquisition.ImageAcquired += new ImageAcquiredEventHandler(acquisition_ImageAcquired); acquisition.AcquireCompleted += new AcquireCompletedEventHandler(acquisition_AcquireCompleted); acquisition.AcquireCanceled += new AcquireCanceledEventHandler(acquisition_AcquireCanceled); }

static void acquisition_AcquireCanceled(object sender, EventArgs args) { Console.Out.WriteLine("Acqusition Canceled"); }

static void acquisition_AcquireCompleted(object sender, AcquireCompletedEventArgs args) { Console.Out.WriteLine("Acquisition Finished"); }

static int count; static void acquisition_ImageAcquired(object sender, ImageAcquiredEventArgs args) { string filename = "out" + count++ + ".tif"; //save scanned images as png args.OutputImage.Save(ImageType.PNG, @"c:\"+count+".png"); Console.Out.WriteLine("Frame " + count + " Acquired. Saved At: " + filename); }

}

How to Scan Many Pages into PDF or TIFF file A common task in the document imaging world is to scan many pages into a single file.RETwain, along with REImage can easily be used to accomplish this task. The two most popular multipage

image formats are TIFF and PDF, and this example will concentrate on PDF. Since in RasterEdge Imaging, the TIFFDocument and PDFDocument have common prototype, BaseDocument Class, so the procedure for TIFF is very similar. The key is to set up the event to assist with the process of scanning from device and convert the image obtained to form a PDFDocument. AcquireCanceled: Raised if the user cancels the acquisition process. AcquireCompleted: Raised when the scanner has finished scanning the last page. ImageAcquired: Raised each time the scanner finishes scanning a page. Note: You need to reference RasterEdge.Imaging.PDF Assembly and RasterEdge.Imaging.Twain Assembly to your project to complete the following function. private bool _acquireCanceled; private List _imageList; public void ScanImages() { _acquireCanceled = false; Acquisition myAcquisition = new Acquisition(); myAcquisition.AcquireCanceled += new AcquireCanceledEventHandler(OnAcquireCanceled); myAcquisition.AcquireCompleted += new AcquireCompletedEventHandler(OnAcquireCompleted); myAcquisition.ImageAcquired += new ImageAcquiredEventHandler(OnImageAcquired); TWAINDevice device = myAcquisition.DefaultDevice; device.Open(); device.ScanSetting.ShouldTransferAllPages = true; _imageList = new List(); device.Acquire(); } private void OnImageAcquired(object sender, ImageAcquiredEventArgs args) { if (args.OutputImage != null) { //Add Scaned images to image collection _imageList.Add(args.OutputImage);

} } private void OnAcquireCanceled(object sender, EventArgs args) { _acquireCanceled = true; }

private void OnAcquireCompleted(object sender, AcquireCompletedEventArgs args) { if (_acquireCanceled) return; //form a pdf document using image collection scanned PDFDocument doc = new PDFDocument(_imageList.ToArray()); //save pdf document doc.Save(@"c:\ScannedPDF.pdf"); doc.Dispose(); // do some extra work to finish compose the pdf document.

////Get a tiff document using similar operation //TIFFDocument doc = new TIFFDocument(_imageList.ToArray()); ////save tiff document //doc.Save(@"c:\scannedTiff.tif"); //doc.Dispose();

} }

Licensing RasterEdge Imaging Purchasing License Before you can use RasterEdge Toolkit to develop your commercial software, you need to obtain required SDK license. The license can be purchased directly from the RasterEdge website. If you have any questions, please contact us at [email protected].