We have legacy applications built using VB6. These applications are using lead-tools. Everything was perfectly working. We have another .NET process that optimizes the image (and do some water-marking) and save it in tiff format. Here is glimpse of .NET code,
using (var bitmap = new Bitmap(contractWidth, contractHeight))
{
using (var canvas = Graphics.FromImage(bitmap))
{
canvas.InterpolationMode = InterpolationMode.Default;
// Play with canvas
canvas.Save();
}
using (var stream = new MemoryStream())
{
bitmap.Save(stream, ImageFormat.Tiff);
return stream.ToArray();
}
}
When we save this in tiff format (say image.tif). But when we open this file on our VB6 project, it shows a blue screen. I tried to compare the image which is working and image which is not working. Here are screens,
Working:
Not Working:
Update: This fixed my issue Convert TIFF to 1bit
I know you found a solution to the problem by converting the input image to 1-bit, but I wanted to elaborate more on the cause of the original problem, which is LEADTOOLS not opening the 32-bit file correctly in the first place.
You haven't specified which version of LEADTOOLS you're using, but since it's a legacy VB6 application, it's probably a rather old version (somewhere between v10 and v17; the current version is 20).
In any case, even older versions of the SDK should have no problem opening 32-bit TIFF files, but your application might be missing one or both of the following requirements:
Different sub-types of TIFF files require different LEADTOOLS DLLs. This is explained in the help topic Files to be Included with Your Application.
Older versions of the SDK required a special license to support LZW compression, back in the days when there was an active patent on LZW. If you're using one of these versions AND your application does not have that license, it won't support LZW tiff or gif files.
Please note that even owners of older SDK versions get free support. So if you are the owner of the original SDK, feel free to email any questions to support#leadtools.com, along with your LEADTOOLS product serial number.
Related
I'm try to create a simple WinForms viewer to show DICOM files generated in a NOVARAD PACS system. I'm using the following code from their GitHub page:
var image = new DicomImage(#"C:\myDicom.dcm");
image.RenderImage().AsClonedBitmap().Save(#"test.jpg");
Process.Start("test.jpg");
When I run this code I get the following error:
Dicom.Imaging.Codec.DicomCodecException: 'Decoding dataset with
transfer syntax: JPEG 2000 Image Compression (Lossless Only) is not
supported.'
I'm assuming I need to decompress from the JPEG 2000. Can this not be done with fo-dicom?
I was trying to play around with GDCM library but I couldn't find the C# wrapper, and noticed several comments saying they rolled it into fo-dicom.
Any suggestions?
In .NET Framework applications, the build architecture needs to be set to x86 or x64. Codec access on Any CPU architecture will not work, since there are no native codec libraries available for that architecture. For more information, see the fo-dicom wiki.
I get Out of Memory exception when using System.Drawing.Graphics.FromImage (using latest versions of .NET software on Windows 2012 server), ONLY on a very few specific image files. Most of the time the code works fine.
Typical answers to above issue indicate that certain resources are not being released.
Please consider the following before answering:-
This specific image is 34KB in size, is a .JPG image. Server is idle and has over 32GB RAM.
If I look at properties of
this jpg file, using windows explorer, by right-clicking on file, Windows says: 96 dpi and 32 bit depth.
BUT, if I open this jpg file using any graphics program (e.g. photoshop), the file properties show as: 72 dpi and 24 bit depth.
So, there is a mis-match between what I think file header properties
say and what the file actually contains.
Further, if I open the jpg
file using a graphics program and just re-save without changing
anything, the file properties in windows explorer now match/read correct
(72 dpi and 24 bit depth); and the file is processed by
System.Drawing.Graphics correctly, without throwing exception.
Due to my limited knowledge of the subject, I don't know if the file header of an image file can contain different data from actual file contents.
Questions:
How can I fix this problem? Or how can I tell System.Drawing.Graphics to ignore file header data and just look at actual image file contents? (as all graphics programs such as photoshop appear to do).
Thanks!
While I'm not a guru on the JPEG file format i did some research on the subject and here's what i found that could help you with your problem/questions.
Note that this answer will assume rather than specifically pinpoint the source of your problem due to the lack of an example file to inspect and tell what differs it from what the .Net/GDI+ JPEG/JFIF decoder expects.
The JPEG/JFIF format
Starting off, you might want to have some insight into the JPEG/JFIF format itself. After all, you have just encountered a file that .Net/GDI+ cannot load/parse. Since i don't have the file you experience issues with i would suggest you load it up in a hex editor of choice... that has the capability to highlight the file based on a template/code/parser.
I used 010 Editor and the JPEG Template from Sweetscape's online template repository.
010 Editor comes with a 30-day free trial.
What you are specifically looking for is the SOFn identifier and data in your bad JPEG.
In the SOFn data i can see that my image is Y (154) pixels high and X (640) pixels wide with a precision of 8 bits per component using 3 components, making it 24 bits per pixel.
The JPEG/JFIF format is a huge mix of many different implementations/formats. Obviously, you won't find every variant of the format in any library that has been around since long long ago before the odd JPEG formats appeared. Which the GDI+ library has.
In your case, i suspect you have run into the commonly asked about CMYK color profile on your JPEG files.
The .Net implementation
You said you used System.Drawing.Graphics.FromImage so i will assume your code looks like one of the following:
Graphics.FromImage(Image.FromFile("nope.jpg"));
Graphics.FromImage(Image.FromFile("nope.jpg", true));
Graphics.FromImage(Image.FromStream(nopeJpegStream));
From those calls, you may get an OutOfMemoryException when the native gdiplus.dll calls...
GdipGetImageGraphicsContext
GdipLoadImageFromFile
GdipLoadImageFromFileICM (or their respective *Stream variants) or
GdipImageForceValidation
... returns code 3 or 5 (Out of memory or Insufficient buffer respectively)
Which i gathered from referencesource.microsoft.com looking through the .Net sources there.
In any case, this most likely isn't an issue with .Net but an issue with GDI+ (gdiplus.dll) which Microsoft doesn't provide source code for. Which also means that there is no way of controlling how the image loads using the .Net wrappers and there's no way to check WHY it fails. (though i still suspect your JPEG is saved with CMYK)
Unfortunately, you are going to find many many more of these strange exceptions/errors as you move along in GDI+ land. As the library is all but deprecated in favor of the Windows Presentation Framework (WPF) and the Windows Imaging Component. (WIC)
My own testing
Since you never provided an image or any additional details on the subject i attempted to reproduce your issue. Which was a task in of itself, Image.FromFile (GdipLoadImageFromFile) will fail on many different file formats. At least it doesn't care what the file extension is, which thankfully Photoshop does.
So with your information, i finally managed to reproduce a .jpg file that loads fine in Photoshop, shows DPI as 96 and bit depth as 32. Of course, if i knew more about the JPEG format i probably could have gotten to the solution right away.
Showing this file (which i had to set to CMYK color space in Photoshop) in 010 Editor gave me the following SOFn data: Y (154) pixels high and X (640) pixels wide with a precision of 8 bits per component using 4 components, making it 32 bits per pixel.
I suspect you would see the same on your "bad" file.
And yes, Image.FromFile now throws an OutOfMemoryException!
Possible solutions
Use an external library for loading image files. (An exercise i leave to you but ImageMagick A.K.A Magick.NET seems like a good bet)
Make use of a command line tool (invoked when you get this exception) that can convert an image from one format to another. Or from JPEG to JPEG as it may be in this case. (Once again, ImageMagick's "convert" command line tool seems like a good bet)
Use the Windows Presentation Framework assemblies...
public static Image ImageFromFileWpf(string filename) {
/* Load the image into an encoder using the Presentation Framework.
* This is done by adding a frame (which in laymans terms is a layer) to a class derived BitmapEncoder.
* Only TIFF, Gif and JPEG XR supports multiple frames.
* Since we are going to convert our image to a GDI+ resource we won't support this as GDI+ doesn't (really) support it either.
* If you want/need support for layers/animated Gif files, create a similar method to this one that takes a BitmapFrame as an argument and then...
* 1. Instanciate the appropriate BitmapDecoder.
* 2. Iterate over the BitmapDecoders frames, feeding them to the new method.
* 3. Store the returned images in a collection of images.
*
* Finally, i opted to use a PngBitmapEncoder here which supports image transparency.
*/
var bitmapEncoder = new PngBitmapEncoder();
bitmapEncoder.Frames.Add(BitmapFrame.Create(new Uri(filename)));
// Use a memorystream as a handover from one file format to another.
using (var memoryStream = new MemoryStream()) {
bitmapEncoder.Save(memoryStream);
/* We MUST create a copy of our image from stream, MSDN specifically states that the stream must remain
* open throughout the lifetime of the image.
* We cannot instanciate the Image class, so we instanciate a Bitmap from our temporary image instead.
* Bitmaps are derived from Image anyways, so this is perfectly fine.
*/
var tempImage = Image.FromStream(memoryStream);
return new Bitmap(tempImage);
}
}
Based on this answer...
... Which i would say is a good option as it keeps you within the .Net framework.
Please keep in mind that when the method returns, you do specifically get a PNG image back. If you call Image.Save(string) on it you WILL save a PNG file, no matter what extension you save it as.
There is an overload Image.Save(string, ImageFormat) that will save the file using the intended file format. However, using that overload with ImageFormat.Jpeg will cause a loss in quality in the resulting file on more than one level.
That can be somewhat remedied by using the third overload:
foreach (var encoder in ImageCodecInfo.GetImageEncoders()) {
if (encoder.MimeType == "image/jpeg")
image.Save(filename, encoder, new EncoderParameters { Param = new [] { new EncoderParameter(Encoder.Quality, 100L) }});
}
Which, at least, will save a JPEG with "almost" no compression. GDI+ still doesn't do a good job at it.
However, no matter how much you twist and turn it. GDI+ will not be as good as a proper image library, which once again would most likely be ImageMagick. The further away you can get from GDI+, the better off you will be.
Conclusion / TL:DR and other notes.
Q: Can i load these files in .Net?
A: Yes, with a bit of fiddling and not using GDI+ for the initial loading of the file as GDI+ doesn't support the CMYK color space in JPEG files.
And even so, GDI+ lacks support for many things which is why i would recommend an external image library over GDI+.
Q: Mismatch in DPI and bit depth for file between Windows and <insert photo app here>
A: This is just proof that Windows JPEG loading differs from other applications JPEG loading routines. Only applications that use GDI or GDI+ would see the same information that Windows does when showing image details.
If you are using Windows 7+ then it isn't using GDI+ to show the information nor the image. It is using WPF or WIC to do so which are somewhat more up to date.
Q: If I open the jpg file using a graphics program and just re-save without changing anything, the file properties in windows explorer now match/read correct (72 dpi and 24 bit depth)
A: If you are using Adobe Photoshop and you use "Save for web" then the JPEG image will not be saved in CMYK format. Use "Save As..." instead and you will find that the color space (and bit depth) stays the same.
However, i wasn't able to reproduce your discrepancy in DPI and bit depth when loading my file in Photoshop. They are reported as the same in both Windows and Photoshop.
I had the same issue with this bug - seems as though the Graphics / Bitmap / Image library throws an exception with certain malformed images. Narrowing it down more than that, as Cadde shows, is difficult.
Following on from the great answer made by Cadde (which left using an external library as an exercise to the reader), I changed my code to the following using MagickNet which you can get here, or simply with NuGet: PM> Install-Package Magick.NET-Q16-x86.
The code tries to create a Graphics object from the image, and if it fails, uses ImageMagick to load the image again, convert to a Bitmap, and attempts to load from there.
Image bitmap = Bitmap.FromFile(filename, false);
Graphics graphics = null;
try
{
graphics = Graphics.FromImage(bitmap);
}
catch (OutOfMemoryException oome)
{
// Well, this looks like a buggy image.
// Try using alternate method
ImageMagick.MagickImage image = new ImageMagick.MagickImage(filename);
image.Resize(image.Width, image.Height);
image.Quality = 90;
image.CompressionMethod = ImageMagick.CompressionMethod.JPEG;
graphics = Graphics.FromImage(image.ToBitmap());
}
I had the same problem. My jpg file was generated from Photoshop. A simple solution is to open the jpg file with Winodws Paint, and save as a new jpg file. Import the new jpg file to C# project and the problem will be disappear.
It seems that .NET can't open JP2 (Jpeg 2000) files using the GDI library. I've searched on google but can't find any libraries or example code to do this.
Anybody got any ideas? I don't really want to pay for a library to do it unless I have to..
Seems like we can do it using FreeImage (which is free)
FIBITMAP dib = FreeImage.LoadEx("test.jp2");
//save the image out to disk
FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JPEG, dib, "test.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYNORMAL);
//or even turn it into a normal Bitmap for later use
Bitmap bitmap = FreeImage.GetBitmap(dib);
I was looking for something similar a while back, with a view to implementing one if I could; The responses to my question imply that there is no documented method to do this for GDI+ which the Image class in .Net uses.
I believe that if you're writing a WPF application, then you can extend the list of supported image formats through Windows Imanging Components codecs, and there may be one out there already (ask your local friendly search engine?)
There is an option to use an addon such as DotImage which supports JPEG2000, although there may be more "effort" involved in loading images.
For anyone coming across this old post, the above code from Gordon works great, but as jixtra pointed out, you will indeed get an exception: System.DllNotFoundException: 'Unable to load DLL 'FreeImage': The specified module could not be found.' when installing via nuget. I was able to get it working in .net 4.6.1 by installing the FreeImage-dotnet-core nuget package and manually adding the FreeImage.dll to the bin folder. You can download the dll here: http://freeimage.sourceforge.net/download.html.
I needed a better quality image to use with tesseract so I made a few minor changes which made a huge difference to the quality of the new jpeg:
var jp2Format = FREE_IMAGE_FORMAT.FIF_JP2;
var dib = FreeImage.LoadEx("test.jp2", ref jp2Format);
FreeImage.SetResolutionX(dib, 300);
FreeImage.SetResolutionY(dib, 300);
FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JPEG, dib, "test.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYSUPERB);
// NOTE: memory needs to be explicitly freed (GC won't do this)
FreeImage.UnloadEx(ref dib);
I've used Leadtools to display JPEG 2000 images. They provide a .NET library including WPF and WinForms controls to display the images. However, there is a reasonably steep price tag.
You can use Jpeg2000.Net library if you need a fully managed solution without unsafe blocks. Disclaimer: I am working on this library, the library is commercial.
Here is the basic sample for decoding of JPEG 2000 image to TIFF:
string fileName = ...; // path to JPEG 2000 image
using (var image = new J2kImage(fileName))
{
var options = new J2kDecodingOptions
{
UpsampleComponents = true
};
// Alternatively, you can decode only part of the image using J2kImage.DecodeArea method
var imageData = image.Decode(options);
imageData.Save(tiffFileName, J2kOutputFormat.Tiff);
}
Also, for a currently-up-to-date, open-source option you can use Emgu CV, which is a wrapper around OpenCV. Basic example code in C# looks like:
Mat image = CvInvoke.Imread(#"\Path\To\File.jp2");
I want to load and draw pdf files graphically using C#. I don't need to edit them or anything, just render them at a given zoom level.
The pdf libraries I have found seem to be focussed on generation. How do I do this?
Thanks.
Google has open sourced its excellent PDF rendering engine - PDFium - that it wrote with Foxit Software.
There is a C# nuget package called PdfiumViewer which gives a C# wrapper around PDFium and allows PDFs to be displayed and printed.
I have used it and was very impressed with the quality of the rendering.
PDFium works directly with streams so it doesn't require any data to be written to disk.
This is my example from a WinForms app
public void LoadPdf(byte[] pdfBytes)
{
var stream = new MemoryStream(pdfBytes);
LoadPdf(stream);
}
public void LoadPdf(Stream stream)
{
// Create PDF Document
var pdfDocument = PdfDocument.Load(stream);
// Load PDF Document into WinForms Control
pdfRenderer.Load(pdfDocument);
}
Edit: To get the pdfRenderer control in WinForm: Add the PdfiumViewer NuGet package to the project; open the projects packages folder in Windows Explorer and drag the PdfiumViewer.dll file onto the Toolbox window; A control called PdfRenderer will be available to add:
There are a few other choices in case the Adobe ActiveX isn't what you're looking for (since Acrobat must be present on the user machine and you can't ship it yourself).
For creating the PDF preview, first have a look at some other discussions on the subject on StackOverflow:
How can I take preview of documents?
Get a preview jpeg of a pdf on windows?
.NET open PDF in winform without external dependencies
PDF Previewing and viewing
In the last two I talk about a few things you can try:
You can get a commercial renderer (PDFViewForNet, PDFRasterizer.NET, ABCPDF, ActivePDF, XpdfRasterizer and others in the other answers...).
Most are fairly expensive though, especially if all you care about is making a simple preview/thumbnails.
In addition to Omar Shahine's code snippet, there is a CodeProject article that shows how to use the Adobe ActiveX, but it may be out of date, easily broken by new releases and its legality is murky (basically it's ok for internal use but you can't ship it and you can't use it on a server to produce images of PDF).
You could have a look at the source code for SumatraPDF, an OpenSource PDF viewer for windows.
There is also Poppler, a rendering engine that uses Xpdf as a rendering engine.
All of these are great but they will require a fair amount of commitment to make make them work and interface with .Net and they tend to be be distributed under the GPL.
You may want to consider using GhostScript as an interpreter because rendering pages is a fairly simple process.
The drawback is that you will need to either re-package it to install it with your app, or make it a pre-requisite (or at least a part of your install process).
It's not a big challenge, and it's certainly easier than having to massage the other rendering engines into cooperating with .Net.
I did a small project that you will find on the Developer Express forums as an attachment.
Be careful of the license requirements for GhostScript through.
If you can't leave with that then commercial software is probably your only choice.
Here is my answer from a different question.
First you need to reference the Adobe Reader ActiveX Control
Adobe Acrobat Browser Control Type Library 1.0
%programfiles&\Common Files\Adobe\Acrobat\ActiveX\AcroPDF.dll
Then you just drag it into your Windows Form from the Toolbox.
And use some code like this to initialize the ActiveX Control.
private void InitializeAdobe(string filePath)
{
try
{
this.axAcroPDF1.LoadFile(filePath);
this.axAcroPDF1.src = filePath;
this.axAcroPDF1.setShowToolbar(false);
this.axAcroPDF1.setView("FitH");
this.axAcroPDF1.setLayoutMode("SinglePage");
this.axAcroPDF1.Show();
}
catch (Exception ex)
{
throw;
}
}
Make sure when your Form closes that you dispose of the ActiveX Control
this.axAcroPDF1.Dispose();
this.axAcroPDF1 = null;
otherwise Acrobat might be left lying around.
PdfiumViewer is great, but relatively tightly coupled to System.Drawingand WinForms. For this reason I created my own wrapper around PDFium: PDFiumSharp
Pages can be rendered to a PDFiumBitmap which in turn can be saved to disk or exposed as a stream. This way any framework capable of loading an image in BMP format from a stream can use this library to display pdf pages.
For example in a WPF application you could use the following method to render a pdf page:
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using PDFiumSharp;
static class PdfRenderer
{
public static ImageSource RenderPage(string filename, int pageIndex, string password = null, bool withTransparency = true)
{
using (var doc = new PdfDocument(filename, password))
{
var page = doc.Pages[pageIndex];
using (var bitmap = new PDFiumBitmap((int)page.Width, (int)page.Height, withTransparency))
{
page.Render(bitmap);
return new BmpBitmapDecoder(bitmap.AsBmpStream(), BitmapCreateOptions.None, BitmapCacheOption.OnLoad).Frames.First();
}
}
}
}
ABCpdf will do this and many other things for you.
Not ony will it render your PDF to a variety of formats (eg JPEG, GIF, PNG, TIFF, JPEG 2000; vector EPS, SVG, Flash and PostScript) but it can also do so in a variety of color spaces (eg Gray, RGB, CMYK) and bit depths (eg 1, 8, 16 bits per component).
And that's just some of what it will do!
For more details see:
http://www.websupergoo.com/abcpdf-8.htm
Oh and you can get free licenses via the free license scheme.
There are EULA issues with using Acrobat to do PDF rendering. If you want to go down this route check the legalities very carefully first.
Use the web browser control. This requires Adobe reader to be installed but most likely you have it anyway. Set the UrL of the control to the file location.
You can add a NuGet package CefSharp.WinForms to your application and then add a ChromiumWebBroweser control to your form.
In the code you can write:
chromiumWebBrowser1.Load(filePath);
This is the easiest solution I have found, it is completely free and independent of the user's computer settings like it would be when using default WebBrowser control.
I would like to mention Docotic.Pdf library here. It can convert PDF to image in C# and VB.NET. And it can also render and print PDF documents.
The library is 100% managed without external dependencies. It does not depend on System.Drawing.dll or GDI+. You will get consistent output on Windows, Linux, macOS, iOS, and Android.
I am one of Docotic.Pdf developers, so I really like it. Please try it and you will probably like it, too.
You can also just return a byte[] of a pdf as a file. Here is an example of returning a rendered pdf in a C# web application from a local pdf file. Ideally the pdf would be stored as a byte[] in the database.
public async Task<ActionResult> ViewDocument(GetPdf pdfdata)
{
MemoryStream ms = new MemoryStream();
FileStream stream = new FileStream("Graph.pdf", FileMode.Open, FileAccess.Read);
stream.CopyTo(ms);
return File(ms.ToArray(), "application/pdf");
}
Dynamic PDF Viewer from ceTe software might do what you're looking for. I've used their generator software and was pretty happy with it.
http://www.dynamicpdf.com/
The easiest lib I have used is Paolo Gios's library. It's basically
Create GiosPDFDocument object
Create TextArea object
Add text, images, etc to TextArea object
Add TextArea object to PDFDocument object
Write to stream
This is a great tutorial to get you started.
This looks like the right thing: http://code.google.com/p/lib-pdf/
You could google for PDF viewer component, and come up with more than a few hits.
If you don't really need to embed them in your app, though - you can just require Acrobat Reader or FoxIt (or bundle it, if it meets their respective licensing terms) and shell out to it. It's not as cool, but it gets the job done for free.
We have an application in which admin members can add content for their subordinates to view. Their requirement is that it should be able to display Word, Excel, PowerPoint and PDF documents in a non-editable manner.
The one option that I found for doing this is to have the content loaded into a web browser component. The downside to that is that it prompts the user to open/save/cancel. We are concerned that the subordinates, being mostly computer illiterate, will have trouble opening the documents in this manner.
Using the above method also means that Microsoft Office and Adobe Acrobat (or another IE enabled PDF viewer) need to be installed on all the machines that will be running the application, which implies expensive licensing fees.
Is there a better way to get this content to display on my forms in C#?
Possibly interesting as well:
Save the documents to XPS using Microsoft Office 2007 (or print them to an XPS printer).
You can display the read-only XPS document either using the XPS viewer component or render page by page into a PNG or JPEG image. This rendering can be achieved quite easily using .NET 3.5 / WPF.
XpsDocument xpsDoc = new XpsDocument(xpsFileName, System.IO.FileAccess.Read);
FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence();
const double scaleFactor = 0.8;
for (int pageNum = 0; pageNum < docSeq.DocumentPaginator.PageCount; pageNum++)
{
DocumentPage docPage = docSeq.DocumentPaginator.GetPage(pageNum);
// FIX: calling GetPage without calling UpdateLayout causes a memory leak
((FixedPage)docPage.Visual).UpdateLayout();
RenderTargetBitmap renderTarget = new RenderTargetBitmap((int)Math.Round(scaleFactor * docPage.Size.Width),
(int)Math.Round(scaleFactor * docPage.Size.Height), (int)Math.Round(scaleFactor * 96), (int)Math.Round(scaleFactor * 96), PixelFormats.Default);
renderTarget.Render(docPage.Visual);
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.QualityLevel = 75;
// Choose type here ie: JpegBitmapEncoder, etc
//BitmapEncoder encoder = new PngBitmapEncoder(); // Choose type here ie: JpegBitmapEncoder, etc
encoder.Frames.Add(BitmapFrame.Create(renderTarget));
string pageImageFileName = string.Format("{0}-{1}.jpg", Path.Combine(Path.GetDirectoryName(xpsFileName), Path.GetFileNameWithoutExtension(xpsFileName)), pageNum);
using (FileStream pageOutStream = new FileStream(pageImageFileName, FileMode.Create, FileAccess.Write))
{
encoder.Save(pageOutStream);
}
}
This code needs references to the PresentationCore, PresentationFramework and ReachFramework assemblies.
EDIT: The code above contained a memory leak (see Opening XPS document in .Net causes a memory leak). The workaround has been been inserted in the example.
SpreadsheetGear for .NET has an Excel Compatible Windows Forms control which will display your Excel workbooks (it will do lot more than that if you want it to). You can see what people say and download the free trial if you want to give it a try.
SpreasheetGear can also create images from charts and ranges of cells if you need to generate images to display in a web page.
Have you looked at Microsoft Word 9.0 object library ? It might not be possible to just display the data as it was originally written, however, you COULD do something evul here, how about, printing as a temporary pdf in memory and displaying that?
This is how you display a PDF with C#
All this is windows specific.
If you wish to display something on a client machine without relying on any local install then you must take total responsibility for the rendering either by:
Supplying some sort of non invasive libraries that run at the client and know how to render it
Use the 'proper' tools/libraries to render it on the server to an in memory image and send that image to the client. Slow, very computationally expensive on your server and will not provide a 'document like' interface to your clients.
Sumatra is completely free and open source. It would not require any form of install, thus including it in your application install as a binary in a sub folder and then shelling out directly to that to display pdf's will work fine (either the pdf ids network accessible so it's as simple as executing
SumatraPDF.exe {path-to-file}
If it is not network accessible download it in the background to a temporary location and then execute as above.
Office documents are a bit more tricky since they all require a local install. Here's a (out of date) list Note that many of the links to downloads will then point you to the very latest version which is recommended.
An alternate approach for this is to use OpenOffice.org in it's 'portable' incarnation which will allow it to run without requiring an install (so you can drop it in place just like the Sumatra approach) this however has a great many flaws in your case because it would still require java to be installed, the resulting fiels would be editable (unless you made changes to the OpenOffice version which may well be complex) and you may not get terribly good display.
If you have any sort of ability to run arbitrary programs on install of your application installing the viewers is probably for the best, they are entirely free and redistributable.
If you have access to SharePoint you can try an entirely different approach which is to do it all via a web application. The sharepoint plugins will allow hosting views on the documents directly in the browser. Note that this pretty much requires Internet Explorer to be fully usable though.
Disclaimer, I'm from Atalasoft
If you want to display PDF in any kind of .NET GUI (Winforms, ASP.NET, Silverlight, WPF), our DotImage with PDF Reader add-on supports it. It doesn't use Adobe and doesn't require anything to be installed on the client-machine or server (just our assemblies).