Hi All,

I am reading some samples about iText but I confess I am having some problem starting with this one.

Does anyone can help me ?

Basiclly I want to write some phrases with a diferent color and paragraph alignment for each one, generating a pdf on the fly.

Thanks in advanced to all.

I know it's a basic question but it's important to me !


Here my code:


package pdfgenerator;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import java.awt.*;

import com.lowagie.text.*;
import com.lowagie.text.Font;
import com.lowagie.text.pdf.*;

public class completeSample extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws
      IOException, ServletException {
    Document document = new Document();

    try {
        Font blue = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.ITALIC, new Color(0x00, 0x00, 0xFF));
        Font red = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.BOLD, new Color(0xFF, 0x00, 0x00));
        Font orange = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.ITALIC, new Color(0xFF, 0x66, 0x00));

        response.setContentType("application/pdf");
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());

        document.open();

        Paragraph paragraph = new Paragraph();

        // Need to blue font (variable declared above)
        paragraph.setAlignment(Element.ALIGN_CENTER);
        document.add(new Paragraph("Centered title"));

        // Need to red font (variable declared above)
        paragraph.setAlignment(Element.ALIGN_RIGHT);
        document.add(new Paragraph("Right..."));
       
        // Need to organe font (variable declared above)
        paragraph.setAlignment(Element.ALIGN_LEFT);
        document.add(new Paragraph("Left..."));
       
        document.newPage();

        // Need to blue font (variable declared above)
        paragraph.setAlignment(Element.ALIGN_CENTER);
        document.add(new Paragraph("New page... Date and time"));
        document.add(new Paragraph(new Date().toString()));
    } catch (DocumentException de) {
      de.printStackTrace();
      System.err.println("document: " + de.getMessage());
    }

    document.close();
  }

}



--
Cumprts,
Carlos Bergueira

Reply via email to