mercredi 30 septembre 2020

Generate checkboxes and read back checkbox state to PDF with PHP

I have the problem, i would generaete checkbox in pdf with php, but if i recheck checkbox state i not found checkboxs.

I tried:

  • TCPDF (Generate)
  • C# (Read, it not found checkbox)
  • Python (Read,Pypdf2, it not found checkbox)

Images:

Files:

PHP checkbox generate code:

$pdf = new \setasign\Fpdi\TcpdfFpdi('L', 'mm', 'A4');
$pages = $pdf->setSourceFile('file://C:/Users/JonDoe/Desktop/sample.pdf');


for ($i = 1; $i <= $pages; $i++)
{
    $pdf->AddPage();
    $page = $pdf->importPage($i);
    $pdf->useTemplate($page, 0, 0);

    $pdf->CheckBox('newsletter', 5, true, array(), array(), 'OK1', 600/5, 500/5, true);
}
$pdf->Output("file://C:/Users/JonDoe/Desktop/sample.pdf", 'F');

Reader script:

C#:

using System;
using iTextSharp.text.pdf;;
using System.Linq;

namespace PDF_Checkbox
{
    class Program
    {

        static void Main(string[] args)
        {

            string path = "C:\\Users\\JonDoe\\Desktop\\sample";
            PdfReader reader2 = new PdfReader(@"" + path + ".pdf");
            var fieldList = GetFormFieldNamesWithValues(reader2);


            Console.WriteLine("============================================================");
            Console.WriteLine("Fields: " + fieldList);
            Console.WriteLine("============================================================");

            Console.ReadKey();
        }

    }
}

Python 3.8:

import PyPDF2 as pypdf

pdfobject=open('sample.pdf','rb')
pdf=pypdf.PdfFileReader(pdfobject)
print(pdf.getFields())

As you read, I want to see the generated checkboxes state, whether python or c #, php Does anyone know a solution for this?




Aucun commentaire:

Enregistrer un commentaire