473,898 Members | 3,853 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using iText to convert Tiff to PDF

Hi all !

I have a multi-page Tiff image file that I want to convert to PDF. To do so
I am using iText library. The conversion is working, but the code execution
is very different according to wich
iTextSharp.text .Image.getInsta nce(...) signature I am using :
- using code 1 below, the conversion is fast enough but the resulting PDF
file is too big (1 817ko sample Tiff file is converted in less than 30
seconds to a 2 764ko PDF file)
- using code 2 below, resulting PDF size is good but the conversion is too
slow (1 817ko sample Tiff file is converted in about 10 minutes to a 1 780ko
PDF file)

code 1:
Document document = new Document(PageSi ze.A4, 50, 50, 50, 50);
PdfWriter writer = PdfWriter.getIn stance(document , new
System.IO.FileS tream(pdfFileNa me, System.IO.FileM ode.Create,
System.IO.FileA ccess.Write));
System.Drawing. Bitmap bitmap = new System.Drawing. Bitmap(tiffFile Name);
numberOfPages =
bitmap.GetFrame Count(System.Dr awing.Imaging.F rameDimension.P age);
document.Open() ;
PdfContentByte cb = writer.DirectCo ntent;
for(int page = 0; page < numberOfPages; page++)
{
bitmap.SelectAc tiveFrame(Syste m.Drawing.Imagi ng.FrameDimensi on.Page,
page);
System.IO.Memor yStream stream = new System.IO.Memor yStream();
bitmap.Save(str eam, System.Drawing. Imaging.ImageFo rmat.Png)
iTextSharp.text .Image img =
iTextSharp.text .Image.getInsta nce(stream.ToAr ray());
stream.Close();
img.scalePercen t(72f / bitmap.Horizont alResolution * 100);
img.setAbsolute Position(0, 0);
cb.addImage(img );
document.newPag e();
}
document.Close( );

code 2:
Document document = new Document(PageSi ze.A4, 50, 50, 50, 50);
PdfWriter writer = PdfWriter.getIn stance(document , new
System.IO.FileS tream(pdfFileNa me, System.IO.FileM ode.Create,
System.IO.FileA ccess.Write));
System.Drawing. Bitmap bitmap = new System.Drawing. Bitmap(tiffFile Name);
numberOfPages =
bitmap.GetFrame Count(System.Dr awing.Imaging.F rameDimension.P age);
document.Open() ;
PdfContentByte cb = writer.DirectCo ntent;
for(int page = 0; page < numberOfPages; page++)
{
bitmap.SelectAc tiveFrame(Syste m.Drawing.Imagi ng.FrameDimensi on.Page,
page);
iTextSharp.text .Image img =
iTextSharp.text .Image.getInsta nce(bitmap); // This step is really slow
img.scalePercen t(72f / bitmap.Horizont alResolution * 100);
img.setAbsolute Position(0, 0);
cb.addImage(img );
document.newPag e();
}
document.Close( );

If I use solution 1 with a Jpeg format instead of Png, the conversion is a
bit slower and the PDF file size is 22 901ko. I also tried changing Jpeg
compression value with this code :
System.Drawing. Imaging.ImageCo decInfo myImageCodecInf o =
GetEncoderInfo( "image/jpeg");
System.Drawing. Imaging.Encoder myEncoder =
System.Drawing. Imaging.Encoder .Quality;
System.Drawing. Imaging.Encoder Parameter myEncoderParame ter= new
System.Drawing. Imaging.Encoder Parameter(myEnc oder, 50L);
System.Drawing. Imaging.Encoder Parameters myEncoderParame ters = new
System.Drawing. Imaging.Encoder Parameters(1);
myEncoderParame ters.Param[0] = myEncoderParame ter;
//....
bitmap.Save(str eam, myImageCodecInf o, myEncoderParame ters);
//....
but the resulting PDF file is still 17 900ko.

If I use
iTextSharp.text .Image img =
iTextSharp.text .Image.getInsta nce(bitmap.Widt h, bitmap.Height, true,
iTextSharp.text .Element.CCITTG 4, 0, stream.ToArray( ));
instead of
iTextSharp.text .Image img =
iTextSharp.text .Image.getInsta nce(stream.ToAr ray());
in code 1, then the PDF is only filled with white pages and I have an error
box when I open the PDF in Acrobat Reader.

I tried both http://itextsharp.sourceforge.net/ and
http://www.ujihara.jp/iTextdotNET/en/. I am having the same problem with
both libraries. Any suggestion to have a fast conversion with small PDF size
would be appreciated.

Thanks in advance.

Nicolas
Jul 21 '05 #1
0 18136

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7057
by: Dominic | last post by:
Hi guys, In .NET, how can I convert a HTML file to TIFF efficiently? One possible way is that I can first use word automatation to load the HTML up and then print it to TIFF. Is that right? However, even if it is technically feasible, it can take long time to do the conversion, especially the HTML is complicated. Is there any other more efficient way? Thanks!
0
1690
by: MC | last post by:
Hi, I'm developing an VB.NET app that converts TIFFs to PDFs using Office Imaging 2003 and Adobe Distiller 6.0 in the follwing way: 1. Using automation, I open the TIFF file with Office Imaging 2003. 2. I Printout the document to a .PS file using the Printout method into Adobe PostScript virtual printer.
4
50967
by: Pushp | last post by:
Hello friends, Can any body tell me the sample code to convert a Tiff image to a Gif or Jpeg format. The Resolution of picture is a big concern keeping in mind. Hope to get the response from all of you. Regards,
1
16249
by: Prasad More | last post by:
Hello, I am trying to write a text on Multi-page TIFF image using C# and .NET GDI+. I have written following code to do this. When I execute this code I get "Invalid Parameter User. at System.Drawing.Image.Save" error. public void addAnnotationStampOnImage() { string strStamp = Path.GetFileNameWithoutExtension(_ImageFileName); Size dSize; Image iMulti = Image.FromFile(_ImageFileName);
3
4104
by: David A. Osborn | last post by:
I currently have a class that has an enumeration of graphics extensions that it supports ie: Public Enum GraphicFormats JPG JPEG BMP TIFF End Enum
0
2816
by: Nicolas Guilhot | last post by:
Hi all ! I have a multi-page Tiff image file that I want to convert to PDF. To do so I am using iText library. The conversion is working, but the code execution is very different according to wich iTextSharp.text.Image.getInstance(...) signature I am using : - using code 1 below, the conversion is fast enough but the resulting PDF file is too big (1 817ko sample Tiff file is converted in less than 30 seconds to a 2 764ko PDF file) -...
0
2370
by: gcorgnet | last post by:
Hi all, I have a set of Multipage Tiff documents that are to be sent to a web browser. So, I want to convert them to Gif (or Png) before sending them to the client. Those Tiff docs are bitonal (1bpp) with a 200dpi*200dpi resolution. They don't display very well on the browser (I think resolution is too big and bitonal images are not nice to read anyway ...) So I would like to be able to convert on-the-fly my docs to grayscale gif. ...
0
4143
by: shlim | last post by:
Currently I'm using VB.Net to perform a http/https multipart form post to a servlet. I'm able to perform the post using HttpWebrequest via GetRequestStream(). However, the servlet returned me with "The remote server returned an error: (500) Internal Server Error". Obviously, this means that I have not posted all the parameters as the servlet requested. But I just can't seem to find out what went wrong with my code. Hope someone can enlighten me,...
1
3896
by: sainathparuchuri | last post by:
As a project requirement we need to convert word documents to tiff images. We have been using Microsoft Office Document Image Writer (MODI) for this puspose and doing absolutely well. But now this process need to be automated. Whenever a document is converted to tiff MODI pops up a "Save as" dialog box which asks the path to save the converted tiff file. Now is there a way this "Save as" dialog box can be suppressed and all the files be...
0
9993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9841
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11265
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7188
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5882
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4707
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4296
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.