Export pictures in Microsoft Word to TIFF - c#

How to export pictures in Microsoft Word to TIFF file using Visual Studio Tools for Office? I can obtain a reference to the pictures as InlineShape object collection, the hard part now is how to save them as TIFF images.

OK guys, I got the problem solved. Here's the code snippet:
private void SaveToImage(Word.InlineShape picShape, string filePath)
{
picShape.Select();
theApp.Selection.CopyAsPicture();
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(typeof(Bitmap)))
{
Bitmap image = (Bitmap)data.GetData(typeof(Bitmap));
image.Save(filePath);
}
}
Hope it helps :)

Well. not sure if this is helpful, but you if you are okay with jpegs, then one really cool technique for extracting images from Word 2007 file is as follows:
Rename the .docx file to .zip.
Under the (now) zip file, go to the following path: word/media.
All the images in the document are found here as jpeg files.
Cheers.

Related

How extract image from DOC file without using of Microsoft.Office.Interop.Word

I'm trying to extract image from *.doc file without using of Microsoft.Office.Interop.Word. I found library like FreeSpire.Doc, but It seems the free version of library isn't able to extract images. Can someone help me with this problem?
[Attached *.doc file with the image I need][1]
[1]: https://mega.nz/#!5nITyQzT!aesEA0akirlpKSEEDceNDjifOAFKlNZSmgTwfhFm36M
Thank you
The only library i found which can extract Images from .doc Document is Aspose. There is an example in their documentation how you can Export Images.
I ended up with this solution. I found a library named GemBox.Document. Unluckily this library is free only for documents containing up to 20 paragraphs. So I had to remove extra paragraphs and then I used this code to get first picture in document.
public void CreateSubnestImageFromNestingReport(string picturePath,string docPath)
{
var fileDir = Path.GetDirectoryName(picturePath);
Directory.CreateDirectory(fileDir);
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
var document = DocumentModel.Load(docPath, LoadOptions.DocDefault);
var pict = document.GetChildElements(true).Single(el => el.ElementType == ElementType.Picture) as Picture;
File.WriteAllBytes(picturePath, pict.PictureStream.ToArray());
}

iText GetTextFromPage exception with inline image

I have the same problem as was discussed here, which was not solved. My objective is to extract the text from an existing pdf file. I get the error message Could not find image data or EI for a certain pdf, which I cannot share as a sample. It works for other pdfs, with the following code
string fileURI = "C:\\Test\\Sample.pdf";
PdfReader reader = new PdfReader(fileURI);
ITextExtractionStrategy strategy = new LocationTextExtractionStrategy();
string s = PdfTextExtractor.GetTextFromPage(reader, 1, strategy);
Debug.WriteLine(s);
I am using iTextSharp 5.5.0 and tried changing found == 1 to found <= 1 as suggested in other posts. It does not help.
Would it help to remove all images in the pdf? I really just need the text. Which commands from iText could help me with this?
I downloaded the trial version of Acrobat to create a version of the pdf file, that I could share. After opening the file and saving it again as "Optimized PDF" over the Acrobat, the code was working and I could extract the text.
So the solution to the problem is probably opening each file in Acrobat and saving it again with the right settings using the Acrobat reference and then extracting the text.

Document to .jpg converter

We're looking for an all around document converter to create small thumbnails for previewing in our asp.net project. So far we've encountered a handfull of difficult to use/document commandline tools that can convert one filetype to jpg, but we're looking for an all around solution. ( xls, doc, pdf to jpg ). Does anybody know any solutions for this problem with a pricetag that doesn't exceed 700- 1500 $?
Its just an Idea About Creating Thumbnails.
You will have to use image.GetThumbnailImage() method.
It works as follows:
Image img = Image.FromFile(fName);
Image thumb = img.GetThumbnailImage(120, 120, ()=>false, IntPtr.Zero);
thumb.Save(Path.ChangeExtension(fName, "thumb"));
MSDN:
http://msdn.microsoft.com/en-us/library/system.drawing.image.getthumbnailimage.aspx
Hope Its Helpful.

How may I get the image of DataVisualization.Charting.Chart to iTextSharp.text.Image without writing to a file?

I'm writing a piece of software for visualization of measurement data. For this I use System.Windows.Forms.DataVisualization.Charting.Chart and I do know that I can get the shown image by chartObj.SaveImage to store it to a file.
My software shall have a PDF export in which the picture should be included. For this, I'm using iTextSharp. Again, I do know how to put a picture which I have stored in a file into the PDF by iTextSharp.text.Image.GetInstance.
So by now I am able to take the picture of the chart, put it to a file (e.g. a .jpg file) and load this file again to put it in my PDF. Now I'm looking for a nice solution to get the picture into the PDF without storing it into a file, maybe through a Stream or something like that. I've tried quite some time, but until now I didn't succeed. I've thought of something like
Stream imageStream = image of chartObj;
iTextSharp.text.Image picture = iTextSharp.text.Image.GetInstance(imageStream);
As far as I understand, I fail in putting the picture from the chartObj into a Stream instead of a file. If I had this, I guess I could load the Stream via iTextSharp.text.Image.GetInstance.
Has anyone some help you could offer? Guess it's not that difficult, but I'm new to C# and also to iText, so I'm just a bit stucked here.
Thanks in advance for every thought you have about this!
Anna
SaveImage to a MemoryStream:
using (var chartimage = new MemoryStream())
{
chart.SaveImage(chartimage, ChartImageFormat.Png);
return chartimage.GetBuffer();
}
From:
Microsoft Chart Controls to PDF with iTextSharp and ASP.NET MVC

C# import of Adobe Illustrator (.AI) files render to Bitmap?

Anyone knows how to load a .AI file (Adobe Illustrator) and then rasterize/render the vectors into a Bitmap so I could generate eg. a JPG or PNG from it?
I would like to produce thumbnails + render the big version with transparent background in PNG if possible.
Ofcause its "possible" if you know the specs of the .AI, but has anyone any knowledge or code to share for a start? or perhaps just a link to some components?
C# .NET please :o)
Code is most interesting as I know nothing about reading vector points and drawing splines.
Well, if Gregory is right that ai files are pdf-compatible, and you are okay with using GPL code, there is a project called GhostscriptSharp on github that is a .NET interface to the Ghostscript engine that can render PDF.
With the newer AI versions, you should be able to convert from PDF to image. There are plenty of libraries that do this that are cheap, so I would choose buy over build on this one. If you need to convert the older AI files, all bets are off. I am not sure what format they were in.
private void btnGetAIThumb_Click(object sender, EventArgs e)
{
Illustrator.Application app = new Illustrator.Application();
Illustrator.Document doc = app.Open(#"F:/AI_Prog/2009Calendar.ai", Illustrator.AiDocumentColorSpace.aiDocumentRGBColor, null);
doc.Export(#"F:/AI_Prog/2009Calendar.png",Illustrator.AiExportType.aiPNG24, null);
doc.Close(Illustrator.AiSaveOptions.aiDoNotSaveChanges);
doc = null; //
}
Illustrator.AiExportType.aiPNG24 can be set as JPEG,GIF,Flash,SVG and Photoshop format.
I Have Tested that with Pdf2Png and it worked fine with both .PDF and .ai files.
But I don't know how it will work with transparents.
string pdf_filename = #"C:\test.ai";
//string pdf_filename = #"C:\test.pdf";
string png_filename = "converted.png";
List<string> errors = cs_pdf_to_image.Pdf2Image.Convert(pdf_filename, png_filename);

Categories