Create PDF invoice in Windows Forms application. Written by Apitron Documentation Team



Similar documents
Create PDF Forms in ios applications using Xamarin PDF library by Apitron. Written by Apitron Documentation Team

Catalog Creator by On-site Custom Software

PDF MAKER FOR VTIGER CRM

MicroStrategy Quick Guide: Creating Prompts ITU Data Mart Support Group, Reporting Services

Coding HTML Tips, Tricks and Best Practices

CREATING EXCEL PIVOT TABLES AND PIVOT CHARTS FOR LIBRARY QUESTIONNAIRE RESULTS

ADOBE DREAMWEAVER CS3 TUTORIAL

Ansur Test Executive. Users Manual

Using Adobe Dreamweaver CS4 (10.0)

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

Participant Guide RP301: Ad Hoc Business Intelligence Reporting

2/24/2010 ClassApps.com

We automatically generate the HTML for this as seen below. Provide the above components for the teaser.txt file.

Table of Contents. What is ProSite? What is Behance? How do ProSite & Behance work together? Get Started in 6 Easy Steps.

Your Guide to the All New, Drag & Drop, Mobile-Responsive Builder

Instructions for Formatting MLA Style Papers in Microsoft Word 2010

Teradata SQL Assistant Version 13.0 (.Net) Enhancements and Differences. Mike Dempsey

Access II 2007 Workshop

MAKER FOR VTIGER CRM

Crystal Reports Designer Version 10

Customizing forms and writing QuickBooks Letters

DIGITAL DESIGN APPLICATIONS Word Exam REVIEW

MS Excel. Handout: Level 2. elearning Department. Copyright 2016 CMS e-learning Department. All Rights Reserved. Page 1 of 11

DNNCentric Custom Form Creator. User Manual

Step-by-Step Instructions for Setting Up a Paper in APA Format

MAKER FOR VTIGER CRM

Recreate your Newsletter Content and Layout within Informz (Workshop) Monica Capogna and Dan Reade. Exercise: Creating two types of Story Layouts

How To Change Your Site On Drupal Cloud On A Pcode On A Microsoft Powerstone On A Macbook Or Ipad (For Free) On A Freebie (For A Free Download) On An Ipad Or Ipa (For

CONTENTM WEBSITE MANAGEMENT SYSTEM. Getting Started Guide

Data Warehousing With Microsoft Access

Creating Accessible Word Forms. Contents. Introduction

The Essential Guide to HTML Design

Creating Mailing Lables in IBM Cognos 8 Report Studio

Application Note. Building a Website Using Dreamweaver without Programming. Nan Xia. MSU ECE 480 Team 5

HTML Egg Pro. Tutorials

Get to know PayAnywhere.

Create and load PDF Forms in Universal Applications using Windows Store and Windows Phone PDF library. Written by Apitron Documentation Team

Creating Personal Web Sites Using SharePoint Designer 2007

Joomla! 2.5.x Training Manual

STC: Descriptive Statistics in Excel Running Descriptive and Correlational Analysis in Excel 2013

Quick Reference Guide

Adobe Dreamweaver CC 14 Tutorial

E-Commerce Installation and Configuration Guide

State of Nevada. Ektron Content Management System (CMS) Basic Training Guide

Ingeniux 8 CMS Web Management System ICIT Technology Training and Advancement (training@uww.edu)

Personal Portfolios on Blackboard

TIBCO Spotfire Automation Services 6.5. User s Manual

BID2WIN Workshop. Advanced Report Writing

Caldes CM12: Content Management Software Introduction v1.9

Instructions for Formatting APA Style Papers in Microsoft Word 2010

Microsoft PowerPoint 2010 Templates and Slide Masters (Level 3)

Fairsail PDF Template Generator: A Complete Guide

Microsoft Access 2007 Introduction

Create a Poster Using Publisher

Kentico CMS 5.5 User s Guide

Integrating Microsoft Word with Other Office Applications

Excel 2003 A Beginners Guide

Access 2007 Creating Forms Table of Contents

Desktop Studio: Importing Crystal Reports

LaGuardia Community College Thomson Ave, Long Island City, New York Created by ISMD s Dept. Training Team. Overview

Search help. More on Office.com: images templates. Here are some basic tasks that you can do in Microsoft Excel 2010.

1. To start Installation: To install the reporting tool, copy the entire contents of the zip file to a directory of your choice. Run the exe.

USING MARKETING TOOLS. 1. Marketing Tools Overview. 2. Partner Program. 3. Affiliate Program. 4. Flyers

SelectSurvey.NET Basic Training Class 1

Kentico CMS, 2011 Kentico Software. Contents. Mobile Development using Kentico CMS 6 2 Exploring the Mobile Environment 1

Web design build questions to ask new clients David Tully Web Designer/Developer

Microsoft FrontPage 2003

Working with the Ektron Content Management System

Kentico CMS 7.0 User s Guide. User s Guide. Kentico CMS

Website Development Komodo Editor and HTML Intro

Q&As: Microsoft Excel 2013: Chapter 2

NiceLabel Designer Standard User Guide

Responsive Web Design for Teachers. Exercise: Building a Responsive Page with the Fluid Grid Layout Feature

A ribbon has replaced the Desktop toolbar. You still have access to the same features, but the new interface makes them easier to find.

To change title of module, click on settings

Introduction to Macromedia Dreamweaver MX

Garfield Public Schools Fine & Practical Arts Curriculum Web Design

Spreadsheet - Introduction

Decision Support AITS University Administration. Web Intelligence Rich Client 4.1 User Guide

Create a New Database in Access 2010

wpf5concat Start Microsoft Visual Studio. File New Project WPF Application, Name= wpf5concat OK.

CONVERSION GUIDE Financial Statement Files from CSA to Accounting CS

KaleidaGraph Quick Start Guide

Microsoft Access Introduction

Mobile Web Design with HTML5, CSS3, JavaScript and JQuery Mobile Training BSP-2256 Length: 5 days Price: $ 2,895.00

Data-Tracker PLUS and Data-Viewer PLUS Software User s Guide

Working with the new enudge responsive styles

Joomla! template Blendvision v 1.0 Customization Manual

Hello. What s inside? Ready to build a website?

South China Bullion Client Trading Terminal USER MANUAL

1-Step Appraisals Jewelry Appraisal Software

Create a Web Page with Dreamweaver

SETTING UP SALESFORCE ORDERS FOR YOUR ORGANIZATION

Document Manager 2.0. User Guide

To reuse a template that you ve recently used, click Recent Templates, click the template that you want, and then click Create.

Merging Labels, Letters, and Envelopes Word 2013

Transcription:

Create PDF invoice in Windows Forms application Written by Apitron Documentation Team

Introduction Very common scenario where our.net PDF library comes into play is invoices or reports generation. With fixed and flow layout API offered by Apitron PDF Kit for.net, such tasks become quickly solvable. This post demonstrates how to create basic Windows Forms PDF invoice creation application, similar to the one many companies use on their daily basis. It generates PDF invoice based on entered company and customer info using Apitron PDF Kit.NET component. The complete sample can be found in Samples\Windows Forms folder inside the download package available on our website.

Solution overview Our application uses Windows Forms and is written in C#, it has just a single window with all necessary controls in place. It represents an invoicing tool for imaginary company called Home Depot which is selling various tools for home use. Company and customer information should be entered in multiline textboxes and products list should be filled using the data grid below. When the user finishes with the invoice, he or she clicks the Generate button and gets branded PDF invoice created. Image below demonstrates the running app main window with entered information. Pic. 1 PDF Invoice generator application, main window As you can see from this screenshot the controls layout is very basic, but as it s not the main point in this example, we decided to keep it simple and paid the most attention to the PDF generation part of the app.

Here you can see the resulting invoice generated from data set shown on the first picture. As an addition to the entered data, it contains the company logo in the page header and stamp image. See the image below: Pic. 2 Created PDF invoice

The code We won t dive into windows forms specifics here and focus only on PDF generation and related code. A few functions responsible for this are listed below: /// <summary> /// Generates the invoice based on entered data. /// </summary> /// <param name="stream">stream to save the resulting pdf into.</param> private void GenerateInvoice(Stream stream) // base path for images string imagespath = @"..\..\images"; // create document and register styles FlowDocument document = new FlowDocument(); /* style for products table header, assigned via type + class selectors */ document.stylemanager.registerstyle("gridrow.tableheader", new Style() Background = RgbColors.LightSlateGray); /* style matching all cells in rows with class "centeralignedcells" set and all cells in rows with class "centeralignedcell" set */ document.stylemanager.registerstyle("gridrow.centeralignedcells > *, gridrow > *.centeralignedcell", new Style() Align = Align.Center, Margin = new Thickness(0)); /* style matching all elements in rows with class "leftalignedcell" set */ document.stylemanager.registerstyle("gridrow > *.leftalignedcell", new Style() Align = Align.Left, Margin = new Thickness(5, 0, 0, 0)); /* default style for any cell in any grid row, assigned via type + child selectors, makes it right aligned */ document.stylemanager.registerstyle("gridrow > *", new Style() Align = Align.Right, Margin = new Thickness(0, 0, 5, 0)); // create resource manager and register image resources ResourceManager resourcemanager = new ResourceManager(); resourcemanager.registerresource(new Apitron.PDF.Kit.FixedLayout.Resources.XObjects.Image("logo", Path.Combine(imagesPath, "storelogo.png"), true) Interpolate = true); resourcemanager.registerresource(new Apitron.PDF.Kit.FixedLayout.Resources.XObjects.Image("stamp", Path.Combine(imagesPath, "stamp.png"), true) Interpolate = true); // construct page header which includes store logo and the text "Invoice" document.pageheader.margin = new Thickness(0, 40, 0, 20); document.pageheader.padding = new Thickness(10, 0, 10, 0); document.pageheader.height = 120; document.pageheader.background = RgbColors.LightGray; document.pageheader.lineheight = 60; document.pageheader.add(new Image("logo") Height = 50, Width = 50, VerticalAlign = VerticalAlign.Middle); document.pageheader.add(new TextBlock("Invoice") Display = Display.InlineBlock, Align = Align.Right, Font = new Font(StandardFonts.CourierBold, 20), Color = RgbColors.Black ); the code continues on next page

// page content section with padding Section pagesection = new Section() Padding = new Thickness(20); // add company info section pagesection.additems( CreateInfoSubsections(new string[] txtcompany.text, "Bill to:\r\n" + txtcustomerinfo.text)); // add horizontal line for visual separation pagesection.add(new Hr() Padding = new Thickness(0, 20, 0, 20)); // add products grid pagesection.add(createproductsgrid()); // add new line after grid pagesection.add(new Br Height = 20); // insert empty padding section and stamp image pagesection.add(new Section() Width = 250, Display = Display.InlineBlock); pagesection.add(new Image("stamp")); // add page section into document document.add(pagesection); // save document to stream document.write(stream, resourcemanager, new PageBoundary(Boundaries.A4)); Creates information sections located above the products table: /// <summary> /// Creates several info sections side by side based on given list of strings. /// </summary> /// <returns> /// List of created sections with textual information. /// </returns> private IList<Section> CreateInfoSubsections(string[] info) List<Section> createdsections = new List<Section>(); double width = 100.0/info.Length; for (int i = 0; i < info.length; i++) Section section = new Section() Width = Length.FromPercentage(width), Display = Display.InlineBlock; using (StringReader reader = new StringReader(info[i])) string currentline = null; while ((currentline = reader.readline())!= null) section.add(new TextBlock(currentLine)); section.add(new Br()); createdsections.add(section); return createdsections;

Creates products grid: /// <summary> /// Creates products grid. /// </summary> private Grid CreateProductsGrid() // create grid content element and its define columnts Grid productsgrid = new Grid(20, Length.Auto, 30, 50, 55, 60); // add header row productsgrid.add(new GridRow(new TextBlock("#"), new TextBlock("Product"), new TextBlock("Qty."), new TextBlock("Price"), new TextBlock("Disc.(%)"), new TextBlock("Total")) Class = "tableheader centeralignedcells" ); Decimal invoicetotal = 0; // enumerate the list of products and create grid rows foreach (ProductEntry product in products) TextBlock pos = new TextBlock(product.Pos.ToString()) Class = "centeralignedcell"; TextBlock description = new TextBlock(product.Description) Class = "leftalignedcell"; TextBlock qty = new TextBlock(product.Qty.ToString()) Class = "centeralignedcell"; TextBlock price = new TextBlock(product.Price.ToString(CultureInfo.InvariantCulture)); TextBlock discount = new TextBlock(product.Discount.ToString(CultureInfo.InvariantCulture)); TextBlock total = new TextBlock(product.Total.ToString(CultureInfo.InvariantCulture)); productsgrid.add(new GridRow(pos, description, qty, price, discount, total)); invoicetotal += product.total; // append "total" row productsgrid.add(new GridRow(new TextBlock("Total(USD)") ColSpan = 4, new TextBlock(invoiceTotal.ToString(CultureInfo.InvariantCulture)) ColSpan = 2)); return productsgrid; Definitions for all used styles and their descriptions can be found at the beginning of the GenerateInvoice function which is responsible for combing all parts of the invoice together.

Conclusion Using small piece of code we managed to create a fully functional Windows Forms PDF invoice generator. Apitron PDF Kit offers unlimited capabilities for developers interested in PDF processing and a good way to start is to read the book, describing it step by step with code samples and references to original specification. This free book is available for download from our website. We created plenty of C# samples for various platforms and included them in our download package. These samples demonstrate every aspect of PDF processing and, sometimes, can be adapted to your applications with minimal modifications. Windows desktop, Windows Phone, Windows Store, Xamarin ios and Android,.NET/Mono our component covers them all. We also offer free evaluation and royalty-free licensing. Contact us if you have any questions and we ll do our best to help you.