我需要填写 pdf 表格。为此,我找到并使用了 qPDF c++ 库。
我使用以下命令在 fillPdf.pro 上添加了 libqpdf.dll.a:
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/qpdf/lib/ -llibqpdf.dll
INCLUDEPATH += $$PWD/qpdf
DEPENDPATH += $$PWD/qpdf
我还将 qpdf 库中的所有包含 .h 和 .hh 标头添加到我的项目中。
但我仍然有看起来像链接问题的错误:
.o:-1: In function `ZN8reporter8fillTestEPKcS1_S1_':
.cpp:19: erreur : undefined reference to `QPDF::QPDF()'
.cpp:20: erreur : undefined reference to `QPDF::processFile(char const*, char const*)' ^
.cpp:19: erreur : undefined reference to `QPDF::~QPDF()'
collect2.exe:-1: erreur : error: ld returned 1 exit status
总结代码所有符号都被qt创建者识别,我可以通过点击它们来访问它们:
#include <qpdf/QPDF.hh>
#include <qpdf/QPDFWriter.hh>
#include <qpdf/QUtil.hh>
#include <iostream>
int main(int argc, char* argv[])
{
char* whoami = QUtil::getWhoami(argv[0]);
if (argc != 3)
{
std::cerr << "Usage: " << whoami << " infile outfile" << std::endl;
return 2;
}
char const* infile = argv[1];
char const* outfile = argv[2];
QPDF in;
in.processFile(infile);
int pageno = 0;
std::vector<QPDFObjectHandle> const& pages = in.getAllPages();
for (std::vector<QPDFObjectHandle>::const_iterator iter = pages.begin();
iter != pages.end(); ++iter)
{
std::cout << ++pageno << " ";
QPDFObjectHandle page = *iter;
page.replaceKey(
"/Contents",
QPDFObjectHandle::newStream(&in, "q Q"));
}
QPDFWriter out(in, outfile);
out.write();
return 0;
}
更多信息 :
QPDF WINDOWS Lib : https://sourceforge.net/projects/qpdf/files/qpdf/8.4.0/
includes : https://github.com/qpdf/qpdf/tree/master/include/qpdf
exemple : https://github.com/qpdf/qpdf/blob/master/examples/pdf-set-form-values.cc
我正在使用基于 qt 5.9.1 (MSVC 2015, 32bit) 的 qt creator 4.4.0
有人能告诉我我哪里错了吗?
我的.pro
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG += qt
QT += core gui
QT += axcontainer
QT += serialport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += main.cpp
HEADERS += \
qpdf/Buffer.hh \
qpdf/BufferInputSource.hh \
qpdf/ClosedFileInputSource.hh \
qpdf/Constants.h \
qpdf/DLL.h \
qpdf/FileInputSource.hh \
qpdf/InputSource.hh \
qpdf/JSON.hh \
qpdf/Pipeline.hh \
qpdf/Pl_Buffer.hh \
qpdf/Pl_Concatenate.hh \
qpdf/Pl_Count.hh \
qpdf/Pl_DCT.hh \
qpdf/Pl_Discard.hh \
qpdf/Pl_Flate.hh \
qpdf/Pl_QPDFTokenizer.hh \
qpdf/Pl_RunLength.hh \
qpdf/Pl_StdioFile.hh \
qpdf/PointerHolder.hh \
qpdf/qpdf-c.h \
qpdf/QPDF.hh \
qpdf/QPDFAcroFormDocumentHelper.hh \
qpdf/QPDFAnnotationObjectHelper.hh \
qpdf/QPDFDocumentHelper.hh \
qpdf/QPDFExc.hh \
qpdf/QPDFFormFieldObjectHelper.hh \
qpdf/QPDFNameTreeObjectHelper.hh \
qpdf/QPDFNumberTreeObjectHelper.hh \
qpdf/QPDFObject.hh \
qpdf/QPDFObjectHandle.hh \
qpdf/QPDFObjectHelper.hh \
qpdf/QPDFObjGen.hh \
qpdf/QPDFOutlineDocumentHelper.hh \
qpdf/QPDFOutlineObjectHelper.hh \
qpdf/QPDFPageDocumentHelper.hh \
qpdf/QPDFPageLabelDocumentHelper.hh \
qpdf/QPDFPageObjectHelper.hh \
qpdf/QPDFSystemError.hh \
qpdf/QPDFTokenizer.hh \
qpdf/QPDFWriter.hh \
qpdf/QPDFXRefEntry.hh \
qpdf/QTC.hh \
qpdf/QUtil.hh \
qpdf/RandomDataProvider.hh \
qpdf/Types.h
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/qpdf/lib/ -llibqpdf.dll
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/qpdf/lib/ -llibqpdf.dllINCLUDEPATH += $$PWD/qpdf
DEPENDPATH += $$PWD/qpdf