Displaying Postscript text and Vector images on PDF in C#.net using Imageglue - Blogs

Displaying Postscript text and Vector images on PDF in C#.net using Imageglue

Postscript is a language used for creating vector Images,Vector images are made up of many scalable objects  and they are  defined  by mathematical equations rather than the pixels ,so they always renders higher quality images.

The Advantages of Vector Images over Bitmap images

1.Vector images are resolution independent, how much ever we resize the image the quality remains the same.



2.Vector Images images does not contains rectangular background as the bitmap images.





Conversion of vector images to bitmap image is referred as Rasterization.

 When you convert a vector image to a bitmap, you can specify the output resolution of the final bitmap for whatever size you need. It's always important to save a copy of your original vector image in its native format (EPS, SVG) before converting it to a bitmap; once it has been converted to a bitmap, the image loses all the wonderful qualities it had in its vector state. If you convert a vector to a bitmap at a size of 100 by 100 pixels and then decide you need the image to be larger, you'll need to go back to the original vector file and export the image again. Also keep in mind that opening a vector image in a bitmap editing program usually destroys the vector qualities of the image and converts it to raster data.

The most common reason for wanting to convert a vector to a bitmap would be for use on the Web.

Drawing text using postscript

      MyScript = "/" + Font name of text + " findfont " + Font size of text in double+ " scalefont setfont " + red + " " + green + " " + blue + " setrgbcolor " + x Position of text in double + " " + y Position of text in double + " translate " + Angle of rotation in integer+ " rotate " + x Scale factor in double+ " " + y Scale factor in double+ " scale newpath 0 0 moveto (" + Text to be drawn + ") show "

Drawing a line using postscript

MyScript = "" + Thickness of underline in Double + " setlinewidth " + red + " " + green + " " + blue + " setrgbcolor " + Starting X position + " " + Starting Y position + " " + " moveto " + Final X position + " " + Final Y position + " lineto stroke  show";

Displaying postscript text and Vector images on pdf using C#.net.

The .Net framework does not support the drawing of Vector graphics or displaying of vector graphics. To overcome by this we have used a third party control by name IMAGEGLUE (www.websupergoo.com/imageglue-1.htm).

Steps to draw text and vector images on pdf using Imageglue and c#.net

1. Create a pdf file and save it in a temporary folder as below.

string strFileName = "VectorImage.pdf";

string path = Server.MapPath(".") + "\\PDFFiles\\"; //saves temporary to this folder

2.Create a object of the class Canvas of the Imageglue .

This Canvas object provides a space for drawing and painting, It has various properties such as size and color and methods for drawing a variety of objects.

Pass the Width,Height  and color of the canvas as the parameter  as below.

Canvas canvas = new Canvas(intdivdropWidth, intdivdropHeight, new XColor(objCommonFunctions.GetColorforHEXCode(“#FFFFFF”)));

3.Draw the text on canvas as below

String MyScript;

MyScript = "/" + Fontname of text + " findfont " + Fontsize of text in double+ " scalefont setfont " + red + " " + green + " " + blue + " setrgbcolor " + x Position of text in double + " " + y Position of text in double + " translate " + Angle of rotation in integer+ " rotate " + x Scalefactor in double+ " " + y Scalefactor in double+ " scale newpath 0 0 moveto (" + Text to be drawn + ") show ";

canvas.DrawPostscript(MyScript, new DrawOptions());

4. Draw the Image on canvas as below

String FileName = Server.UrlDecode(FileName);//Fetch the raster or vector image(EPS,SVG)

String  strWidth = “20”; //Width of the Image

String  strHeight = “20”; //Height of the Image

Int   intX=50; //X position  of the Image

Int   intY=50; //Y position  of the Image

WebSupergoo.ImageGlue7.XImage  image = null;

WebSupergoo.ImageGlue7.DrawOptions drawOpts = new DrawOptions(canvas);

drawOpts.ImageFit = DrawOptions.ImageFitType.Stretch;

drawOpts.Transparency = true;

image = XImage.FromFile(FileName);

drawOpts.Transform.Translate(double.Parse(intX.ToString()), double.Parse(intY.ToString()));

canvas.DrawImage(image, double.Parse(strWidth), double.Parse(strHeight), drawOpts);

image.Dispose(); //Releasing the resources

5.Saving  the Canvas as PDF

XExport objexport = new XExport();

 objexport.Pdf.CropBox = new XRect(intdivdropWidth, intdivdropHeight);

canvas.SaveAs(Server.MapPath("~/PDFFiles/" + strFileName), objexport);

The below image shows the output, you can observe the quality of the vector image of tiger and the raster image of the tiger but the quality of the raster image(left side) is poor compare to vector image(right side). If you draw text using DrawPostscript method of Imageglue the quality of the text is good compare to drawing the text by using DrawText method of Imageglue.




What are Frames? How to handle frames in Selenium WebDriver with C#?

IFrame (FullForm: Inline Frame) is an HTML document that is included in another HTML document and is...

Read More >

What is Synchronization? Handling Synchronization in Selenium WebDriver using C#:

Synchronization meaning: when two or more components involved to perform any action, we expect these...

Read More >

Sending Test reports by Email using Office 365, Gmail

Wouldn’t it be great if Test Report are sent automatically across team as soon the Test Execut...

Read More >

ASP.NET: Audit Trail Implementation using Entity Framework

When you are working with certain projects which involves the Customer records, you might need to tr...

Read More >

Create Restful service using Web API

What is Asp.Net Web API?Asp.Net Web API is a framework for building HTTP services that can be consum...

Read More >

Create custom project templates in Visual Studio

Visual studio installation comes with the various predefined project templates, and we can use one o...

Read More >

WCF SOAP and REST Services

WCF (Windows Communication Foundation) is a programming platform and runtime system for building, co...

Read More >

What's New In C# 6.0?

Microsoft has released the preview version of Visual Studio 2015 and .NET 4.6 for developers to try ...

Read More >

How to Customize the Microsoft Dynamics NAV 2013 R2 Splash screen Image

I think I got late with this post, but I was unaware that most of us still don’t know how to c...

Read More >

Creating an RDLC report in Asp.Net

Step 1.  Create a new website and Add DataSet to the WebsiteRight Click on the project, Add new...

Read More >


Try DevOpSmartBoard Ultimate complete Azure DevOps End-to end reporting tool

Sign Up

  • Recent
  • Popular
  • Tag
Monthly Archive

Contact Us
  • *
  • *