[iText-questions] how to invert color of tiff using itext

2009-05-22 Thread marlonbrando

Hello to all...when i convert tiff2pdf i found a little problem, for some
particular tiff (wich have COMP_FAX_G3_2D compression) the result pdf have
color inverted (black to white and white to black).

Is there a way using itext to invert the colors of the image?


my code is:



ByteArrayOutputStream baos = new ByteArrayOutputStream();
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, baos);
try {
int pages = 0;
document.open();
PdfContentByte cb = writer.getDirectContent();
RandomAccessFileOrArray ra = null;
int comps = 0;
ra = new RandomAccessFileOrArray(tiff.getStream());
comps = TiffImage.getNumberOfPages(ra);
for (int c = 0; c  comps; ++c) {

Image img = TiffImage.getTiffImage(ra, c + 1);
long h = 0;
long w = 0;
if (img != null) {
Float height = new 
Float(img.getScaledHeight());
h = height.longValue();
Float width = new 
Float(img.getScaledWidth());
w = width.longValue();
float percent = 100;
int pos = 0;
if (w  895)
percent = ((595 + 18) * 100 / 
w);
if (h  842)
pos = (int) (842 - h * percent 
/ 100);
else
pos = (int) (842 - h);

img.scalePercent(percent);
img.setAbsolutePosition(0, pos);
  
document.add(new Paragraph());
cb.addImage(img);
document.newPage();
++pages;
}

}

ra.close();
document.close();
writer.close();

-- 
View this message in context: 
http://www.nabble.com/how-to-invert-color-of-tiff-using-itext-tp23667238p23667238.html
Sent from the iText - General mailing list archive at Nabble.com.


--
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers  brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing,  
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA,  Big Spaceship. http://www.creativitycat.com 
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/


Re: [iText-questions] tiff2pdf byte Array problem

2008-03-18 Thread marlonbrando

Ok, 

 ByteArrayOutputStream baos =new ByteArrayOutputStream(); 
 Document document = new Document(); 
 PdfWriter writer = PdfWriter.getInstance(document,baos); 
try { 
  int pages = 0; 
  document.open(); 
  PdfContentByte cb = writer.getDirectContent(); 
  RandomAccessFileOrArray ra = null; 
  int comps = 0; 
  try { 
  ra = new 
 RandomAccessFileOrArray(tiff.getStream()); 
  comps = TiffImage.getNumberOfPages(ra); 
  
 for (int c = 0; c  comps; ++c) { 
  try { 
 Image img = 
 TiffImage.getTiffImage(ra,c+1); 
  long h = 0; 
  long w = 0; 
  if (img != null) { 
  Float height = new 
 Float(img.getScaledHeight()); 
  h = height.longValue(); 
  Float width = new 
 Float(img.getScaledWidth()); 
  w = width.longValue(); 
  float percent = 100; 
  int pos = 0; 
  if (w  895) 
  percent = ((595 + 18) * 
 100 / w); 
  if (h  842) 
  pos = (int) (842 - h * 
 percent / 100); 
else 
  pos = (int) (842 - h); 
  
  
 img.scalePercent(percent); 
  
 img.setAbsolutePosition(0,pos); 
  
 document.add(new Paragraph()); 
  
 cb.addImage(img); 
  
 document.newPage(); 
 ++pages; 
 } 
  
  } catch (Throwable e) { 
  e.printStackTrace(); 
  } 
  } 
  
  } catch (Throwable e) { 
  e.printStackTrace(); 
  } 
   FileOutputStream fos= new
FileOutputStream(result.pdf); 
   fos.write(baos.toByteArraY()); 
  document.close(); 
 } 
the code for conversion is the same. 
I must use a byte array because i want to return this to another method. 




Fabrizio Accatino wrote:
 
 Post the source code where you use ByteArrayOutputStream.
 
 -
 This SF.net email is sponsored by: Microsoft
 Defy all challenges. Microsoft(R) Visual Studio 2008.
 http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
 ___
 iText-questions mailing list
 iText-questions@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/itext-questions
 Buy the iText book: http://itext.ugent.be/itext-in-action/
 
 

-- 
View this message in context: 
http://www.nabble.com/tiff2pdf--byte-Array-problem-tp16097034p16105705.html
Sent from the iText - General mailing list archive at Nabble.com.


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/


[iText-questions] tiff2pdf byte Array problem

2008-03-17 Thread marlonbrando

hello to alli have write a little application that convert a multipage
tiff to a multipage pdf...

OutputStream fout =new FileOutputStream(result.pdf);
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document,fout);
  try {
int pages = 0;
document.open();
PdfContentByte cb = writer.getDirectContent();
RandomAccessFileOrArray ra = null;
int comps = 0;
try {
ra = new RandomAccessFileOrArray(tiff.getStream());
comps = TiffImage.getNumberOfPages(ra);

for (int c = 0; c  comps; ++c) {
try {
Image img = TiffImage.getTiffImage(ra,c+1);
long h = 0;
long w = 0;
if (img != null) {
Float height = new 
Float(img.getScaledHeight());
h = height.longValue();
Float width = new 
Float(img.getScaledWidth());
w = width.longValue();
float percent = 100;
int pos = 0;
if (w  895)
percent = ((595 + 18) * 100 / w);
if (h  842)
pos = (int) (842 - h * percent / 100);
else
pos = (int) (842 - h);


img.scalePercent(percent);

img.setAbsolutePosition(0,pos);
document.add(new 
Paragraph());
cb.addImage(img);
document.newPage();
++pages;
}
cb.getPdfDocument();
} catch (Throwable e) {
e.printStackTrace();
}
}

} catch (Throwable e) {
e.printStackTrace();
}
 document.close();
}

this code work fine.

but if i set  PdfWriter writer = PdfWriter.getInstance(document,new
ByteArrayOutputStream);

and then i write the content of outputstream on a file the pdf result is
corrupted...
Can anyone help me??

%-|
-- 
View this message in context: 
http://www.nabble.com/tiff2pdf--byte-Array-problem-tp16097034p16097034.html
Sent from the iText - General mailing list archive at Nabble.com.


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/