Я использую iText в моей java-программе для редактирования существующего PDF-файла. Сгенерированный PDF-файл не может быть открыт, и он показывает ошибку подписи PDF-файла, не найденную. Я использую оба моих входных и выходных файла с одним и тем же именем.
private static String INPUTFILE = "/sample.pdf";
private static String OUTPUTFILE = "/sample.pdf";
public static void main(String[] args)
throws DocumentException,
IOException
{
Document doc = new Document();
PdfWriter writer = PdfWriter.getInstance(doc,new FileOutputStream(OUTPUTFILE));
doc.open();
PdfReader reader = new PdfReader(INPUTFILE);
int n;
n = reader.getNumberOfPages();
System.out.println("No. of Pages :" +n);
for (int i = 1; i <= n; i++)
{
if (i == 1)
{
Rectangle rect = new Rectangle(85,650,800,833);
PdfFormField pushbutton = PdfFormField.createPushButton(writer);
pushbutton.setWidget(rect, PdfAnnotation.HIGHLIGHT_PUSH);
PdfContentByte cb = writer.getDirectContent();
PdfAppearance app = cb.createAppearance(380,201);
app.rectangle(62,100,50,-1);
app.fill();
pushbutton.setAppearance(PdfAnnotation.APPEARANCE_NORMAL,app);
writer.addAnnotation(pushbutton);
PdfImportedPage page = writer.getImportedPage(reader, i);
Image instance = Image.getInstance(page);
doc.add(instance);
}