save a file in memory instead of a physical path - c#

I am trying to use Office Interop assembly to export a PowerPoint slide to an image. The SaveAs(), SaveCopyAs(), and Export() methods all accept a physical path as the output folder.
I want to put it in memory for further processing instead of creating a bunch of images on disks that I have to clear them later.
How can I export a slide and hold it in the memory temporarily instead of saving it in a physical folder?

Calling the Slide's .Copy method will put the slide on the clipboard in a number of formats, including PNG, GIF, JPG, DIB, BMP and metafile/enhanced metafile.
It should be possible to access the format you want from there.

There is no way of writing an Office Apps files straight to memory. You can look at Open XML SDK for Office, but i think, it will be easier if you just save the image to a file and load it through memorystream.

Related

Access Tools in Save Menu with C#

I use C# to turn ppt files into jpg images but I also want the program to resave the same ppt with compressed pictures and cropped pictures, I want to use settings in Tools menu when saving a file. How can I access them with Microsoft.Office.Interop.PowerPoint?
Sorry, I should clarify. I want to re-save the same ppt but with those settings of compression and cropping. Basically, I want to resave the ppt file and then break it into images. I need a ppt with compressed images in order to save space on the pc.
Right now I use this to save JPGs.
file.SaveCopyAs(outputPath + "CONVERTED.jpg", PowerPoint.PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoTrue);
I may have an answer for you:
In the PPTX file's PPT folder, you'll find a presProps.xml file.
In it, you'll find something like this:
<p:extLst>
<p:ext uri="{E76CE94A-603C-4142-B9EB-6D1370010A27}">
<p14:discardImageEditData xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="0"/>
</p:ext>
<p:ext uri="{D31A062A-798A-4329-ABDD-BBA856620510}">
<p14:defaultImageDpi xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="96"/>
</p:ext>
<p:ext uri="{FD5EFAAD-0ECE-453E-9831-46B23BE46B34}">
<p15:chartTrackingRefBased xmlns:p15="http://schemas.microsoft.com/office/powerpoint/2012/main" val="1"/>
</p:ext>
</p:extLst>
From this, it appears that you could save a copy of the PPTX, change defaultImageDPI and possibly discardImageEditData in the XML, re-open and resave the PPTX from PPT.
It doesn't seem to allow values below 96dpi; set it lower and it reverts to 96 when you open the file in PPT.

Prevent PDFsharp from saving an image file?

I have prevented my program from saving images downloaded as files. (They are saved in Image variables instead). However, my application is slowed down significantly because the PDFsharp libraries save the image files anyway before drawing them to the PDF document. This is done deep within a hierarchy of calls by its functions.
Is there a simple fix to get around this?
JPEG images are simply copied into the PDF file, all other image formats have to be converted to the PDF format. AFAIK PDFsharp does not save the images to the local file system, however they are saved into a memory stream during the conversion.
There is a simple fix to get around this: write a better conversion and submit it to the PDFsharp team.
I think PDFSharp always need to save first. It cannot handle byte image that will used to import an image. I recently encountered it when I also coded and used pdfsharp. My process is to save an image then import to code in pdfsharp. I have a part that I need to delete all temporary images.

Embed image in file

I'm trying to figure out a way to embed an image into a file in c#.
What I'm doing is to create a file with text inside of it (it uses XML) , and I want a quite big image embedded into it which I then can read from the file along with the XML.
But how do I do that?
I can't put an image file along with the file since the file may be used on different computers and I don't want 100's of image files laying around with the files.
Any ideas would be appreciated!

How to programmatically determine if an image file is georeferenced

I have a task to programamatically scan a folder for georeferenced images. There might be a lot of images, some quite large, and some not georeferenced. The spatial information can also be either embedded or in a world file.
How can I tell programmatically (C#/WPF/ESRI Runtime) if "C:\someFolder\file.x" is georeferenced?
Thanks
First check the file type to see if it's a format that supports built in georeferencing (GeoTiff, jp2, and MrSid). Other static image files would need some sort of companion file with the georeferencing information. So for each image file you'd want to look for a matching companion file.
If you add some info on what formats the images/world files are in it'll be easier to show you some sample code.

Creating print previews of documents

I need to create a software which will create print previews of the documents of following formats: the MS Office documents (.doc(x), .ppt(x), .xls(x)), images, .txt files and PDF files. I have made a working prototype using XPS files. So basically I do the following: I convert the office files to .xps using Office Automation and then I render the .xps documents to images. I simply create XPS files from images and .txt by adding text or an image to FlowDocument, then rendering it. But I have found out that there is no way to convert PDF to XPS fast (A document which has 600 pages takes more than 2 minutes to convert and this is totally not suitable). So I am stuck at this point. It seems that I should start over again, using the different file format. Should I rewrite my program using PDF, for example, or is there any other way to accomplish my task? And if I should use PDF, could you, please, suggest me a good PDF C# library to render previews of pages as fast as possible? I tried using Websupergoo's ABCPdf, but it is too slow, because it does not allow me to render the previews to System.Windows.Media.Imaging.BitmapSource, only System.Drawing.Bitmap, so I have to convert Bitmap to BitmapSource and it takes up a lot of time.
Thanks in advance.
Use Ghostscipt to convert PDF to images. Though, I don't know why you wouldn't just use the PDF. I have used GhostScript for a number of PDF/Image manipulation tasks.
http://www.wibit.net/blog/integrating_ghostscript_c
Ghostscript will output any PDF to images to the settings you specify. I think you can use it as a DLL or as a commandline process.

Categories

Resources