|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.pdfbox.pdmodel; |
| 18 | + |
| 19 | +import java.io.ByteArrayOutputStream; |
| 20 | +import java.io.IOException; |
| 21 | + |
| 22 | +import org.apache.pdfbox.pdmodel.common.PDRectangle; |
| 23 | +import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget; |
| 24 | +import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; |
| 25 | +import org.apache.pdfbox.pdmodel.interactive.form.PDTextField; |
| 26 | + |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | + |
| 29 | +/** |
| 30 | + * Test case introduced with PDFBOX-6097 |
| 31 | + * |
| 32 | + */ |
| 33 | +class TestPDPage |
| 34 | +{ |
| 35 | + @Test |
| 36 | + void testAddingPageAfterCreatingAnnotation() throws IOException |
| 37 | + { |
| 38 | + try (PDDocument document = new PDDocument()) |
| 39 | + { |
| 40 | + PDPage page = new PDPage(PDRectangle.A4); |
| 41 | + // Create AcroForm |
| 42 | + PDAcroForm acroForm = new PDAcroForm(document); |
| 43 | + document.getDocumentCatalog().setAcroForm(acroForm); |
| 44 | + |
| 45 | + // Create a single text field |
| 46 | + PDTextField textField = new PDTextField(acroForm); |
| 47 | + textField.setPartialName("testField"); |
| 48 | + PDAnnotationWidget widget = textField.getWidgets().get(0); |
| 49 | + widget.setRectangle(new PDRectangle(100, 700, 200, 20)); |
| 50 | + widget.setPage(page); |
| 51 | + page.getAnnotations().add(widget); |
| 52 | + acroForm.getFields().add(textField); |
| 53 | + |
| 54 | + // Adding page AFTER creating form fields causes a StackOverflowError |
| 55 | + document.addPage(page); |
| 56 | + |
| 57 | + document.save(new ByteArrayOutputStream()); |
| 58 | + document.close(); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | +} |
0 commit comments