Viewing 1 post (of 1 total)
  • Author
    Posts
  • #26563

    Below is a simple PDF-forms based server-side “calculator”. It submits PDF form input to server-side script and recieves the form update as FDF data.

    Note: Preview.app of Mac OS X (default PDF reader of Safari browser) does not seem to support PDF form submitting.

    index.jsp
    [language=xml:1rjc3xsm]<%@ taglib uri="http://pd4ml.com/tlds/pd4ml/2.6" prefix="pd4ml" %><%@page contentType="text/html; charset=ISO8859_1"%>



    pd4ml test


    Field 1:
    Field 2:
    Popup message:
    Result:
     


    [/language:1rjc3xsm]

    fdf.jsp
    [language=xml:1rjc3xsm]<%@page contentType="application/vnd.fdf"%><% int v1 = 0; int v2 = 0; try { v1 = Integer.parseInt(request.getParameter("field1")); } catch ( NumberFormatException e ) { } try { v2 = Integer.parseInt(request.getParameter("field2")); } catch ( NumberFormatException e ) { } int res = v1 + v2; // business logic of the script String status = request.getParameter("status"); String message = ( status != null && status.length() > 0 ) ? “/Status (Well done!)” : “”;
    %>
    %FDF-1.2
    1 0 obj
    < /Fields [ << /T(result) /V(<%=res%>) >>
    << /T(field1) /V(<%=v1%>) >>
    << /T(field2) /V(<%=v2%>) >>
    % << /T(status) /V(<%=(message.length() > 0?”Yes”:”Off”)%>) >> % Checkbox init does not work for some reason
    ]
    /UF(<%=request.getHeader("referer") %>)
    /F(<%=request.getHeader("referer") %>)
    >>
    >>
    endobj
    trailer
    <>
    %%EOF[/language:1rjc3xsm]

Viewing 1 post (of 1 total)

The forum ‘PD4ML Tips & Tricks’ is closed to new topics and replies.