0% found this document useful (0 votes)
18 views2 pages

21 Posts Link: Garyzh

The document discusses various ways to convert image files to different file formats like Word, PDF, and Excel using .NET components. It provides code samples to convert an image to a Word document by inserting the image into a paragraph and setting its size. It also shows how to convert an image to a PDF by drawing the image onto a PDF page and resizing it. Finally, it demonstrates converting an image to an Excel file by adding the image to a worksheet. The response notes that images cannot be converted to plain text Notepad files.

Uploaded by

Abcxyz Xyzabc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

21 Posts Link: Garyzh

The document discusses various ways to convert image files to different file formats like Word, PDF, and Excel using .NET components. It provides code samples to convert an image to a Word document by inserting the image into a paragraph and setting its size. It also shows how to convert an image to a PDF by drawing the image onto a PDF page and resizing it. Finally, it demonstrates converting an image to an Excel file by adding the image to a worksheet. The response notes that images cannot be converted to plain text Notepad files.

Uploaded by

Abcxyz Xyzabc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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