changed:
-
<p>Para converter arquivos de imagem no formato TIF em documentos PDF basta
usar o iText. Adicione o arquivo <a
href="http://www.lowagie.com/iText/download.html">iText-2.1.4.jar</a> no seu
projeto e crie uma classe (ou método em uma classe já existente) parecida
com a apresentada abaixo:</p>
<p><font color="#009900">/*<br />
* $Id: Tiff2Pdf.java 3373 2008-05-12 16:21:24Z xlv $<br />
*<br />
* This code is part of the 'iText Tutorial'.<br />
* You can find the complete tutorial at the following address:<br />
*</font> <a href="http://itextdocs.lowagie.com/tutorial/"><font
color="#009900">http://itextdocs.lowagie.com/tutorial/</font></a><br />
<font color="#009900"> *<br />
* This code is distributed in the hope that it will be useful,<br />
* but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.<br />
*<br />
*</font> <a href="mailto:itext-questions@lists.sourceforge.net"><font
color="#009900">itext-questions@lists.sourceforge.net</font></a><br />
<font color="#009900"> */</font></p>
<p><font color="#009900">package
com.lowagie.examples.objects.images.tiff;</font></p>
<p><font color="#009900">import java.io.FileOutputStream;</font></p>
<p><font color="#009900">import com.lowagie.text.Document;<br />
import com.lowagie.text.Image;<br />
import com.lowagie.text.Paragraph;<br />
import com.lowagie.text.pdf.PdfContentByte;<br />
import com.lowagie.text.pdf.PdfWriter;<br />
import com.lowagie.text.pdf.RandomAccessFileOrArray;<br />
import com.lowagie.text.pdf.codec.TiffImage;</font></p>
<p><font color="#009900">/**<br />
* Demonstrates how the Tiff to PDF conversion works.<br />
*<br />
* @author psoares<br />
* @author blowagie<br />
*/</font></p>
<p><font color="#009900">public class Tiff2Pdf {</font></p>
<p><font color="#009900"> /**<br />
* Demonstrates some TIFF functionality.<br />
*<br />
* @param args<br />
* a
list of tiff files to convert<br />
*/<br />
public void convertTiff2Pdf(String fileName) {<br />
String pdf_file;<br />
<br />
pdf_file = fileName.substring(0, fileName.lastIndexOf('.') + 1)
+ "pdf";<br />
Document document = new Document();<br />
try {<br />
PdfWriter writer = PdfWriter.getInstance(document,<br />
new FileOutputStream(pdf_file));<br />
int pages = 0;<br />
document.open();<br />
PdfContentByte cb = writer.getDirectContent();<br />
RandomAccessFileOrArray ra = null;<br />
int comps
= 0;<br />
try
{<br />
ra = new RandomAccessFileOrArray(fileName);<br />
comps = TiffImage.getNumberOfPages(ra);<br />
<br />
System.out.println("Processing: " + fileName);<br />
for (int c = 0; c < comps; ++c) {<br />
try {<br />
Image img = TiffImage.getTiffImage(ra, c + 1);<br />
if (img != null) {<br />
System.out.println("page " + (c + 1));<br />
if (img.getScaledWidth() > 500 || img.getScaledHeight() > 700) {<br />
img.scaleToFit(500, 700);<br />
}<br />
img.setAbsolutePosition(20, 20);<br />
document.add(new Paragraph(fileName + " - page " + (c + 1)));<br />
cb.addImage(img);<br />
document.newPage();<br />
++pages;<br />
}<br />
}<br />
catch (Throwable e) {<br />
System.out.println("Exception " + fileName + " page " + (c + 1) + " " +
e.getMessage());<br />
}<br />
}<br />
ra.close();<br />
document.close();<br />
}<br />
catch
(Throwable e) {<br />
System.out.println("Exception in " + fileName + " " + e.getMessage());<br />
}<br />
} catch (Throwable e) {<br />
e.printStackTrace();<br />
}<br />
} <br />
}<br />
</font></p>