I receive an exception ExceptionConverter: java.lang.RuntimeException: The name 'anchor2' has no local destination., when trying to execute the following simple program.

 

If I change

      anchor1.setName(" ");

by

      anchor1.setName("something");

 

then the document is generated ok.

 

import com.lowagie.text.Anchor;

import com.lowagie.text.Document;

import com.lowagie.text.DocumentException;

import com.lowagie.text.Paragraph;

import com.lowagie.text.pdf.PdfWriter;

 

public class Test {

      void render(OutputStream stream) throws Exception {

            try {

                  PdfWriter writer = PdfWriter.getInstance(doc, stream);

                  doc.open();

                  Anchor anchor1 = new Anchor("Go to anchor2");

                  anchor1.setReference("#anchor2");

                  doc.add(new Paragraph(anchor1));

                  doc.newPage();

                  anchor1 = new Anchor("Anchor2");

                  anchor1.setName(" ");

                  doc.add(anchor1);

            } finally {

                  if (doc.isOpen()) {

                        doc.close();

                  }

            }

      }

      Document doc = new Document();

      PdfTemplate template;

     

      static public void main(String[] args) {

            try {

                  new Test().render();

                  System.out.println("Successfully generated");

            } catch (Exception e) {

                  e.printStackTrace();

            }

      }

}

 

 

--------

David

 

Reply via email to