RE: [iText-questions] True Type Font Portability and Division by Zero exception

2002-05-14 Thread Paulo Soares

That's really strange. The method where the exception is thrown is called
after the embedded information is sent to the pdf, so the byte array has the
font. It can only throw the exception if head.unitsPerEm is zero and that
value was used before many times.
I tested your code and it works.

Best Regards,
Paulo Soares

 -Original Message-
 From: Jeff Larsen [SMTP:[EMAIL PROTECTED]]
 Sent: Monday, May 13, 2002 20:21
 To:   [EMAIL PROTECTED]
 Subject:  [iText-questions] True Type Font Portability and Division by
 Zero exception
 
 I'm using iText to generate PDF on the fly in a servlet running
 under Tomcat 4.0.3. The PDF document requires that an image file
 and True Type font file be packaged with the class that creates
 the PDF. In my development environment where the image and font
 files are read directly from the file system, everything works just
 fine. In my production environment (UNIX), where the PDF writing class,
 font and image files are packaged in a jar, I get a division by zero
 error as shown in the stack trace at the end of this message.
 
 Here's the java code for creating the font:
 
 BaseFont ocra = null;
 ClassLoader cl = Thread.currentThread().getContextClassLoader();
 URL ocraURL = cl.getResource(com/qec/util/fonts/OCRAN.TTF);
 if (ocraURL != null) {
   byte[] bytes = new byte[ocraURL.openConnection().getContentLength()];
   ocraURL.openStream().read(bytes);
   ocra = BaseFont.createFont(OCRAN.TTF, BaseFont.WINANSI,
  BaseFont.EMBEDDED, BaseFont.CACHED, bytes,
 null);
 }
 
 Since my ultimate goal was to make this code reusable outside of
 servlets, the class which contains the iText code and the required font
 and image files are packaged with the servlet in a jar file which is
 placed in the WEB-INF/lib directory of my web application.
 
 I know that the ClassLoader.getResource() code works, because I load an
 image file using the same technique. Am I incorrect in thinking that
 embedded True Type fonts can be used in this fashion outside of the
 Windows environment?
 
 Any insight into this problem is greatly appreciated.
 
 Jeff
 
 Here's the previously mentioned stack trace:
 
 ExceptionConverter: java.lang.ArithmeticException: / by zero
  at com.lowagie.text.pdf.TrueTypeFont.getFontDescriptor(Unknown Source)
  at com.lowagie.text.pdf.TrueTypeFont.writeFont(Unknown Source)
  at com.lowagie.text.pdf.FontDetails.writeFont(Unknown Source)
  at com.lowagie.text.pdf.PdfWriter.close(Unknown Source)
  at com.lowagie.text.pdf.PdfDocument.close(Unknown Source)
  at com.lowagie.text.Document.close(Unknown Source)
  at com.qec.util.InvoiceWriter.writePdf(InvoiceWriter.java:103)
  at
 com.qec.offsite.servlet.InvoiceServlet.doInvoiceAsPDF(InvoiceServlet.java:
 106)
  at
 com.qec.offsite.servlet.InvoiceServlet.processRequest(InvoiceServlet.java:
 51)
  at com.qec.offsite.servlet.InvoiceServlet.doGet(InvoiceServlet.java:39)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
  at
 com.qec.offsite.servlet.AbstractOffsiteServlet.service(AbstractOffsiteServ
 let.java:60)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicati
 onFilterChain.ja
 va:247)
  at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilter
 Chain.java:193)
  at
 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.
 java:243)
  at
 org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java
 :566)
  at
 org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472
 )
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
  at
 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.
 java:190)
  at
 org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java
 :566)
  at
 org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472
 )
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
  at
 org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
  at
 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:1
 80)
  at
 org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java
 :566)
  at
 org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValv
 e.java:170)
  at
 org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java
 :564)
  at
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:1
 70)
  at
 org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java
 :564)
  at
 org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472
 )
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
  at
 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.ja
 va:174)
  at
 org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java
 :566)
  at
 

RE: [iText-questions] height of a row in a table

2002-05-14 Thread Paulo Soares

PdfPTable.getDefaultCell().setBorder(Rectangle.NO_BORDER)

Best Regards,
Paulo Soares

 -Original Message-
 From: Ravi Prakash Vinnamuri [SMTP:[EMAIL PROTECTED]]
 Sent: Monday, May 13, 2002 17:13
 To:   [EMAIL PROTECTED]
 Subject:  [iText-questions] height of a row in a table
 
 I'm using table and getting data into table dynamically. But I'm not able
 to control the row height.
  I found that row height can be controlled using pdfptable but I didn't
 find a method in pdfptable where by I can display table with no borders.
 Can somebody suggest me a way to control the height of row in a table  OR
 a way to display a pdfptable with no borders.
  
 Thanks, 

___

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



Re: [iText-questions] True Type Font Portability and Division by Zero exception

2002-05-14 Thread Jeff Larsen

I found and fixed the problem. It had nothing to do with iText.

In the original code (below) the call to ocraURL.openStream().read(bytes)
returns the full file when the file is not jarred. When the font file
is contained in a jar, openStream() gets you an unbufffered InputStream
which requires repeated reads to get the full file.

BaseFont ocra = null;
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL ocraURL = cl.getResource(com/qec/util/fonts/OCRAN.TTF);
if (ocraURL != null) {
  byte[] bytes = new byte[ocraURL.openConnection().getContentLength()];
  ocraURL.openStream().read(bytes);
  ocra = BaseFont.createFont(OCRAN.TTF, BaseFont.WINANSI,
 BaseFont.EMBEDDED, BaseFont.CACHED, bytes, null);
}

The correct code to read the byte[] is:

  BufferedInputStream input = new BufferedInputStream(ocraURL.openStream());
  input.read(bytes, 0, bytes.length);

So the exception thrown by iText was because I fed it a font byte[] of
mostly zeros. Perhaps future versions of iText could throw an exception
in the call to BaseFont.createFont() if the byte[] is bogus. Then developers
would have a better idea of where the problem lies.

Thanks, 

Jeff

- Original Message - 
From: Paulo Soares [EMAIL PROTECTED]
To: 'Jeff Larsen' [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Tuesday, May 14, 2002 5:22 AM
Subject: RE: [iText-questions] True Type Font Portability and Division by Zero 
exception


 That's really strange. The method where the exception is thrown is called
 after the embedded information is sent to the pdf, so the byte array has the
 font. It can only throw the exception if head.unitsPerEm is zero and that
 value was used before many times.
 I tested your code and it works.
 
 Best Regards,
 Paulo Soares
 
  -Original Message-
  From: Jeff Larsen [SMTP:[EMAIL PROTECTED]]
  Sent: Monday, May 13, 2002 20:21
  To: [EMAIL PROTECTED]
  Subject: [iText-questions] True Type Font Portability and Division by
  Zero exception
  
  I'm using iText to generate PDF on the fly in a servlet running
  under Tomcat 4.0.3. The PDF document requires that an image file
  and True Type font file be packaged with the class that creates
  the PDF. In my development environment where the image and font
  files are read directly from the file system, everything works just
  fine. In my production environment (UNIX), where the PDF writing class,
  font and image files are packaged in a jar, I get a division by zero
  error as shown in the stack trace at the end of this message.
  
  Here's the java code for creating the font:
  
  BaseFont ocra = null;
  ClassLoader cl = Thread.currentThread().getContextClassLoader();
  URL ocraURL = cl.getResource(com/qec/util/fonts/OCRAN.TTF);
  if (ocraURL != null) {
byte[] bytes = new byte[ocraURL.openConnection().getContentLength()];
ocraURL.openStream().read(bytes);
ocra = BaseFont.createFont(OCRAN.TTF, BaseFont.WINANSI,
   BaseFont.EMBEDDED, BaseFont.CACHED, bytes,
  null);
  }
  
  Since my ultimate goal was to make this code reusable outside of
  servlets, the class which contains the iText code and the required font
  and image files are packaged with the servlet in a jar file which is
  placed in the WEB-INF/lib directory of my web application.
  
  I know that the ClassLoader.getResource() code works, because I load an
  image file using the same technique. Am I incorrect in thinking that
  embedded True Type fonts can be used in this fashion outside of the
  Windows environment?
  
  Any insight into this problem is greatly appreciated.
  
  Jeff
  
  Here's the previously mentioned stack trace:
  
  ExceptionConverter: java.lang.ArithmeticException: / by zero
   at com.lowagie.text.pdf.TrueTypeFont.getFontDescriptor(Unknown Source)
   at com.lowagie.text.pdf.TrueTypeFont.writeFont(Unknown Source)
   at com.lowagie.text.pdf.FontDetails.writeFont(Unknown Source)
   at com.lowagie.text.pdf.PdfWriter.close(Unknown Source)
   at com.lowagie.text.pdf.PdfDocument.close(Unknown Source)
   at com.lowagie.text.Document.close(Unknown Source)
   at com.qec.util.InvoiceWriter.writePdf(InvoiceWriter.java:103)
   at
  com.qec.offsite.servlet.InvoiceServlet.doInvoiceAsPDF(InvoiceServlet.java:
  106)
   at
  com.qec.offsite.servlet.InvoiceServlet.processRequest(InvoiceServlet.java:
  51)
   at com.qec.offsite.servlet.InvoiceServlet.doGet(InvoiceServlet.java:39)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
   at
  com.qec.offsite.servlet.AbstractOffsiteServlet.service(AbstractOffsiteServ
  let.java:60)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
   at
  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicati
  onFilterChain.ja
  va:247)
   at
  org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilter
  Chain.java:193)
   at
  org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.
  java:243)
   at
  

[iText-questions] Implementing image maps

2002-05-14 Thread Paul Warren

Hi,

I am trying to implement image maps in a PDF document, so that areas of
a graphic link to other points in a PDF document.

I am creating the graphics using Graphics2D to create a PDFTemplate (as
per tutorial chapter10).  I want to include the graphics inline, so I
then do:

  document.add(new ImgTemplate(myPDFTemplate));

This much works very well.  

My problem is in creating the link areas.  I can use
PDFTemplate.localGoto(name, llx, lly, urx, ury), but these
co-ordinates are relative to the page, not the template.  What I really
want to do is use co-ordinates relative to the lower left of the
template.

Is there a way around this?  I can't see how to transform the
co-ordinates myself, as I don't know the absolute position where the
ImgTemplate will be placed.

cheers,

Paul

___

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



RE: [iText-questions] Implementing image maps

2002-05-14 Thread Paulo Soares

Link coordinates are always relative to the page and that's the way PDF
works. It's impossible for the moment to make it relative to the template as
it would require to store the transformation matrix, something that is not
done now. You'll have to place the images at absolute positions and work
from there.

Best Regards,
Paulo Soares

 -Original Message-
 From: Paul Warren [SMTP:[EMAIL PROTECTED]]
 Sent: Tuesday, May 14, 2002 16:26
 To:   [EMAIL PROTECTED]
 Subject:  [iText-questions] Implementing image maps
 
 Hi,
 
 I am trying to implement image maps in a PDF document, so that areas of
 a graphic link to other points in a PDF document.
 
 I am creating the graphics using Graphics2D to create a PDFTemplate (as
 per tutorial chapter10).  I want to include the graphics inline, so I
 then do:
 
   document.add(new ImgTemplate(myPDFTemplate));
 
 This much works very well.  
 
 My problem is in creating the link areas.  I can use
 PDFTemplate.localGoto(name, llx, lly, urx, ury), but these
 co-ordinates are relative to the page, not the template.  What I really
 want to do is use co-ordinates relative to the lower left of the
 template.
 
 Is there a way around this?  I can't see how to transform the
 co-ordinates myself, as I don't know the absolute position where the
 ImgTemplate will be placed.
 
 cheers,
 
 Paul
 
 ___
 
 Have big pipes? SourceForge.net is looking for download mirrors. We supply
 the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
 ___
 iText-questions mailing list
 [EMAIL PROTECTED]
 https://lists.sourceforge.net/lists/listinfo/itext-questions

___

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



Re: [iText-questions] ArrayIndexOutOfBoundsException

2002-05-14 Thread Ben Sinclair

I just tried something new that might shed some light on my problem.

This is what I have been doing:

Create a temp pdf and a real pdf. Write to the temp pdf, close it, then import
it into the real pdf.

Some of these variables are defined outside this method.

When I run this, I get the ArrayIndexOutOfBoundsException.

 tempPdf.close();

 System.out.println(tempPdf length:  + new File(rendertemp.pdf).length());
 try {

  PdfReader reader = new PdfReader(rendertemp.pdf);
  System.out.println(Number of pages:  + reader.getNumberOfPages());

  for (int i = 1; i = reader.getNumberOfPages(); i++) {
   System.out.println(Adding page  + i);
   PdfImportedPage page = writer.getImportedPage(reader, i);
   PdfContentByte cb = writer.getDirectContent();
   cb.addTemplate(page,0,0); // Add temp pdf to the real pdf
try {
pdf.newPage();
   } catch (Exception e) {
System.err.println(Error starting new page);
   }
  }

 } catch (IOException e) {
  System.err.println(Couldn't open rendertemp.pdf!);
 }



Just for fun I tried to open an existing pdf that I didn't generate myself,
instead of rendertemp.pdf. That worked fine. I then renamed the temp pdf and
tried to append it, and that worked as well. It seems like if I generate my
temp pdf, close it, then import it into my real pdf right away, it doesn't
work.

Is there something more I have to do other than tempPdf.close() before I try
and open it?


--
Ben Sinclair
[EMAIL PROTECTED]


- Original Message -
From: Ben Sinclair [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, May 13, 2002 12:47 PM
Subject: Re: [iText-questions] ArrayIndexOutOfBoundsException


 I know the PDF is probably totally invalid. Is there any way to make it throw
 an exception indicating this before I call .close()? Since this occurs during
 close(), I don't get anything into my new PDF.



___

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



Re: [iText-questions] Implementing image maps

2002-05-14 Thread Paul Warren

On Tue, May 14, 2002 at 04:38:29PM +0100, Paulo Soares wrote:
 Link coordinates are always relative to the page and that's the way PDF
 works. It's impossible for the moment to make it relative to the template as
 it would require to store the transformation matrix, something that is not
 done now. You'll have to place the images at absolute positions and work
 from there.

OK.  The difficulty I see in doing this is in mixing the graphics and
text (and in particular, tables).  From reading the tutorial, it looks
like I not use the Document class, and instead should do the text layout
using columns, as this allows me call get/setYLine and thus stop and
start text around the graphics.

My next question is then how to handle tables.  Given that I'll be using
absolute position, it sounds like I need to use PdfPTables.  What
concerns me is how to split PdfPTables across multiple pages where
necessary.  Presumably, I need to look at each row and call
getRowHeight to determine what will fit on a page, and then call
writeSelectedRows appropriately.

Would it be worth me attempting to develop a patch to allow relative
link co-ordinates?

cheers,

Paul

___

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



[iText-questions] adding an image to a cell with text

2002-05-14 Thread Campanale, Rocco

I am working with version .91. What I am trying to accomplish is to add a cell to 
table that contains an image,jpeg, and some text, side by side.

I seem to be able to accomplish this with the following snippet of code:

hdr1 = new Chunk(uncheckImg,0,0);
hdr2 =  new Chunk(Pricing);
Phrase phrase = new Phrase(hdr1);   
phrase.add(hdr2);
  
cell = new Cell(phrase);
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorder(Rectangle.NO_BORDER);
//cell.setGrayFill(grayFill);
table.addCell(cell,currentRow++,firstCol+2);

However, if I uncomment setGrayFill() for the cell, the image is no longer visible.

Am I missing something or are there other solutions besides putting the image and text 
in separate cells. 

Thanks.

Rocco

___

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



[iText-questions] Question: How can I extract form elements?

2002-05-14 Thread Scott Yanoff
Title: Question: How can I extract form elements?






This product seems the best out of any I have been researching so far.
Currently, I can successfully read in a series of PDF files and concatenate them into one.
However, I'd like to update existing widget/form fields with new text values.
The Big Faceless PDF Library allows me to do this pretty easily by looping through all the form elements. I tried using getAcroForm via the document class but did not have any luck. Any references would be appreciated!


Scott Yanoff
414.577.7259 / [EMAIL PROTECTED] / AOL IM: say kjy





*DISCLOSURE STATEMENT*
This transmission may contain information which is confidential, proprietary and privileged. If you are not the individual or entity to which it is addressed, note that any review, disclosure, copying, retransmission or other use is strictly prohibited. If you received this transmission in error, please notify the sender immediately and delete the material from your system. This transmission is for informational purposes only, and is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. Any information regarding specific investments or other products is not warranted as to completeness or accuracy and is subject to change without notice.




Re: [iText-questions] Question: How can I extract form elements?

2002-05-14 Thread Leonard Rosenthol
Title: Re: [iText-questions] Question: How can I extract
form


At 2:27 PM -0500 5/14/02, Scott Yanoff wrote:
Currently, I
can successfully read in a series of PDF files and concatenate them
into one.
However, I'd
like to update existing widget/form fields with new text
values.

 At this
time, you can't :(. But a couple of us are actively
investigating it...


Leonard
-- 

---
Leonard
Rosenthol
mailto:[EMAIL PROTECTED]
Chief Technical
Officer
http://www.pdfsages.com
PDF Sages,
Inc. 215-629-3700
(voice)