Forums

Overview » C# » How to Use C# Convert Image to PDF
Reply

How to Use C# Convert Image to PDF

Wallace Stephen
Member



Since: 23 Nov 2010
Posts: 63
Posted 13 Jun 2011 09:07:08

Why Convert Image to PDF?

Since 1993 PDF format had been introduced by Adobe Systems it has rapidly become the number one universal document format on the internet.

1. Compatible Across platforms
2. Compact & Small
3. Can be created from any source document/application
4. Securable, avoid people from modifying & redistributing your work
6. Easy and quick to create when using the right software
7. Software to view PDF Files is completely free
8. Viewable within most web-browsers
9. PDF Files meet legal document requirements.
10. Compatible with modern portable reader systems

With the Top 10 advantages of PDF, you should be clear that why we convert files from image to PDF.

How to Use C# Convert Image to PDF?

In this article, I will introduce you a solution of how to use C# fast converting files from image to PDF. First, please allow me to introduce you a .NET component, Spire.Doc for .NET, which is available to use C# convert files from all images to PDF. Download Spire.Doc for .NET and install on your system. With the code below, you will soon learn how to use your C# to convert image to PDF.

Convert Image to PDF with C#
[C#]
using System;
using Spire.Pdf;
using Spire.Pdf.Graphics;

namespace ConsoleTest
{
class Program
{
static void Main(string[] args)
{
PdfDocument doc = new PdfDocument();
PdfSection section = doc.Sections.Add();
PdfPageBase page = doc.Pages.Add();
PdfImage image = PdfImage.FromFile("test.png";

float widthFitRate = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
float fitRate = Math.Max(widthFitRate, heightFitRate);
float fitWidth = image.PhysicalDimension.Width / fitRate;
float fitHeight = image.PhysicalDimension.Height / fitRate;

page.Canvas.DrawImage(image, 0, 0, fitWidth, fitHeight);
doc.SaveToFile("test.pdf";
doc.Close();
}
}
}

Related Articles:
How to Use C# Convert HTML to PDF
How to Use C# Convert Doc to PDF
How to Use C# Convert Text to PDF
How to Use C# Convert XML to PDF

Why Convert Image to PDF?

Since 1993 PDF format had been introduced by Adobe Systems it has rapidly become the number one universal document format on the internet.

1. Compatible Across platforms
2. Compact & Small
3. Can be created from any source document/application
4. Securable, avoid people from modifying & redistributing your work
6. Easy and quick to create when using the right software
7. Software to view PDF Files is completely free
8. Viewable within most web-browsers
9. PDF Files meet legal document requirements.
10. Compatible with modern portable reader systems

With the Top 10 advantages of PDF, you should be clear that why we convert files from image to PDF.

How to Use C# Convert Image to PDF?

In this article, I will introduce you a solution of how to use C# fast converting files from image to PDF. First, please allow me to introduce you a .NET component, Spire.Doc for .NET, which is available to use C# convert files from all images to PDF. Download Spire.Doc for .NET and install on your system. With the code below, you will soon learn how to use your C# to convert image to PDF.

Convert Image to PDF with C#
[C#]
using System;
using Spire.Pdf;
using Spire.Pdf.Graphics;

namespace ConsoleTest
{
class Program
{
static void Main(string[] args)
{
PdfDocument doc = new PdfDocument();
PdfSection section = doc.Sections.Add();
PdfPageBase page = doc.Pages.Add();
PdfImage image = PdfImage.FromFile("test.png";

float widthFitRate = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
float fitRate = Math.Max(widthFitRate, heightFitRate);
float fitWidth = image.PhysicalDimension.Width / fitRate;
float fitHeight = image.PhysicalDimension.Height / fitRate;

page.Canvas.DrawImage(image, 0, 0, fitWidth, fitHeight);
doc.SaveToFile("test.pdf";
doc.Close();
}
}
}

Related Articles:
How to Use C# Convert HTML to PDF
How to Use C# Convert Doc to PDF
How to Use C# Convert Text to PDF
How to Use C# Convert XML to PDF

Magnet Peterson
Newbie



Since: 02 Nov 2011
Posts: 4
Replied 17 Nov 2011 11:22:52
Another way for this:
Also you may use this .Net library PDF Vision for the converting from images to PDF.
Combining high quality and low cost of converting the system's memory, this component also brought me the ability to convert from Web pages to PDF
This code may be useful:


			SautinSoft.PdfVision v = new SautinSoft.PdfVision();
			v.ImageStyle.Quality=80;

			//Create array containing paths to different image files
			string[] arImages = new string[4];
			arImages[0] = @"c:\image1.jpg";
			arImages[1] = @"c:\image2.png";
			arImages[2] = @"c:\image3.gif";
			arImages[3] = @"c:\image4.jpg";

			//Convert array of images files into PDF file
			int ret = v.ConvertImageFileArrayToPDFFile(arImages, @"c:\Single.pdf");

			if(ret==0 )
			{
				//Show produced PDF in Adobe Acrobat
				System.Diagnostics.Process.Start(@"c:\Single.pdf");
			}



Edited by - Magnet Peterson on 18 Nov 2011  09:03:07


Edited by - Magnet Peterson on 08 Dec 2011  13:41:30
caroline forbes
Newbie



Since: 11 Apr 2013
Posts: 1
Replied 11 Apr 2013 06:57:20
i also want to share my experience in the image to PDF convert. it is pretty fast and accurate.
arron lee
Newbie



Since: 22 Apr 2013
Posts: 4
Replied 22 Apr 2013 06:24:10
what you said is very useful to me
thx a lot.
and you can also read this information How to convert PDF to Word?


there are also same great tools for us to choose from.
here is Yiigo.Image
i found it by google. it is very convenient.
danny rough
Newbie



Since: 18 Apr 2013
Posts: 4
Replied 02 May 2013 04:18:28
to convert image to pdf, an imaging converter should be employed. i am using this image converter which can be applied in C#, i suggest you to have a try. good luck!

Reply to this topic

Message
Reply
Follow us on twitter Subscribe to our RSS feed
Activate your free membership today | Login | Currency