<%@page import="java.io.*,
                javax.servlet.*,
                java.text.*,
                java.util.*,
                com.pdflib.pdflib" %><%
    /* $Id: personalize.jsp,v 1.1.2.4 2002/01/28 17:45:30 rp Exp $
     *
     * Personalize.jsp.
     */


    int form, pdi_page, font;
    float width, height;
    pdflib p;
    Date now = new Date();
    DateFormat fulldate = DateFormat.getDateInstance(DateFormat.LONG); 
    String infile = "PDFlib-purchase-order.pdf";
    final int col1 = 70, col2 = 335;

    p = new pdflib();
    byte[] buf;
    ServletOutputStream output;

    p.open_file("");

    p.set_info("Creator", "personalize.jsp");
    p.set_info("Author", "Rainer Ploeckl");
    p.set_info("Title", "PDFlib personalization demo (JSP)");

    form = p.open_pdi(infile, "", 0);
    if (form == -1) {
	System.err.println("Couldn't open input file '" + infile + "'.\n");
	System.exit(1);
    }

    pdi_page = p.open_pdi_page(form, 1, "");
    if (pdi_page == -1) {
	System.err.println("Couldn't open page 1 in '" + infile + "'.\n");
	System.exit(1);
    }

    font = p.findfont("Helvetica-Bold", "host", 0);

    // get the dimensions of the imported form
    width = p.get_pdi_value("width", form, pdi_page, 0);
    height = p.get_pdi_value("height", form, pdi_page, 0);

    p.begin_page(width, height);
    p.place_pdi_page(pdi_page, 0, 0, 1, 1);
    p.close_pdi_page(pdi_page);

    p.setfont(font, 18);
    p.set_value("leading", 24);
    p.set_text_pos(col1, 486);

    p.show("Doublecheck, Inc.");
    p.continue_text("Petra Porst");
    p.continue_text("500, Market St.");
    p.continue_text("94110 San Francisco, CA");
    p.continue_text("");
    p.continue_text("USA");
    p.continue_text("+1/950/123-4567");
    p.continue_text("+1/950/123-4568");
    p.continue_text("");
    p.set_text_pos(col1, 278);
    p.show("petra@doublecheck.com");

    p.set_text_pos(col2, 104);
    p.continue_text(fulldate.format(now));

    p.end_page();

    p.close();
    p.close_pdi(form);

    buf = p.get_buffer();

    response.setContentType("application/pdf");
    response.setContentLength(buf.length);

    output = response.getOutputStream();
    output.write(buf);
    output.close();
%>
