Spaces:
Running
Running
File size: 10,092 Bytes
5cee033 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
#include <QtCore/QCoreApplication>
#include <QtCore/QDateTime>
#include <QtCore/QDebug>
#include <iostream>
#include <poppler-qt6.h>
#include <poppler-form.h>
static std::ostream &operator<<(std::ostream &out, Poppler::FormField::FormType type)
{
switch (type) {
case Poppler::FormField::FormButton:
out << "Button";
break;
case Poppler::FormField::FormText:
out << "Text";
break;
case Poppler::FormField::FormChoice:
out << "Choice";
break;
case Poppler::FormField::FormSignature:
out << "Signature";
break;
}
return out;
}
static std::ostream &operator<<(std::ostream &out, Poppler::FormFieldButton::ButtonType type)
{
switch (type) {
case Poppler::FormFieldButton::Push:
out << "Push";
break;
case Poppler::FormFieldButton::CheckBox:
out << "CheckBox";
break;
case Poppler::FormFieldButton::Radio:
out << "Radio";
break;
}
return out;
}
static std::ostream &operator<<(std::ostream &out, Poppler::FormFieldText::TextType type)
{
switch (type) {
case Poppler::FormFieldText::Normal:
out << "Normal";
break;
case Poppler::FormFieldText::Multiline:
out << "Multiline";
break;
case Poppler::FormFieldText::FileSelect:
out << "FileSelect";
break;
}
return out;
}
static std::ostream &operator<<(std::ostream &out, Poppler::FormFieldChoice::ChoiceType type)
{
switch (type) {
case Poppler::FormFieldChoice::ComboBox:
out << "ComboBox";
break;
case Poppler::FormFieldChoice::ListBox:
out << "ListBox";
break;
}
return out;
}
static std::ostream &operator<<(std::ostream &out, Poppler::SignatureValidationInfo::SignatureStatus status)
{
switch (status) {
case Poppler::SignatureValidationInfo::SignatureValid:
out << "Valid";
break;
case Poppler::SignatureValidationInfo::SignatureInvalid:
out << "Invalid";
break;
case Poppler::SignatureValidationInfo::SignatureDigestMismatch:
out << "DigestMismatch";
break;
case Poppler::SignatureValidationInfo::SignatureDecodingError:
out << "DecodingError";
break;
case Poppler::SignatureValidationInfo::SignatureGenericError:
out << "GenericError";
break;
case Poppler::SignatureValidationInfo::SignatureNotFound:
out << "NotFound";
break;
case Poppler::SignatureValidationInfo::SignatureNotVerified:
out << "NotVerifiedYet";
break;
}
return out;
}
static std::ostream &operator<<(std::ostream &out, Poppler::SignatureValidationInfo::CertificateStatus status)
{
switch (status) {
case Poppler::SignatureValidationInfo::CertificateTrusted:
out << "Trusted";
break;
case Poppler::SignatureValidationInfo::CertificateUntrustedIssuer:
out << "UntrustedIssuer";
break;
case Poppler::SignatureValidationInfo::CertificateUnknownIssuer:
out << "UnknownIssuer";
break;
case Poppler::SignatureValidationInfo::CertificateRevoked:
out << "Revoked";
break;
case Poppler::SignatureValidationInfo::CertificateExpired:
out << "Expired";
break;
case Poppler::SignatureValidationInfo::CertificateGenericError:
out << "GenericError";
break;
case Poppler::SignatureValidationInfo::CertificateNotVerified:
out << "NotVerifiedYet";
break;
case Poppler::SignatureValidationInfo::CertificateVerificationInProgress:
out << "InProgress";
}
return out;
}
static std::ostream &operator<<(std::ostream &out, Qt::Alignment alignment)
{
switch (alignment) {
case Qt::AlignLeft:
out << "Left";
break;
case Qt::AlignRight:
out << "Right";
break;
case Qt::AlignHCenter:
out << "HCenter";
break;
case Qt::AlignJustify:
out << "Justify";
break;
case Qt::AlignTop:
out << "Top";
break;
case Qt::AlignBottom:
out << "Bottom";
break;
case Qt::AlignVCenter:
out << "VCenter";
break;
case Qt::AlignCenter:
out << "Center";
break;
case Qt::AlignAbsolute:
out << "Absolute";
break;
}
return out;
}
static std::ostream &operator<<(std::ostream &out, const QString &string)
{
out << string.toUtf8().constData();
return out;
}
static std::ostream &operator<<(std::ostream &out, const QRectF &rect)
{
out << QStringLiteral("top: %1 left: %2 width: %3 height: %4").arg(rect.x()).arg(rect.y()).arg(rect.width()).arg(rect.height());
return out;
}
template<typename T>
std::ostream &operator<<(std::ostream &out, const QList<T> &elems)
{
bool isFirst = true;
for (int i = 0; i < elems.count(); ++i) {
if (!isFirst) {
out << " ";
}
out << elems[i];
isFirst = false;
}
return out;
}
int main(int argc, char **argv)
{
QCoreApplication a(argc, argv);
if (!(argc == 2)) {
qWarning() << "usage: poppler-forms filename";
exit(1);
}
std::unique_ptr<Poppler::Document> doc = Poppler::Document::load(argv[1]);
if (!doc) {
qWarning() << "doc not loaded";
exit(1);
}
std::cout << "Forms for file " << argv[1] << std::endl;
for (int i = 0; i < doc->numPages(); ++i) {
std::unique_ptr<Poppler::Page> page = doc->page(i);
if (page) {
std::vector<std::unique_ptr<Poppler::FormField>> forms = page->formFields();
std::cout << "\tPage " << i + 1 << std::endl;
for (const std::unique_ptr<Poppler::FormField> &form : forms) {
std::cout << "\t\tForm" << std::endl;
std::cout << "\t\t\tType: " << form->type() << std::endl;
std::cout << "\t\t\tRect: " << form->rect() << std::endl;
std::cout << "\t\t\tID: " << form->id() << std::endl;
std::cout << "\t\t\tName: " << form->name() << std::endl;
std::cout << "\t\t\tFullyQualifiedName: " << form->fullyQualifiedName() << std::endl;
std::cout << "\t\t\tUIName: " << form->uiName() << std::endl;
std::cout << "\t\t\tReadOnly: " << form->isReadOnly() << std::endl;
std::cout << "\t\t\tVisible: " << form->isVisible() << std::endl;
switch (form->type()) {
case Poppler::FormField::FormButton: {
const Poppler::FormFieldButton *buttonForm = static_cast<const Poppler::FormFieldButton *>(form.get());
std::cout << "\t\t\tButtonType: " << buttonForm->buttonType() << std::endl;
std::cout << "\t\t\tCaption: " << buttonForm->caption() << std::endl;
std::cout << "\t\t\tState: " << buttonForm->state() << std::endl;
std::cout << "\t\t\tSiblings: " << buttonForm->siblings() << std::endl;
} break;
case Poppler::FormField::FormText: {
const Poppler::FormFieldText *textForm = static_cast<const Poppler::FormFieldText *>(form.get());
std::cout << "\t\t\tTextType: " << textForm->textType() << std::endl;
std::cout << "\t\t\tText: " << textForm->text() << std::endl;
std::cout << "\t\t\tIsPassword: " << textForm->isPassword() << std::endl;
std::cout << "\t\t\tIsRichText: " << textForm->isRichText() << std::endl;
std::cout << "\t\t\tMaximumLength: " << textForm->maximumLength() << std::endl;
std::cout << "\t\t\tTextAlignment: " << textForm->textAlignment() << std::endl;
std::cout << "\t\t\tCanBeSpellChecked: " << textForm->canBeSpellChecked() << std::endl;
} break;
case Poppler::FormField::FormChoice: {
const Poppler::FormFieldChoice *choiceForm = static_cast<const Poppler::FormFieldChoice *>(form.get());
std::cout << "\t\t\tChoiceType: " << choiceForm->choiceType() << std::endl;
std::cout << "\t\t\tChoices: " << choiceForm->choices() << std::endl;
std::cout << "\t\t\tIsEditable: " << choiceForm->isEditable() << std::endl;
std::cout << "\t\t\tIsMultiSelect: " << choiceForm->multiSelect() << std::endl;
std::cout << "\t\t\tCurrentChoices: " << choiceForm->currentChoices() << std::endl;
std::cout << "\t\t\tEditChoice: " << choiceForm->editChoice() << std::endl;
std::cout << "\t\t\tTextAlignment: " << choiceForm->textAlignment() << std::endl;
std::cout << "\t\t\tCanBeSpellChecked: " << choiceForm->canBeSpellChecked() << std::endl;
} break;
case Poppler::FormField::FormSignature: {
const Poppler::FormFieldSignature *signatureForm = static_cast<const Poppler::FormFieldSignature *>(form.get());
const Poppler::SignatureValidationInfo svi = signatureForm->validate(Poppler::FormFieldSignature::ValidateVerifyCertificate);
std::cout << "\t\t\tSignatureStatus: " << svi.signatureStatus() << std::endl;
std::cout << "\t\t\tCertificateStatus: " << svi.certificateStatus() << std::endl;
if (svi.signerName().isEmpty() == false) {
std::cout << "\t\t\tSignerName: " << svi.signerName() << std::endl;
} else {
std::cout << "\t\t\tSignerName: "
<< "(null)" << std::endl;
}
const QDateTime sviTime = QDateTime::fromSecsSinceEpoch(svi.signingTime(), Qt::UTC);
std::cout << "\t\t\tSigningTime: " << sviTime.toString() << std::endl;
} break;
}
}
}
}
}
|