Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forms on multi page pdfs #913

Open
wants to merge 2 commits into
base: open-dev-v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
input { color: orange; font-family: monospace; }
textarea { color: red; font-family: monospace; }
button { color: blue; font-family: monospace; border-radius: 8px; background-color: yellow; }
input[name="signature"] { color: green; }
</style>
</head>
<body>
Expand All @@ -20,6 +21,7 @@
<input type="submit" value="GO!"/>
<button type="submit">SUBMIT</button>
<input type="password" name="notvery" value="secret"/>
<input type="text" name="signature" class="signature"/>

<div>
<input type="checkbox" name="checker1" value="1" checked="" style="-fs-checkbox-style: check;" />
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<html>
<head>
<style>
@page {
size: 200px 100px;
margin: 5px;
}
body {
margin: 0;
}
input {
width: 12em;
height: 50px;
}
</style>
</head>
<body>
<form>
<div>Text</div>
<input type="text" name="text-input" value="Hello World!" style="border: 1px solid red;" />
<div>Text</div>
<input type="text" name="text-input2" value="Hello Second World!" style="border: 1px solid green;" />
</form>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<html>
<head>
<style>
@page {
size: 500px 250px;
margin:0;padding:20px;
}
body {margin:0;padding:0;font-size:10px; font-famliy: TestFont, serif, sans-serif; }
div {border: 0px}
input[name="signature"] {
height: 80px;
width: 150px;
border: 0;
background-color: lightgrey;
}
input[name="another-signature"] {
width: 400px;
height: 2.5em;
border: 0;
border-bottom: 1px solid black;
}
</style>
</head>

<body>
<div>
<form>
<div>
Required signature please:
<input type="text" name="signature1" required="required" class="signature"/>
</div>
<div>

<input type="text" name="another-signature" title="Alternate Field Name" alt="Partial Nameeee" class="signature"/>
<div>Another one</div>
</div>

</form>
</div>
</body>
</html>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,15 @@ public void testIssue792TargetCounterStyle() throws IOException {
assertTrue(vt.runTest("issue-792-target-counter-style"));
}

@Test
public void testSignatureField() throws IOException {
assertTrue(vt.runTest("form-signature-field"));
}
@Test
public void testFormFieldOnSecondPage() throws IOException {
assertTrue(vt.runTest("form-control-on-second-page"));
}

// TODO:
// + Elements that appear just on generated overflow pages.
// + content property (page counters, etc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

Expand All @@ -31,57 +33,57 @@ public static Element getChild(Element parent, String name) {
for (int i = 0; i < children.getLength(); i++) {
Node n = children.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
Element elem = (Element)n;
Element elem = (Element) n;
if (elem.getTagName().equals(name)) {
return elem;
}
}
}
return null;
}

public static List<Element> getChildren(Element parent, String name) {
List<Element> result = new ArrayList<>();
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node n = children.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
Element elem = (Element)n;
Element elem = (Element) n;
if (elem.getTagName().equals(name)) {
result.add(elem);
}
}
}
return result.size() == 0 ? null : result;
}

/**
* Helper function to find an enclosing element with given node name. Returns null on failure.
*/
public static Element findClosestEnclosingElementWithNodeName(Node e, String nodeName) {
Node parent;
while ((parent = e.getParentNode()) != null) {
if (parent.getNodeType() == Node.ELEMENT_NODE &&
parent.getNodeName().equals(nodeName)) {
parent.getNodeName().equals(nodeName)) {
return (Element) parent;
}
e = parent;
}
return null;
}

/**
* Loads all of the text content in all offspring of an element.
* Ignores all attributes, comments and processing instructions.
*
* @return a String with the text content of an element (may be an empty string but will not be null).
*/
public static String getText(Element parent) {
StringBuilder sb = new StringBuilder();
getText(parent, sb);
StringBuilder sb = new StringBuilder();
getText(parent, sb);
return sb.toString();
}

/**
* Appends all text content in all offspring of an element to a StringBuffer.
* Ignores all attributes, comments and processing instructions.
Expand All @@ -93,10 +95,28 @@ public static void getText(Element parent, StringBuilder sb) {
for (int i = 0; i < children.getLength(); i++) {
Node n = children.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
getText((Element)n, sb);
getText((Element) n, sb);
} else if (n.getNodeType() == Node.TEXT_NODE) {
sb.append(n.getNodeValue());
}
}
}

public static String toDebugInfo(Element element) {
if (element == null)
return "null";
StringBuilder elementString = new StringBuilder();
elementString.append('<');
elementString.append(element.getNodeName());
NamedNodeMap attributes = element.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Node attribute = attributes.item(i);
elementString.append(' ');
elementString.append(attribute.getNodeName());
elementString.append("=\"");
elementString.append(attribute.getNodeValue());
elementString.append('"');
}
return elementString.toString();
}
}
Loading