By Date: <-- -->
By Thread: <-- -->

FW: text editor and itext



 Yes, I know what's wrong:

First you need to understand that a BOLD font and a NORMAL font are two
different fonts.

Java takes the work out of it and chooses the correct font for you whether
you have chosen bold, normal, italic etc.

iText does not do this, if you want to have this work properly in iText, you
will have to do it manually and
Iterate through the text attributes and manually setup fonts etc.

I will look into the PdfGraphics2D class and see if there might be an
addition to make this work better.

-Bill Ensley
Bear Printing

-----Original Message-----
From: Stefano Maxis [mailto:stefano_maxis (at) hotmail.it] 
Sent: Sunday, February 05, 2006 4:55 AM
To: bill (at) bearprinting.com; dcmeagle (at) goosemoose.com;
itext-questions (at) lists.sourceforge.net
Subject: RE: FW: [iText-questions] text editor and itext

Hi, i've tried your example, but i lost font-weight. I'm using a different
html editor and i use style attribute and not font tag. In the editor
everything is ok (size, color, ...), but when i convert to pdf i lost
font-weight. Do u know the reason?

thanks


>From: "Bill Ensley" <bill (at) bearprinting.com>
>To: "'Dominic Maricic'" <dcmeagle (at) goosemoose.com>,"iText Mail Group" 
><itext-questions (at) lists.sourceforge.net>
>Subject: FW: [iText-questions] text editor and itext
>Date: Sun, 11 Dec 2005 20:05:34 -0800
>
>Brilliance has it's limits.  Here's the attachement.
>
>-Bill
>
>   _____
>
>From: Bill Ensley [mailto:bill (at) bearprinting.com]
>Sent: Sunday, December 11, 2005 8:00 PM
>To: 'Dominic Maricic'; iText Mail Group
>(itext-questions (at) lists.sourceforge.net)
>Subject: RE: [iText-questions] text editor and itext
>
>
>Attached is an updated version of my example with style editing built in.
>Italic, Bold, Family, Size and Color.
>
>What do you mean by needing to "discern colors and bold, italic, & 
>underline."?
>
>Enjoy.
>
>-Bill Ensley
>Bear Printing
>
>   _____
>
>From: Dominic Maricic [mailto:dcmeagle (at) goosemoose.com]
>Sent: Sunday, December 11, 2005 3:45 PM
>To: 'Bill Ensley'; 'iText Mail Group'
>Subject: RE: [iText-questions] text editor and itext
>
>
>That's what I thought. Have you seen any such editor? I've searched 
>high and low but haven't found anything I could use. Once I do, I would 
>still need to figure out how to discern colors and bold, italic, & 
>underline. Anyone done something like this?
>
>Dominic
>
>-----Original Message-----
>From: itext-questions-admin (at) lists.sourceforge.net
>[mailto:itext-questions-admin (at) lists.sourceforge.net] On Behalf Of Bill 
>Ensley
>Sent: Sunday, December 11, 2005 9:48 AM
>To: 'Dominic Maricic'; iText Mail Group
>Subject: RE: [iText-questions] text editor and itext
>
>You need to build that functionality into the JTextPane or JTextArea, 
>or any other JTextComponent.
>
>I just created a simple component and gave you the functionality to get 
>the StyledDocument into a PDF.
>
>You will need to create a Text Editor or find one on the internet.
>
>Once you have what you need, you can use this code to output it to iText.
>
>-Bill Ensley
>Bear Printing
>
>   _____
>
>From: itext-questions-admin (at) lists.sourceforge.net
>[mailto:itext-questions-admin (at) lists.sourceforge.net] On Behalf Of 
>Dominic Maricic
>Sent: Saturday, December 10, 2005 11:54 PM
>To: 'Bill Ensley'; 'iText Mail Group'
>Subject: RE: [iText-questions] text editor and itext Hi Bill,
>  Thanks for the example it definitely helped me see where I had a 
>problem in what I was trying. I don't see any way to have color, or 
>bold , italic, or underline. Is that possible?
>
>Thanks again!
>Dominic
>
>-----Original Message-----
>From: itext-questions-admin (at) lists.sourceforge.net
>[mailto:itext-questions-admin (at) lists.sourceforge.net] On Behalf Of Bill 
>Ensley
>Sent: Saturday, December 10, 2005 6:25 PM
>To: 'Dominic Maricic'; iText Mail Group
>Subject: RE: [iText-questions] text editor and itext
>
>OK, here it is.
>
>If you need help understanding what is going on, let me know.
>
>The main problem with this approach is that it is one page only.  You 
>currently must know it the data spans more than one page and manually 
>create additional pages for that.
>
>I have some code that forces a JTextPane to a certain number of lines 
>so that you could cut the user off after a certain amount of text 
>entered.
>
>-Bill Ensley
>Bear Printing
>
>______________________________________________________
>
>package com.squish.test;
>
>import java.awt.*;
>import java.awt.geom.*;
>
>import com.lowagie.text.Document;
>import com.lowagie.text.pdf.DefaultFontMapper;
>import com.lowagie.text.pdf.PdfContentByte;
>import com.lowagie.text.pdf.PdfWriter;
>
>import java.awt.event.*;
>
>import java.io.*;
>import javax.swing.*;
>
>public class JTextPaneToIText {
>  int inch = Toolkit.getDefaultToolkit().getScreenResolution();
>  float pixelToPoint = (float)72 / (float)inch;
>  JTextPane textPane;
>
>  public JTextPaneToIText() {
>   JFrame frame = new JFrame();
>
>   textPane = new JTextPane();
>
>   JScrollPane scrollPane = new JScrollPane(textPane);
>
>   JPanel north = new JPanel();
>   JButton print = new JButton("Print");
>   print.addActionListener(new ActionListener(){
>    public void actionPerformed(ActionEvent ae){
>     paintToPDF(textPane);
>    }
>   });
>   north.add(print);
>   frame.getContentPane().setLayout(new BorderLayout());
>   frame.getContentPane().add(north, BorderLayout.NORTH);
>   frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
>   frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
>   frame.setSize(1000,1000);
>   frame.setVisible(true);
>  }
>
>  public void paintToPDF(JTextPane ta){
>   try{
>    ta.setBounds(0,0,(int)convertToPixels(612-58),
>(int)convertToPixels(792-60));
>
>    Document document = new Document();
>    FileOutputStream fos = new FileOutputStream("c:/test.pdf");
>      PdfWriter writer = PdfWriter.getInstance(document, fos);
>
>      document.setPageSize(new com.lowagie.text.Rectangle(612, 792));
>      document.open();
>      PdfContentByte cb = writer.getDirectContent();
>
>      cb.saveState();
>      cb.concatCTM(1, 0, 0, 1, 0, 0);
>
>      DefaultFontMapper mapper = new DefaultFontMapper();
>
>      // this will need to be set for your font directory
>      mapper.insertDirectory("c:/windows/fonts");
>
>      Graphics2D g2 = cb.createGraphics(612, 792, mapper, true, .95f);
>
>      AffineTransform at = new AffineTransform();
>      at.translate(convertToPixels(20),convertToPixels(20));
>      at.scale(pixelToPoint,pixelToPoint);
>
>      g2.transform(at);
>
>      g2.setColor(Color.WHITE);
>      g2.fill(ta.getBounds());
>
>      // a JTextComponent makes a copy of any graphics you pass to it 
>and then paints itself last.
>      // this fix makes the JTextComponent paint when you want it to, 
>not when it wants to.
>
>      Rectangle alloc = getVisibleEditorRect(ta);
>      ta.getUI().getRootView(ta).paint(g2, alloc);
>
>      g2.setColor(Color.BLACK);
>      g2.draw(ta.getBounds());
>
>      g2.dispose();
>      cb.restoreState();
>      document.close();
>      fos.flush();
>      fos.close();
>   }
>   catch(Exception e){
>    e.printStackTrace();
>   }
>  }
>
>  public float convertToPoints(int pixels){
>     return (float)(pixels * pixelToPoint);
>   }
>
>  public float convertToPixels(int points){
>     return (float)(points / pixelToPoint);
>   }
>
>  public static void main(String[] args) {
>   new JTextPaneToIText();
>
>  }
>  protected Rectangle getVisibleEditorRect(JTextPane ta) {
>   Rectangle alloc = ta.getBounds();
>   if ((alloc.width > 0) && (alloc.height > 0)) {
>       alloc.x = alloc.y = 0;
>       Insets insets = ta.getInsets();
>       alloc.x += insets.left;
>       alloc.y += insets.top;
>       alloc.width -= insets.left + insets.right;
>       alloc.height -= insets.top + insets.bottom;
>       return alloc;
>   }
>   return null;
>      }
>
>}
>
>   _____
>
>From: Dominic Maricic [mailto:dcmeagle (at) goosemoose.com]
>Sent: Saturday, December 10, 2005 5:45 PM
>To: 'Bill Ensley'
>Subject: RE: [iText-questions] text editor and itext Wow! Thanks
>
>-----Original Message-----
>From: Bill Ensley [mailto:bill (at) bearprinting.com]
>Sent: Saturday, December 10, 2005 5:40 PM
>To: 'Dominic Maricic'
>Subject: RE: [iText-questions] text editor and itext
>
>No, not left yet, another half hour.
>
>I'm going to try to give you a sample before I leave.
>
>-Bill
>
>   _____
>
>From: Dominic Maricic [mailto:dcmeagle (at) goosemoose.com]
>Sent: Saturday, December 10, 2005 5:35 PM
>To: 'Bill Ensley'
>Subject: RE: [iText-questions] text editor and itext My JTextArea 
>expands to the full screen of the JFrame, which is the entire screen. 
>It is in a JScrollPane so it could be even larger. It is possible the 
>text could flow over to a second printed page.
>
>Are you back from the movie already? How was it? That's my favorite 
>book series of all time, I hope to get to see it soon.
>Dominic
>
>-----Original Message-----
>From: Bill Ensley [mailto:bill (at) bearprinting.com]
>Sent: Saturday, December 10, 2005 5:34 PM
>To: 'Dominic Maricic'
>Subject: RE: [iText-questions] text editor and itext
>
>Will your JTextArea be the same size or smaller?
>
>If smaller, what size.
>
>-Bill
>
>   _____
>
>From: itext-questions-admin (at) lists.sourceforge.net
>[mailto:itext-questions-admin (at) lists.sourceforge.net] On Behalf Of 
>Dominic Maricic
>Sent: Saturday, December 10, 2005 4:16 PM
>To: 'Bill Ensley'; 'iText Mail Group'
>Subject: RE: [iText-questions] text editor and itext Ok. I've been 
>using those for most everything so I forget about the exact placement 
>methods. Right now I'm using the PageNumbersWatermark example to create 
>a border. The border is defined by this rectangle: cb.rectangle(20, 20, 
>document.getPageSize().width() - 38, document.getPageSize().height() - 
>40);
>
>Dominic
>
>-----Original Message-----
>From: itext-questions-admin (at) lists.sourceforge.net
>[mailto:itext-questions-admin (at) lists.sourceforge.net] On Behalf Of Bill 
>Ensley
>Sent: Saturday, December 10, 2005 4:13 PM
>To: 'Dominic Maricic'; iText Mail Group
>Subject: RE: [iText-questions] text editor and itext
>
>It can still be placed anywhere with out PdfTable or PdfParagraph.
>
>What do you want your X,Y,W,H to be? what is your border.
>
>-Bill
>
>   _____
>
>From: itext-questions-admin (at) lists.sourceforge.net
>[mailto:itext-questions-admin (at) lists.sourceforge.net] On Behalf Of 
>Dominic Maricic
>Sent: Saturday, December 10, 2005 4:04 PM
>To: 'Bill Ensley'; 'iText Mail Group'
>Subject: RE: [iText-questions] text editor and itext No fair, I want to 
>go too :-) In this case it's actually going to take up an entire 8.5x11 
>page (minus a border I have) as it will be the "Contract Page." But if 
>it came out in a PdfTable or PdfParagraph that's great as then it could 
>be placed anywhere.
>
>I really, really appreciate the help!
>
>Thanks,
>  Dominic
>
>-----Original Message-----
>From: itext-questions-admin (at) lists.sourceforge.net
>[mailto:itext-questions-admin (at) lists.sourceforge.net] On Behalf Of Bill 
>Ensley
>Sent: Saturday, December 10, 2005 4:01 PM
>To: 'Dominic Maricic'; iText Mail Group
>Subject: RE: [iText-questions] text editor and itext
>
>Do you need to place it at a specific X and Y?
>
>and also, what are it's dimensions?
>
>I will be able to write you something tonight, I have to leave for a 
>little while in a few minutes.  Narnia made it to theaters : )
>
>-Bill
>
>   _____
>
>From: Dominic Maricic [mailto:dcmeagle (at) goosemoose.com]
>Sent: Saturday, December 10, 2005 3:57 PM
>To: 'Bill Ensley'; 'iText Mail Group'
>Subject: RE: [iText-questions] text editor and itext Hi Bill,
>  Thanks for the quick response. I want to place an editor on a JPanel 
>in my program where the user can type out a few paragraphs. I want them 
>to be able to underline, bold, italic and change a few colors. Then I 
>want to be able to take what they typed out and insert it into a pdf I 
>create. I already have a 30 page pdf report document created by iText 
>based on other inputs in the program. This is going to be for a 
>contract page and the user has to enter their own. Then I'm going to 
>insert it into the pdf. So basically I need to take their input and 
>place it into the document.
>
>Thanks again.
>Dominic
>
>
>-----Original Message-----
>From: itext-questions-admin (at) lists.sourceforge.net
>[mailto:itext-questions-admin (at) lists.sourceforge.net] On Behalf Of Bill 
>Ensley
>Sent: Saturday, December 10, 2005 3:54 PM
>To: iText Mail Group
>Subject: FW: [iText-questions] text editor and itext
>
>What do you mean by parser?
>
>Are you trying to get the StyledDocument and parse that into iText?
>
>Give me some context for your project what is the end goal?
>
>I will be happy to put together an example, just get me started.
>
>-Bill Ensley
>Bear Printing
>
>   _____
>
>From: Dominic Maricic [mailto:dcmeagle (at) goosemoose.com]
>Sent: Saturday, December 10, 2005 3:48 PM
>To: Bill Ensley; 'Dominic Maricic'; iText Mail Group
>Subject: RE: [iText-questions] text editor and itext I would definately 
>like to see an example! Could you please post one here or email me? 
>I've been struggling with this problem for a long time. I tried writing 
>my own but could never write a decent parser. Thanks!
>
>Dominic
>
>--- "Bill Ensley" <bill (at) bearprinting.com> wrote:
>
>From: "Bill Ensley" <bill (at) bearprinting.com>
>Date: Fri, 9 Dec 2005 21:40:39 -0800
>To: "'Dominic Maricic'" <dcmeagle (at) goosemoose.com>, "iText Mail Group"
><itext-questions (at) lists.sourceforge.net>
>Subject: RE: [iText-questions] text editor and itext I use one, you 
>simply pass a PdfGraphics2D object to the JTextArea's paint method.
>
>it's that simple. you don't need anything special.
>
>Any other questions, I'm happy to answer them.
>
>Paulo, Bruno et al:
>
>Would you like an example of this for the tutorial or book?
>
>-Bill Ensley
>Bear Printing
>
>   _____
>
>From: itext-questions-admin (at) lists.sourceforge.net
>[mailto:itext-questions-admin (at) lists.sourceforge.net] On Behalf Of 
>Dominic Maricic
>Sent: Friday, December 09, 2005 9:15 PM
>To: itext-questions (at) lists.sourceforge.net
>Subject: [iText-questions] text editor and itext Are there any examples 
>of an editor like JTextArea that has color, and the usual bold 
>underline, & italics and then they data is transferred into itext? I'd 
>like to have such an editor and would rather not have to reinvent the 
>wheel. If not, any tips and direction would be greatly appreciated.
>Dominic


><< JTextPaneToIText.java >>

_________________________________________________________________
SMS + facili! Prova un nuovo modo, più comodo, di inviare SMS! 
http://join2.msn.com/?page=messenger/mm&ST=1&pgmarket=it-it



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
iText-questions mailing list
iText-questions (at) lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions