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

[Feature] QPDFFormFieldObjectHelper setFormFieldName #578

Open
amargerandhw opened this issue Apr 25, 2024 · 4 comments · May be fixed by #580
Open

[Feature] QPDFFormFieldObjectHelper setFormFieldName #578

amargerandhw opened this issue Apr 25, 2024 · 4 comments · May be fixed by #580

Comments

@amargerandhw
Copy link

I would like to add the method setFormFieldName of QPDFAcroFormDocumentHelper :
https://github.com/qpdf/qpdf/blob/main/libqpdf/QPDFAcroFormDocumentHelper.cc#L154
https://github.com/qpdf/qpdf/blob/58c31fdd5e9e633281cb6830d63427da050fbe41/include/qpdf/QPDFAcroFormDocumentHelper.hh#L107

But I dont really know well pybind11, where should I start to make my PR. Is there an example of a method from this QPDF class already implemented ?

@jbarlow83
Copy link
Member

Please see general contributing guidelines.
https://pikepdf.readthedocs.io/en/latest/references/contributing.html

I don't have time or need to implement this feature myself (PDF is too big for one person), but I can support your work on a PR.

embeddedfiles.cpp is probably close as to a template since it creates the pikepdf Attachments class which binds QPDFEmbeddedFileDocumentHelper, and several object QPDF*ObjectHelper classes. At a glance, it's possible a property acroform.cpp would similarly succinct and straightforward - a lot of the time the C++ code is giving Pythonic names to C++ methods.

Object helpers must specify shared_ptr as their holder type or you will get lots of segfaults. Document helper must omit this, because it uses the default unique_ptr. The entire class hierachy has to use the same holder type or everything goes boom.

py::class_<QPDFEFStreamObjectHelper,
        std::shared_ptr<QPDFEFStreamObjectHelper>,  // <--- holder type spec
        QPDFObjectHelper>(m, "AttachedFile")

You'll also to ensure #include <pybind11/stl.h> in the cpp file.

QPDF has several functions that return std::vector<QPDFAnnotationObjectHelper>. That's going to be interesting, because I don't have any other code that specifically returns a vector of object helpers. When #include <pybind11/stl.h> is present pybind11 should (!) pull that std::vector apart and construct a Python list of object helpers. I think the pybind11 defaults should be fine here. But it's possible the wheels could fall off the wagon at this point.

@amargerandhw
Copy link
Author

@jbarlow83 Ok thank you I'll look into it and submit a PR asap

@amargerandhw
Copy link
Author

@jbarlow83

I started to try implementing the method here : https://github.com/pikepdf/pikepdf/pull/580/files

But I dont understand what I'm doing wrong, I have this error message :

      In file included from src/core/acroform.cpp:13:
      /private/var/folders/6q/0czph51n4zs82xv5w7l5c66m0000gn/T/pip-build-env-1zxqsgo5/overlay/lib/python3.12/site-packages/pybind11/include/pybind11/pybind11.h:1572:5: error: static assertion failed due to requirement 'detail::integral_constant<bool, false>::value': Unknown/invalid class_ template parameters provided
          static_assert(detail::all_of<is_valid_class_option<options>...>::value,
          ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      src/core/acroform.cpp:20:5: note: in instantiation of template class 'pybind11::class_<QPDFAcroFormDocumentHelper, std::shared_ptr<QPDFAcroFormDocumentHelper>, QPDFObjectHelper>' requested here
          py::class_<QPDFAcroFormDocumentHelper,
          ^
      src/core/acroform.cpp:23:10: error: no member named 'def' in 'pybind11::class_<QPDFAcroFormDocumentHelper, std::shared_ptr<QPDFAcroFormDocumentHelper>, QPDFObjectHelper>'
              .def(
               ^
      2 errors generated.

Could you help me understand it ? 🙏

@jbarlow83
Copy link
Member

I suspect the error is due to QPDFAcroFormDocumentHelper not being a subclass of QPDFObjectHelper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants