Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Fkldjf s[q]sdl

Jjjjjjj nnnnnndfdd dfmdfioe

Garyzh
Member
94 Points
21 Posts

Re: How to convert image files data into word or notepad or pdf or excel
Jul 10, 2013 07:37 AM|LINK

convert image to pdf by the code as below:


PdfDocument doc = new PdfDocument();
PdfSection section = doc.Sections.Add();
PdfPageBase page = doc.Pages.Add();
//Load a tiff image from system
PdfImage image = PdfImage.FromFile(@"D:\images\bear.tif");
//Set image display location and size in PDF
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, 30, 30, fitWidth, fitHeight);
//save and launch the file
doc.SaveToFile("image to pdf.pdf");
doc.Close();
In realizing the above code, I use a .NET PDFcomponent, it can convert image to PDF file without any third party library. In the downloaded Bin folder, there is
a pdf dll, you can add it without downloading other PDF library.
Hope it can help you!

Reply

Koohji
Member
88 Points
27 Posts

Re: How to convert image files data into word or notepad or pdf or excel
Jul 10, 2013 08:57 AM|LINK

I provide you some solutions below.


Converting image files to doc/docx file.
//Create Document
Document document = new Document();
Section s = document.AddSection();
Paragraph p = s.AddParagraph();
//Insert Image and Set Its Size
DocPicture Pic = p.AppendPicture(Image.FromFile(@"E:\Work\Documents\SampleImage\Sample.jpg"));
Pic.Width = 750;
Pic.Height = 468;
//Save and Launch
document.SaveToFile("Image.docx", FileFormat.Docx);
Converting image files to pdf file.
//Create a pdf document.

PdfDocument doc = new PdfDocument();


// Create one page
PdfPageBase page = doc.Pages.Add();
//Draw the image
PdfImage image = PdfImage.FromFile(@"..\..\Sample.jpg");
float width = image.Width * 0.75f;
float height = image.Height * 0.75f;
float x = (page.Canvas.ClientSize.Width - width) / 2;
doc.SaveToFile("Sample.pdf");
Converting image files to excel files.
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
sheet.Pictures.Add(1,1,@"D:\Data\day.jpg");
workbook.SaveToFile("sample.xls");
In realizing the above code, I use a .NET component.

notepad only supports plain text, so image files not are converted to notepad.
Hope the solutions above can help you!

You might also like