473,794 Members | 2,765 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 18056

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

Similar topics

4
7049
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
1680
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
50932
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
16231
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
4096
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
2365
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
4111
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
3892
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
9518
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
10433
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
10212
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10161
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6777
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
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4112
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
3720
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.