Convert Group 3 compressed TIFF to png or pdf in .net [closed]
开发者_JS百科
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this questionI search a way to convert a Group 3 compressed TIFF to png or for best in pdf with c#.net.
Try LibTiff.Net library for this.
The library comes with tiff2pdf utility (you would need to build it yourselves) that probably does exactly what you need. You may even incorporate the code of the utility in your application.
The library and utility are free and open-source. License (New BSD License) allows any modifications. You can use the library and utility in commercial applications.
Disclaimer: I am one of the maintainers of the library.
TIFF to PNG:
System.Drawing.Image will allow you to open a Group3 TIFF and save it as PNG simply by loading the TIFF as a normal image (e.g. Image.FromFile, Image.FromStream, etc.) and then saving it using the Image.Save method with the ImageFormat.Png argument. As TIFFs vary widely, on occasion I have encountered an obscure TIFF that System.Drawing won't open, but that is unusual. If it happens, you'll need to seek out a third party library from opensource (e.g. iText has a sophisticated image library) or there are commercial options such as Lead Tools or Atalasoft.
TIFF to PDF:
iTextSharp is a great library for doing this. I even found some articles on this specific topic with a google search. This one seems to be a good one to start with for your needs.
(disclaimer - I work for Atalasoft) If you use dotImage for this, both conversions are trivial.
for tiff to pdf:
using (outputStream = new FileStream(pathToPdf, FileMode.Create)) {
PdfEncoder encoder = new PdfEncoder();
encoder.Save(outputStream, new FileSystemImageSource(pathToTiff, true), null); // true = do all pages
}
for tiff to png:
FileSystemImageSource source = new FileSystemImageSource(pathToTiff, true);
int page = 0;
while (source.HasMoreImages()) {
AtalaImage image = source[page];
using (FileStream stm = new FileStream("output_page_" + page + ".png", FileMode.Create)) {
PngEncoder encoder = new PngEncoder();
encoder.Save(stm, image, null);
}
source.Release(image);
}
Use ghostscript, i used to extract images from a PDF and create thumbnails, the lib also convert from images to PDF and it's open source.
A guy create a wrapper for the ghostscript API: http://www.mattephraim.com/blog/2009/01/06/a-simple-c-wrapper-for-ghostscript/
精彩评论