HTML to PDF converter for Java and .NET

HOME   FEATURES   PRODUCTS   DOWNLOADS   BUY NOW!   SUPPORT
<< back

PDF forms with PD4ML

PD4ML API supports generatePdfForms conversion parameter, which forces PD4ML to convert HTML forms to corresponding PDF forms.

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

<%@ taglib uri="http://pd4ml.com/tlds/pd4ml/2.6" prefix="pd4ml" %><%@page
contentType="text/html; charset=ISO8859_1"%><pd4ml:transform
	screenWidth="300"
	pageFormat="A5"
	pageOrientation="landscape"
	pageInsets="100,100,100,100,points"
	enableImageSplit="false"
	generatePdfForms="true"
	enable="true">

<html>
	<head>
		<title>pd4ml test</title>
		<style type="text/css">
			body {
				color: #000000;
				background-color: #FFFFFF;
				font-family: Tahoma, "Sans-Serif";
				font-size: 10pt;
			}
		</style>
	</head>
	<body>

<form action="fdf.jsp" method=get name=test>
<table border=0>
<tr>
<td>Field 1:</td><td><input name=field1></td>
</tr>
<tr>
<td>Field 2:</td><td><input name=field2></td>
</tr>
<tr>
<td>Popup message:</td><td><input type=checkbox name=status value=ON></td>
</tr>
<tr>
<td>Result:</td><td><input name=result readonly></td>
</tr>
<tr>
<td> </td><td><input type=submit value=ADD></td>
</tr>
</table>
</form>

	</body>
</html>
</pd4ml:transform>
fdf.jsp
<%@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
<</FDF
   <<
   	  <%=message%>
      /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
<</Root 1 0 R>>
%%EOF
Download the example sources
Copyright ©2004-17 zefer|org. All rights reserved. Bookmark and Share