There's no effort made to keep the javascript in the right places as the
only way to do that would be to interpret the javascript. Nevertheless,
I'll have a look into it.

Paulo

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Peter Soelter
> Sent: Friday, July 14, 2006 11:02 AM
> To: [email protected]
> Subject: [iText-questions] PdfCopyFields and field-kids problem
> 
> Hi everybody,
> i'm trying to use the class PdfCopyFields for copying PDFs 
> with fields.
> 
> There are the same fields on different pages of a PDF and the fields 
> have attached javascript (a coloured border is shown, when the focus 
> is in the field). Therefore i'm using kid-fields with method 
> setPlaceInPage().
> 
> When copying the PDF with PdfCopyFields the fields are copied 
> correctly, but
> the javascript ist lost. In fact, the javascript is attached 
> to the field, 
> but not to the field-kids any more.
> 
> Does anybody have an idea?
> 
> Thanks,
> Peter
> 
> Here is some sourcecode for reproducing the problem:
> 
> 
> import java.io.FileOutputStream;
> import java.io.IOException;
> 
> import com.lowagie.text.Document;
> import com.lowagie.text.DocumentException;
> import com.lowagie.text.PageSize;
> import com.lowagie.text.Paragraph;
> import com.lowagie.text.Rectangle;
> import com.lowagie.text.pdf.BaseFont;
> import com.lowagie.text.pdf.PdfAction;
> import com.lowagie.text.pdf.PdfAnnotation;
> import com.lowagie.text.pdf.PdfBorderDictionary;
> import com.lowagie.text.pdf.PdfCopyFields;
> import com.lowagie.text.pdf.PdfFormField;
> import com.lowagie.text.pdf.PdfReader;
> import com.lowagie.text.pdf.PdfWriter;
> 
> 
> public class CopyWithFields
> {
> 
>     public static void main(String[] args)
>     {
>         Document document = new Document(PageSize.A4, 50, 50, 50, 50);
>         try 
>         {
>             PdfFormField aFormField, aKidField;
>             String strFieldName;
>             String strFile1 = "c:\\form_text.pdf";
>             String strFocusColor;
> 
>             // creation of the different writers
>             PdfWriter writer = 
> PdfWriter.getInstance(document, new FileOutputStream(strFile1));
>             document.open();
> 
>             strFieldName = "field1";
>             Rectangle aRect = new Rectangle(100, 400, 100 + 
> 300, 400 + 50);
> 
>             // create the field and it's first kid on page 1
>             aFormField = createTextField(writer, strFieldName, aRect);
>             PdfFormField aKidField1 = createKidField(writer, 
> aFormField, strFieldName, aRect);
>             aKidField1.setPlaceInPage(1);
> 
>             // create the second kid on page 2
>             Rectangle aRect2= new Rectangle(100, 600, 100 + 
> 100, 600 + 50);
>             PdfFormField aKidField2 = createKidField(writer, 
> aFormField, strFieldName, aRect2);
>             aKidField2.setPlaceInPage(2);
> 
>             document.newPage();
>             document.add(new Paragraph("Hello Fields Page 1"));
> 
>             writer.addAnnotation(aFormField);
> 
>             document.newPage();
>             document.add(new Paragraph("Hello Fields Page 2"));
> 
>             document.close();
>             
>             // copy the PDF with PdfCopyFields
>             PdfCopyFields copyFields = new PdfCopyFields(new 
> FileOutputStream("c:\\form_text_copy.pdf"));
>             PdfReader reader = new PdfReader(strFile1);
>             copyFields.addDocument(reader);
>             copyFields.close();
>             
>             System.out.println("finished.");
>         }
>         catch (Exception de) {
>             de.printStackTrace();
>         }
>     }
>     
>     private static PdfFormField createTextField(PdfWriter 
> writer, String strFieldName, Rectangle aRect) throws 
> DocumentException, IOException
>     {
>         PdfFormField aFormField;
>         aFormField = PdfFormField.createTextField(writer, 
> false, false, 100);
>         aFormField.setFieldName(strFieldName);
>         aFormField.setUserName("Comment");
>         
>         return aFormField;
>     }
> 
>     private static PdfFormField createKidField(PdfWriter 
> writer, PdfFormField aParentField, String strFieldName, 
>                                         Rectangle aRect) 
> throws DocumentException, IOException
>     {
>         PdfFormField aKidField;
>         
>         float fontSize = 10;
>         BaseFont helv = BaseFont.createFont("Helvetica", 
> "winansi", false);
>         
>         aKidField = PdfFormField.createTextField(writer, 
> false, false, 100);
>         aKidField.setWidget(aRect, PdfAnnotation.HIGHLIGHT_INVERT);
>       
>         PdfAction aActionGetFocus = PdfAction.javaScript("var 
> f = this.getField(\"" + strFieldName + "\"); f.strokeColor = 
> color.blue;", writer);
>         PdfAction aActionLooseFocus = 
> PdfAction.javaScript("var f = this.getField(\"" + 
> strFieldName + "\"); f.strokeColor = color.transparent;", writer);
>         
>         
> aKidField.setAdditionalActions(PdfAnnotation.AA_FOCUS, 
> aActionGetFocus);
>         aKidField.setAdditionalActions(PdfAnnotation.AA_BLUR, 
> aActionLooseFocus);
>         
>         aKidField.setBorderStyle(new PdfBorderDictionary(1, 
> PdfBorderDictionary.STYLE_SOLID));
> 
>         aParentField.addKid(aKidField);
>         
>         return aKidField;
>     }
>     
> }


Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter 
informação confidencial ou legalmente protegida. A incorrecta transmissão desta 
mensagem não significa a perca de confidencialidade. Se esta mensagem for 
recebida por engano, por favor envie-a de volta para o remetente e apague-a do 
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de 
usar, revelar ou distribuir qualquer parte desta mensagem. 

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain 
confidential or legally protected information. The incorrect transmission of 
this message does not mean the loss of its confidentiality. If this message is 
received by mistake, please send it back to the sender and delete it from your 
system immediately. It is forbidden to any person who is not the intended 
receiver to use, distribute or copy any part of this message.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to