New Released Products – Suraj | Coding Passion Tue, 09 Oct 2018 07:03:49 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.8 PDF FILE MANIPULATION LIBRARY-Spire.PDF /pdf-file-manipulation-library-using-spire-doc/ /pdf-file-manipulation-library-using-spire-doc/#comments Fri, 19 Sep 2014 06:46:28 +0000 /?p=94 Background

As a computer programmer, sometimes you may need to automatically create and edit PDF document. Here I present you a free PDF processing library (Spire.PDF) which just meets the need.

Introduction

This library is very powerful and easy to use. Check the sample code below. Just three line of code, it creates a PDF document with one blank page. See, it is very easy. The method Add will just add a blank page into the PDF document.

PdfDocument doc = new PdfDocument();

PdfPageBase page = doc.Pages.Add();

doc.SaveToFile("result.pdf");

 

After adding a blank page, you should add some content to the page. Unless a blank page is what you want. You can add text, image, shapes, barcode, table, grid and all other stuff you want to page of PDF document.

These are some methods that the library provides:

page.Canvas.DrawString()

Add text to page.

page.Canvas.DrawImage()

Add image to page.

Class: PdfUnidimensionalBarcode

Draw(PdfPageBase page, PointF location);

Add barcode to page.

Class: PdfTable

Draw(page, new PointF(0, y));

Add table to page.

This library also supports watermark, encryption, digital signature, conversion to many file format, merge documents, split document, extracting text and image…. In a word, you can manipulate PDF files easily and flexibly using this library.

For example:

Encrypt the document:

//load pdf file

PdfDocument doc = new PdfDocument();

doc.LoadFromFile("sample.pdf");

//set the password

doc.Security.UserPassword = "test";

//save pdf file.

doc.SaveToFile("Encryption.pdf");

doc.Close();

 

Convert to XPS file:

//load pdf file

PdfDocument doc = new PdfDocument();

doc.LoadFromFile("sample.pdf");

//convert to xps file.

doc.SaveToFile("result.xps", FileFormat.XPS);

doc.Close();

 

Sample Code

In this part, I will give a demo showing how to use this library to create a very simple PDF document. If you find it difficult to understand the code, please check the above part.

Code:

 

// create a pdf document.

PdfDocument doc = new PdfDocument();

// create one page

PdfPageBase page = doc.Pages.Add();

float pageWidth = page.Canvas.ClientSize.Width;

float y = 0;

//add barcode

PdfCodabarBarcode barcode1 = new PdfCodabarBarcode("00:12-3456/7890");

barcode1.BarcodeToTextGapHeight = 1f;

barcode1.EnableCheckDigit = true;

barcode1.ShowCheckDigit = true;

barcode1.TextDisplayLocation = TextLocation.Bottom;

barcode1.TextColor = Color.Blue;

barcode1.BarHeight = 20;

barcode1.Draw(page, new PointF(5, 3));

y = y + 32;

PdfBrush brush2 = new PdfSolidBrush(Color.Black);

PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));

// add image into document

PdfImage image = PdfImage.FromFile("pic.bmp");

page.Canvas.DrawImage(image, new PointF(pageWidth - image.PhysicalDimension.Width, y));

float imageLeftSpace = pageWidth - image.PhysicalDimension.Width - 2;

float imageBottom = image.PhysicalDimension.Height + y;

// add text into document

PdfStringFormat format4 = new PdfStringFormat();

String text = System.IO.File.ReadAllText("sample.txt");

PdfTrueTypeFont font5 = new PdfTrueTypeFont(new Font("Arial", 10f));

format4.LineSpacing = font5.Size * 1.5f;

PdfStringLayouter textLayouter = new PdfStringLayouter();

float imageLeftBlockHeight = imageBottom - y;

PdfStringLayoutResult result

= textLayouter.Layout(text, font5, format4, new SizeF(imageLeftSpace, imageLeftBlockHeight));

if (result.ActualSize.Height < imageBottom - y)

{

imageLeftBlockHeight = imageLeftBlockHeight + result.LineHeight;

result = textLayouter.Layout(text, font5, format4, new SizeF(imageLeftSpace, imageLeftBlockHeight));

}

foreach (LineInfo line in result.Lines)

{

page.Canvas.DrawString(line.Text, font5, brush2, 0, y, format4);

y = y + result.LineHeight;

}

PdfTextWidget textWidget = new PdfTextWidget(result.Remainder, font5, brush2);

PdfTextLayout textLayout = new PdfTextLayout();

textLayout.Break = PdfLayoutBreakType.FitPage;

textLayout.Layout = PdfLayoutType.Paginate;

RectangleF bounds = new RectangleF(new PointF(0, y), page.Canvas.ClientSize);

textWidget.StringFormat = format4;

textWidget.Draw(page, bounds, textLayout);

// save pdf file.

doc.SaveToFile(@"..\..\sample.pdf");

doc.Close();

 

Conclusion:

This would help Developers if they are searching for any handy tool to reduce their work load .. 🙂

Happy Coding

]]>
/pdf-file-manipulation-library-using-spire-doc/feed/ 7
Spire.Doc -A boost for .NET Developers /spire-doc-a-boost-for-net-developers/ /spire-doc-a-boost-for-net-developers/#comments Fri, 18 Apr 2014 09:43:29 +0000 https://surajsahoo.wordpress.com/?p=43 Recently I got an opportunity from a China-Based Company E-Iceblue, to review one of their products. This for an instant bewildered me as I thought was I that eligible or it was my destiny!! Their product was Spire.doc.Spire.Doc for .NET is a professional Word .NET library specially designed for developers to create, read, write, convert and print Word document files from any .NET( C#, VB.NET, ASP.NET) platform with fast and high quality performance. It doesnot need Microsoft Word to be installed as it is an independent component(A Word.Net component)

I could not believe that we could  incorporate Microsoft Word document creation capabilities into any developers’ .NET applications. Strange right!!  It supports C#, VB.NET, ASP.NET and ASP.NET MVC. One important thing is it can convert the documents to the formats with High Quality.

 

How to Install Spire!!

Its easy and simple, not complex as trivial ones. The Spire.Doc installation is clean, professional and wrapped up in a MSI installer. The first few slides are mandatory informatory and license agreement as it is in most of the products we install right!! and none of us in individuals when we install read the EULA(End User License Agreement)but as an organization or company, it is required to completely go through it before investing.

Spire Doc. is a light weight product, it consumes only 180 MB for installation. Yes when as we download and install it creates chaos if our net speed is slow, but thats not the case in any organizations.

The MSI option provides a full experience, including:

  1. Installs the assemblies (multiple assemblies to support different versions of the .NET Framework)
  2. Installs the demo projects with source code
  3. Installs the documentation locally on the developer’s machine
  4. Adds the assembly to the Add Reference dialog box in Visual Studio

After the installation, the developer must manually add a reference to the assembly. Locally-installed documentation is available by means of Windows HTML Help, which is completely available and searchable while disconnected from the Internet.

 

Functionalities

Below are the list of functionalities provided by the Spire.Doc(I call it “Magic Doc“):-

  • Spire.Doc for .NET is a totally independent .NET Word class library which doesn’t require Microsoft Office installed on system. Microsoft Office Automation is proved to be unstable, slow and not scalable to produce MS Word documents. Spire.Doc for .NET is many times faster than Microsoft Word Automation and with much better stability and scalability.
  • By using Spire.Doc for .NET, users can save Word Doc/Docx to stream, save as web response and convert Word Doc/Docx to XML, RTF, EMF,TXT, XPS, EPUB,HTML and vice versa. Spire.Doc for .NET also supports to convert Word Doc/Docx to PDF and HTML to image.
  • A common use of Spire.Doc for .NET is to create Word document dynamically from scratch. Almost all Word document elements are supported. Mainly includes page,sections, headers, footers,footnotes,paragraphs, lists, tables, text, fields, hyperlinks, bookmarks, comments, images, background settings,printing features, document settings and protection. Furthermore, drawing objects including shapes, textboxes, images, OLE objects and controls are supported as well.
  • By using Spire.Doc, developers can build any type of a 32-bit or 64-bit .NET application including C#, VB.NET, ASP.NET, Web Services and WinForms for .NET Framework version from 2.0 to 4.5.
  • High performance for generating Word documents with huge pages. Superior performance support for reading and writing Word documents.

And Many More…This is what I explored in this span of time.

Lets Start

STEPS

  1. Lets go with a Console Application. Start a console application in Visual Studio 2012/13 and name your application SpireDemo. Name your app as SpireDemo.
  2. Then in the Solution Explorer , select the reference and add the assemblies related to SpireDoc. “Spire.Doc.dll“->Spire.Doc,Spire.License,Spire.pdf.
  3.  Now its time to Code:-

Spire.Doc.Document document = new Doc.Document(); //instance of the class

Section section = document.AddSection();//adds a section

Paragraph para =  section.AddParagraph();//adds a paragraph

para.AppendText("This is a magic Product");

document.SaveToFile("SpireDemo.docx",doc.FileFormat.Docx);//Saving the file in .doc format

 

We could save in any format as mentioned for instance

document.SaveToFile("SpireDemo.pdf",doc.FileFormat.pdf);//Saves the file in pdf format

 

All the File formats are present in an Enumeration FileFormat.cs

Now Question is Did that work?

Yes perfect !! Its working really nice. Playing and juggling with this product, I will explore many new things. Will keep on sharing.

Thank you.(E-Iceblue)

]]>
/spire-doc-a-boost-for-net-developers/feed/ 3