Create a new blank document

This commit is contained in:
Jakub Melka 2020-03-22 15:30:34 +01:00
parent 1af6cf0c31
commit fcaa288c5b
14 changed files with 1308 additions and 452 deletions

View File

@ -251,7 +251,7 @@ void CodeGenerator::generateCode(QString headerName, QString sourceName) const
QFile headerFile(headerName); QFile headerFile(headerName);
if (headerFile.exists()) if (headerFile.exists())
{ {
if (headerFile.open(QFile::ReadOnly)) if (headerFile.open(QFile::ReadOnly | QFile::Text))
{ {
QString utfCode = QString::fromUtf8(headerFile.readAll()); QString utfCode = QString::fromUtf8(headerFile.readAll());
headerFile.close(); headerFile.close();
@ -273,7 +273,7 @@ void CodeGenerator::generateCode(QString headerName, QString sourceName) const
QFile sourceFile(sourceName); QFile sourceFile(sourceName);
if (sourceFile.exists()) if (sourceFile.exists())
{ {
if (sourceFile.open(QFile::ReadOnly)) if (sourceFile.open(QFile::ReadOnly | QFile::Text))
{ {
QString utfCode = QString::fromUtf8(sourceFile.readAll()); QString utfCode = QString::fromUtf8(sourceFile.readAll());
sourceFile.close(); sourceFile.close();

View File

@ -0,0 +1,37 @@
QT += gui
CONFIG += c++11 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
QMAKE_CXXFLAGS += /std:c++latest /utf-8
INCLUDEPATH += $$PWD/../PDFForQtLib/Sources
DESTDIR = $$OUT_PWD/..
LIBS += -L$$OUT_PWD/..
LIBS += -lPDFForQtLib
SOURCES += \
main.cpp \
pdfexamplesgenerator.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
pdfexamplesgenerator.h

View File

@ -0,0 +1,26 @@
// Copyright (C) 2020 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#include <QCoreApplication>
#include "pdfexamplesgenerator.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
PDFExamplesGenerator::generateAnnotationsExample();
}

View File

@ -0,0 +1,33 @@
// Copyright (C) 2020 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#include "pdfexamplesgenerator.h"
#include "pdfdocumentbuilder.h"
#include "pdfdocumentwriter.h"
void PDFExamplesGenerator::generateAnnotationsExample()
{
pdf::PDFDocumentBuilder builder;
builder.appendPage(QRectF(0, 0, 400, 400));
// Write result to a file
pdf::PDFDocument document = builder.build();
pdf::PDFDocumentWriter writer(nullptr);
writer.write("Ex_Annotations.pdf", &document);
}

View File

@ -0,0 +1,29 @@
// Copyright (C) 2020 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#ifndef PDFEXAMPLESGENERATOR_H
#define PDFEXAMPLESGENERATOR_H
class PDFExamplesGenerator
{
public:
explicit PDFExamplesGenerator() = delete;
static void generateAnnotationsExample();
};
#endif // PDFEXAMPLESGENERATOR_H

View File

@ -20,6 +20,7 @@ TEMPLATE = subdirs
SUBDIRS += \ SUBDIRS += \
CodeGenerator \ CodeGenerator \
JBIG2_Viewer \ JBIG2_Viewer \
PdfExampleGenerator \
PdfForQtLib \ PdfForQtLib \
UnitTests \ UnitTests \
PdfForQtViewer PdfForQtViewer
@ -27,3 +28,4 @@ SUBDIRS += \
UnitTests.depends = PdfForQtLib UnitTests.depends = PdfForQtLib
PdfForQtViewer.depends = PdfForQtLib PdfForQtViewer.depends = PdfForQtLib
JBIG2_Viewer.depends = PdfForQtLib JBIG2_Viewer.depends = PdfForQtLib
PDFExampleGenerator.depends = PdfForQtLib

View File

@ -43,6 +43,7 @@ SOURCES += \
sources/pdfcms.cpp \ sources/pdfcms.cpp \
sources/pdfcompiler.cpp \ sources/pdfcompiler.cpp \
sources/pdfdocumentbuilder.cpp \ sources/pdfdocumentbuilder.cpp \
sources/pdfdocumentwriter.cpp \
sources/pdfexecutionpolicy.cpp \ sources/pdfexecutionpolicy.cpp \
sources/pdffile.cpp \ sources/pdffile.cpp \
sources/pdfitemmodels.cpp \ sources/pdfitemmodels.cpp \
@ -90,6 +91,7 @@ HEADERS += \
sources/pdfcompiler.h \ sources/pdfcompiler.h \
sources/pdfdocumentbuilder.h \ sources/pdfdocumentbuilder.h \
sources/pdfdocumentdrawinterface.h \ sources/pdfdocumentdrawinterface.h \
sources/pdfdocumentwriter.h \
sources/pdfexecutionpolicy.h \ sources/pdfexecutionpolicy.h \
sources/pdffile.h \ sources/pdffile.h \
sources/pdfitemmodels.h \ sources/pdfitemmodels.h \

View File

@ -78,6 +78,9 @@ public:
/// Returns security handler associated with these objects /// Returns security handler associated with these objects
const PDFSecurityHandler* getSecurityHandler() const { return m_securityHandler.data(); } const PDFSecurityHandler* getSecurityHandler() const { return m_securityHandler.data(); }
/// Sets security handler associated with these objects
void setSecurityHandler(PDFSecurityHandlerPointer handler) { m_securityHandler = qMove(handler); }
/// Adds a new object to the object list. This function /// Adds a new object to the object list. This function
/// is not thread safe, do not call it from multiple threads. /// is not thread safe, do not call it from multiple threads.
/// \param object Object to be added /// \param object Object to be added

View File

@ -1,272 +1,320 @@
// Copyright (C) 2020 Jakub Melka // Copyright (C) 2020 Jakub Melka
// //
// This file is part of PdfForQt. // This file is part of PdfForQt.
// //
// PdfForQt is free software: you can redistribute it and/or modify // PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by // it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// PdfForQt is distributed in the hope that it will be useful, // PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details. // GNU Lesser General Public License for more details.
// //
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>. // along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#include "pdfdocumentbuilder.h" #include "pdfdocumentbuilder.h"
#include "pdfencoding.h" #include "pdfencoding.h"
#include "pdfconstants.h" #include "pdfconstants.h"
namespace pdf namespace pdf
{ {
void PDFObjectFactory::beginArray() void PDFObjectFactory::beginArray()
{ {
m_items.emplace_back(ItemType::Array, PDFArray()); m_items.emplace_back(ItemType::Array, PDFArray());
} }
void PDFObjectFactory::endArray() void PDFObjectFactory::endArray()
{ {
Item topItem = qMove(m_items.back()); Item topItem = qMove(m_items.back());
Q_ASSERT(topItem.type == ItemType::Array); Q_ASSERT(topItem.type == ItemType::Array);
m_items.pop_back(); m_items.pop_back();
addObject(PDFObject::createArray(std::make_shared<PDFArray>(qMove(std::get<PDFArray>(topItem.object))))); addObject(PDFObject::createArray(std::make_shared<PDFArray>(qMove(std::get<PDFArray>(topItem.object)))));
} }
void PDFObjectFactory::beginDictionary() void PDFObjectFactory::beginDictionary()
{ {
m_items.emplace_back(ItemType::Dictionary, PDFDictionary()); m_items.emplace_back(ItemType::Dictionary, PDFDictionary());
} }
void PDFObjectFactory::endDictionary() void PDFObjectFactory::endDictionary()
{ {
Item topItem = qMove(m_items.back()); Item topItem = qMove(m_items.back());
Q_ASSERT(topItem.type == ItemType::Dictionary); Q_ASSERT(topItem.type == ItemType::Dictionary);
m_items.pop_back(); m_items.pop_back();
addObject(PDFObject::createDictionary(std::make_shared<PDFDictionary>(qMove(std::get<PDFDictionary>(topItem.object))))); addObject(PDFObject::createDictionary(std::make_shared<PDFDictionary>(qMove(std::get<PDFDictionary>(topItem.object)))));
} }
void PDFObjectFactory::beginDictionaryItem(const QByteArray& name) void PDFObjectFactory::beginDictionaryItem(const QByteArray& name)
{ {
m_items.emplace_back(ItemType::DictionaryItem, name, PDFObject()); m_items.emplace_back(ItemType::DictionaryItem, name, PDFObject());
} }
void PDFObjectFactory::endDictionaryItem() void PDFObjectFactory::endDictionaryItem()
{ {
Item topItem = qMove(m_items.back()); Item topItem = qMove(m_items.back());
Q_ASSERT(topItem.type == ItemType::DictionaryItem); Q_ASSERT(topItem.type == ItemType::DictionaryItem);
m_items.pop_back(); m_items.pop_back();
Item& dictionaryItem = m_items.back(); Item& dictionaryItem = m_items.back();
Q_ASSERT(dictionaryItem.type == ItemType::Dictionary); Q_ASSERT(dictionaryItem.type == ItemType::Dictionary);
std::get<PDFDictionary>(dictionaryItem.object).addEntry(qMove(topItem.itemName), qMove(std::get<PDFObject>(topItem.object))); std::get<PDFDictionary>(dictionaryItem.object).addEntry(qMove(topItem.itemName), qMove(std::get<PDFObject>(topItem.object)));
} }
PDFObjectFactory& PDFObjectFactory::operator<<(QString textString) PDFObjectFactory& PDFObjectFactory::operator<<(WrapEmptyArray)
{ {
if (!PDFEncoding::canConvertToEncoding(textString, PDFEncoding::Encoding::PDFDoc)) beginArray();
{ endArray();
// Use unicode encoding return *this;
QByteArray ba; }
{ PDFObjectFactory& PDFObjectFactory::operator<<(QString textString)
QTextStream textStream(&ba, QIODevice::WriteOnly); {
textStream.setCodec("UTF-16BE"); if (!PDFEncoding::canConvertToEncoding(textString, PDFEncoding::Encoding::PDFDoc))
textStream.setGenerateByteOrderMark(true); {
textStream << textString; // Use unicode encoding
} QByteArray ba;
addObject(PDFObject::createString(std::make_shared<PDFString>(qMove(ba)))); {
} QTextStream textStream(&ba, QIODevice::WriteOnly);
else textStream.setCodec("UTF-16BE");
{ textStream.setGenerateByteOrderMark(true);
// Use PDF document encoding textStream << textString;
addObject(PDFObject::createString(std::make_shared<PDFString>(PDFEncoding::convertToEncoding(textString, PDFEncoding::Encoding::PDFDoc)))); }
}
addObject(PDFObject::createString(std::make_shared<PDFString>(qMove(ba))));
return *this; }
} else
{
PDFObjectFactory& PDFObjectFactory::operator<<(WrapAnnotationColor color) // Use PDF document encoding
{ addObject(PDFObject::createString(std::make_shared<PDFString>(PDFEncoding::convertToEncoding(textString, PDFEncoding::Encoding::PDFDoc))));
if (color.color.isValid()) }
{
// Jakub Melka: we will decide, if we have gray/rgb/cmyk color return *this;
QColor value = color.color; }
if (value.spec() == QColor::Cmyk)
{ PDFObjectFactory& PDFObjectFactory::operator<<(WrapAnnotationColor color)
*this << std::initializer_list<PDFReal>{ value.cyanF(), value.magentaF(), value.yellowF(), value.blackF() }; {
} if (color.color.isValid())
else if (qIsGray(value.rgb())) {
{ // Jakub Melka: we will decide, if we have gray/rgb/cmyk color
*this << std::initializer_list<PDFReal>{ value.redF() }; QColor value = color.color;
} if (value.spec() == QColor::Cmyk)
else {
{ *this << std::initializer_list<PDFReal>{ value.cyanF(), value.magentaF(), value.yellowF(), value.blackF() };
*this << std::initializer_list<PDFReal>{ value.redF(), value.greenF(), value.blueF() }; }
} else if (qIsGray(value.rgb()))
} {
else *this << std::initializer_list<PDFReal>{ value.redF() };
{ }
addObject(PDFObject::createNull()); else
} {
*this << std::initializer_list<PDFReal>{ value.redF(), value.greenF(), value.blueF() };
return *this; }
} }
else
PDFObjectFactory& PDFObjectFactory::operator<<(WrapCurrentDateTime) {
{ addObject(PDFObject::createNull());
addObject(PDFObject::createString(std::make_shared<PDFString>(PDFEncoding::converDateTimeToString(QDateTime::currentDateTime())))); }
return *this;
} return *this;
}
PDFObjectFactory& PDFObjectFactory::operator<<(const QRectF& value)
{ PDFObjectFactory& PDFObjectFactory::operator<<(WrapCurrentDateTime)
*this << std::initializer_list<PDFReal>{ value.left(), value.top(), value.right(), value.bottom() }; {
return *this; addObject(PDFObject::createString(std::make_shared<PDFString>(PDFEncoding::converDateTimeToString(QDateTime::currentDateTime()))));
} return *this;
}
PDFObjectFactory& PDFObjectFactory::operator<<(int value)
{ PDFObjectFactory& PDFObjectFactory::operator<<(const QRectF& value)
*this << PDFInteger(value); {
return *this; *this << std::initializer_list<PDFReal>{ value.left(), value.top(), value.right(), value.bottom() };
} return *this;
}
PDFObjectFactory& PDFObjectFactory::operator<<(WrapName wrapName)
{ PDFObjectFactory& PDFObjectFactory::operator<<(int value)
addObject(PDFObject::createName(std::make_shared<PDFString>(qMove(wrapName.name)))); {
return *this; *this << PDFInteger(value);
} return *this;
}
PDFObject PDFObjectFactory::takeObject()
{ PDFObjectFactory& PDFObjectFactory::operator<<(WrapName wrapName)
Q_ASSERT(m_items.size() == 1); {
Q_ASSERT(m_items.back().type == ItemType::Object); addObject(PDFObject::createName(std::make_shared<PDFString>(qMove(wrapName.name))));
PDFObject result = qMove(std::get<PDFObject>(m_items.back().object)); return *this;
m_items.clear(); }
return result;
} PDFObject PDFObjectFactory::takeObject()
{
void PDFObjectFactory::addObject(PDFObject object) Q_ASSERT(m_items.size() == 1);
{ Q_ASSERT(m_items.back().type == ItemType::Object);
if (m_items.empty()) PDFObject result = qMove(std::get<PDFObject>(m_items.back().object));
{ m_items.clear();
m_items.emplace_back(ItemType::Object, qMove(object)); return result;
return; }
}
void PDFObjectFactory::addObject(PDFObject object)
Item& topItem = m_items.back(); {
switch (topItem.type) if (m_items.empty())
{ {
case ItemType::Object: m_items.emplace_back(ItemType::Object, qMove(object));
// Just override the object return;
topItem.object = qMove(object); }
break;
Item& topItem = m_items.back();
case ItemType::Dictionary: switch (topItem.type)
// Do not do anything - we are inside dictionary {
break; case ItemType::Object:
// Just override the object
case ItemType::DictionaryItem: topItem.object = qMove(object);
// Add item to dictionary item break;
topItem.object = qMove(object);
break; case ItemType::Dictionary:
// Do not do anything - we are inside dictionary
case ItemType::Array: break;
std::get<PDFArray>(topItem.object).appendItem(qMove(object));
break; case ItemType::DictionaryItem:
// Add item to dictionary item
default: topItem.object = qMove(object);
Q_ASSERT(false); break;
break;
} case ItemType::Array:
} std::get<PDFArray>(topItem.object).appendItem(qMove(object));
break;
PDFObjectFactory& PDFObjectFactory::operator<<(std::nullptr_t)
{ default:
addObject(PDFObject::createNull()); Q_ASSERT(false);
return *this; break;
} }
}
PDFObjectFactory& PDFObjectFactory::operator<<(bool value)
{ PDFObjectFactory& PDFObjectFactory::operator<<(std::nullptr_t)
addObject(PDFObject::createBool(value)); {
return *this; addObject(PDFObject::createNull());
} return *this;
}
PDFObjectFactory& PDFObjectFactory::operator<<(PDFReal value)
{ PDFObjectFactory& PDFObjectFactory::operator<<(bool value)
addObject(PDFObject::createReal(value)); {
return *this; addObject(PDFObject::createBool(value));
} return *this;
}
PDFObjectFactory& PDFObjectFactory::operator<<(PDFInteger value)
{ PDFObjectFactory& PDFObjectFactory::operator<<(PDFReal value)
addObject(PDFObject::createInteger(value)); {
return *this; addObject(PDFObject::createReal(value));
} return *this;
}
PDFObjectFactory& PDFObjectFactory::operator<<(PDFObjectReference value)
{ PDFObjectFactory& PDFObjectFactory::operator<<(PDFInteger value)
addObject(PDFObject::createReference(value)); {
return *this; addObject(PDFObject::createInteger(value));
} return *this;
}
PDFDocumentBuilder::PDFDocumentBuilder() :
m_version(1, 7) PDFObjectFactory& PDFObjectFactory::operator<<(PDFObjectReference value)
{ {
createDocument(); addObject(PDFObject::createReference(value));
} return *this;
}
PDFDocumentBuilder::PDFDocumentBuilder(const PDFDocument* document) :
m_storage(document->getStorage()), PDFDocumentBuilder::PDFDocumentBuilder() :
m_version(document->getInfo()->version) m_version(1, 7)
{ {
createDocument();
} }
void PDFDocumentBuilder::reset() PDFDocumentBuilder::PDFDocumentBuilder(const PDFDocument* document) :
{ m_storage(document->getStorage()),
*this = PDFDocumentBuilder(); m_version(document->getInfo()->version)
} {
void PDFDocumentBuilder::createDocument() }
{
reset(); void PDFDocumentBuilder::reset()
{
PDFObjectReference catalog = createCatalog(); *this = PDFDocumentBuilder();
PDFObject trailerDictionary = createTrailerDictionary(catalog); }
m_storage.updateTrailerDictionary(trailerDictionary);
} void PDFDocumentBuilder::createDocument()
{
PDFDocument PDFDocumentBuilder::build() if (!m_storage.getObjects().empty())
{ {
updateTrailerDictionary(m_storage.getObjects().size()); reset();
return PDFDocument(PDFObjectStorage(m_storage), m_version); }
}
addObject(PDFObject::createNull());
PDFObjectReference PDFDocumentBuilder::addObject(PDFObject object) PDFObjectReference catalog = createCatalog();
{ PDFObject trailerDictionary = createTrailerDictionary(catalog);
return m_storage.addObject(PDFObjectManipulator::removeNullObjects(object)); m_storage.updateTrailerDictionary(trailerDictionary);
} m_storage.setSecurityHandler(PDFSecurityHandlerPointer(new PDFNoneSecurityHandler()));
}
void PDFDocumentBuilder::mergeTo(PDFObjectReference reference, PDFObject object)
{ PDFDocument PDFDocumentBuilder::build()
m_storage.setObject(reference, PDFObjectManipulator::merge(m_storage.getObject(reference), qMove(object), PDFObjectManipulator::RemoveNullObjects)); {
} updateTrailerDictionary(m_storage.getObjects().size());
return PDFDocument(PDFObjectStorage(m_storage), m_version);
QRectF PDFDocumentBuilder::getPopupWindowRect(const QRectF& rectangle) const }
{
return rectangle.translated(rectangle.width() * 1.25, 0); PDFObjectReference PDFDocumentBuilder::addObject(PDFObject object)
} {
return m_storage.addObject(PDFObjectManipulator::removeNullObjects(object));
QString PDFDocumentBuilder::getProducerString() const }
{
return PDF_LIBRARY_NAME; void PDFDocumentBuilder::mergeTo(PDFObjectReference reference, PDFObject object)
} {
m_storage.setObject(reference, PDFObjectManipulator::merge(m_storage.getObject(reference), qMove(object), PDFObjectManipulator::RemoveNullObjects));
}
void PDFDocumentBuilder::appendTo(PDFObjectReference reference, PDFObject object)
{
m_storage.setObject(reference, PDFObjectManipulator::merge(m_storage.getObject(reference), qMove(object), PDFObjectManipulator::ConcatenateArrays));
}
QRectF PDFDocumentBuilder::getPopupWindowRect(const QRectF& rectangle) const
{
return rectangle.translated(rectangle.width() * 1.25, 0);
}
QString PDFDocumentBuilder::getProducerString() const
{
return PDF_LIBRARY_NAME;
}
PDFObjectReference PDFDocumentBuilder::getPageTreeRoot() const
{
if (const PDFDictionary* trailerDictionary = getDictionaryFromObject(m_storage.getTrailerDictionary()))
{
if (const PDFDictionary* catalogDictionary = getDictionaryFromObject(trailerDictionary->get("Root")))
{
PDFObject pagesRoot = catalogDictionary->get("Pages");
if (pagesRoot.isReference())
{
return pagesRoot.getReference();
}
}
}
return PDFObjectReference();
}
PDFInteger PDFDocumentBuilder::getPageTreeRootChildCount() const
{
if (const PDFDictionary* pageTreeRootDictionary = getDictionaryFromObject(getObjectByReference(getPageTreeRoot())))
{
PDFObject childCountObject = getObject(pageTreeRootDictionary->get("Count"));
if (childCountObject.isInt())
{
return childCountObject.getInteger();
}
}
return 0;
}
/* START GENERATED CODE */ /* START GENERATED CODE */
PDFObjectReference PDFDocumentBuilder::createAnnotationSquare(PDFObjectReference page, PDFObjectReference PDFDocumentBuilder::createAnnotationSquare(PDFObjectReference page,
@ -369,6 +417,9 @@ PDFObjectReference PDFDocumentBuilder::createCatalog()
objectBuilder.beginDictionaryItem("Type"); objectBuilder.beginDictionaryItem("Type");
objectBuilder << WrapName("Catalog"); objectBuilder << WrapName("Catalog");
objectBuilder.endDictionaryItem(); objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Pages");
objectBuilder << createCatalogPageTreeRoot();
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary(); objectBuilder.endDictionary();
PDFObjectReference catalogReference = addObject(objectBuilder.takeObject()); PDFObjectReference catalogReference = addObject(objectBuilder.takeObject());
return catalogReference; return catalogReference;
@ -429,6 +480,58 @@ void PDFDocumentBuilder::updateTrailerDictionary(PDFInteger objectCount)
} }
/* END GENERATED CODE */ PDFObjectReference PDFDocumentBuilder::appendPage(QRectF mediaBox)
{
} // namespace pdf PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Type");
objectBuilder << WrapName("Page");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Parent");
objectBuilder << getPageTreeRoot();
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionary();
objectBuilder.endDictionary();
objectBuilder.beginDictionaryItem("MediaBox");
objectBuilder << mediaBox;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObjectReference pageReference = addObject(objectBuilder.takeObject());
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Kids");
objectBuilder << std::initializer_list<PDFObjectReference>{ pageReference };
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Count");
objectBuilder << getPageTreeRootChildCount() + 1;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObject updatedTreeRoot = objectBuilder.takeObject();
appendTo(getPageTreeRoot(), updatedTreeRoot);
return pageReference;
}
PDFObjectReference PDFDocumentBuilder::createCatalogPageTreeRoot()
{
PDFObjectFactory objectBuilder;
objectBuilder.beginDictionary();
objectBuilder.beginDictionaryItem("Type");
objectBuilder << WrapName("Pages");
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Kids");
objectBuilder << WrapEmptyArray();
objectBuilder.endDictionaryItem();
objectBuilder.beginDictionaryItem("Count");
objectBuilder << 0;
objectBuilder.endDictionaryItem();
objectBuilder.endDictionary();
PDFObjectReference pageTreeRoot = addObject(objectBuilder.takeObject());
return pageTreeRoot;
}
/* END GENERATED CODE */
} // namespace pdf

View File

@ -1,165 +1,183 @@
// Copyright (C) 2020 Jakub Melka // Copyright (C) 2020 Jakub Melka
// //
// This file is part of PdfForQt. // This file is part of PdfForQt.
// //
// PdfForQt is free software: you can redistribute it and/or modify // PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by // it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// PdfForQt is distributed in the hope that it will be useful, // PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details. // GNU Lesser General Public License for more details.
// //
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>. // along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#ifndef PDFDOCUMENTBUILDER_H #ifndef PDFDOCUMENTBUILDER_H
#define PDFDOCUMENTBUILDER_H #define PDFDOCUMENTBUILDER_H
#include "pdfobject.h" #include "pdfobject.h"
#include "pdfdocument.h" #include "pdfdocument.h"
namespace pdf namespace pdf
{ {
struct WrapName struct WrapName
{ {
WrapName(const char* name) : WrapName(const char* name) :
name(name) name(name)
{ {
} }
QByteArray name; QByteArray name;
}; };
struct WrapAnnotationColor struct WrapAnnotationColor
{ {
WrapAnnotationColor(QColor color) : WrapAnnotationColor(QColor color) :
color(color) color(color)
{ {
} }
QColor color; QColor color;
}; };
struct WrapCurrentDateTime { }; struct WrapCurrentDateTime { };
struct WrapEmptyArray { };
/// Factory for creating various PDF objects, such as simple objects,
/// dictionaries, arrays etc. /// Factory for creating various PDF objects, such as simple objects,
class PDFObjectFactory /// dictionaries, arrays etc.
{ class PDFObjectFactory
public: {
inline explicit PDFObjectFactory() = default; public:
inline explicit PDFObjectFactory() = default;
void beginArray();
void endArray(); void beginArray();
void endArray();
void beginDictionary();
void endDictionary(); void beginDictionary();
void endDictionary();
void beginDictionaryItem(const QByteArray& name);
void endDictionaryItem(); void beginDictionaryItem(const QByteArray& name);
void endDictionaryItem();
PDFObjectFactory& operator<<(std::nullptr_t);
PDFObjectFactory& operator<<(bool value); PDFObjectFactory& operator<<(std::nullptr_t);
PDFObjectFactory& operator<<(PDFReal value); PDFObjectFactory& operator<<(bool value);
PDFObjectFactory& operator<<(PDFInteger value); PDFObjectFactory& operator<<(PDFReal value);
PDFObjectFactory& operator<<(PDFObjectReference value); PDFObjectFactory& operator<<(PDFInteger value);
PDFObjectFactory& operator<<(WrapName wrapName); PDFObjectFactory& operator<<(PDFObjectReference value);
PDFObjectFactory& operator<<(int value); PDFObjectFactory& operator<<(WrapName wrapName);
PDFObjectFactory& operator<<(const QRectF& value); PDFObjectFactory& operator<<(int value);
PDFObjectFactory& operator<<(WrapCurrentDateTime); PDFObjectFactory& operator<<(const QRectF& value);
PDFObjectFactory& operator<<(WrapAnnotationColor color); PDFObjectFactory& operator<<(WrapCurrentDateTime);
PDFObjectFactory& operator<<(QString textString); PDFObjectFactory& operator<<(WrapAnnotationColor color);
PDFObjectFactory& operator<<(QString textString);
/// Treat containers - write them as array PDFObjectFactory& operator<<(WrapEmptyArray);
template<typename Container, typename ValueType = decltype(*std::begin(std::declval<Container>()))>
PDFObjectFactory& operator<<(Container container) /// Treat containers - write them as array
{ template<typename Container, typename ValueType = decltype(*std::begin(std::declval<Container>()))>
beginArray(); PDFObjectFactory& operator<<(Container container)
{
auto it = std::begin(container); beginArray();
auto itEnd = std::end(container);
for (; it != itEnd; ++it) auto it = std::begin(container);
{ auto itEnd = std::end(container);
*this << *it; for (; it != itEnd; ++it)
} {
*this << *it;
endArray(); }
return *this; endArray();
}
return *this;
PDFObject takeObject(); }
private: PDFObject takeObject();
void addObject(PDFObject object);
private:
enum class ItemType void addObject(PDFObject object);
{
Object, enum class ItemType
Dictionary, {
DictionaryItem, Object,
Array Dictionary,
}; DictionaryItem,
Array
/// What is stored in this structure, depends on the type. };
/// If type is 'Object', then single simple object is in object,
/// if type is dictionary, then PDFDictionary is stored in object, /// What is stored in this structure, depends on the type.
/// if type is dictionary item, then object and item name is stored /// If type is 'Object', then single simple object is in object,
/// in the data, if item is array, then array is stored in the data. /// if type is dictionary, then PDFDictionary is stored in object,
struct Item /// if type is dictionary item, then object and item name is stored
{ /// in the data, if item is array, then array is stored in the data.
inline Item() = default; struct Item
{
template<typename T> inline Item() = default;
inline Item(ItemType type, T&& data) :
type(type), template<typename T>
object(qMove(data)) inline Item(ItemType type, T&& data) :
{ type(type),
object(qMove(data))
} {
template<typename T> }
inline Item(ItemType type, const QByteArray& itemName, T&& data) :
type(type), template<typename T>
itemName(qMove(itemName)), inline Item(ItemType type, const QByteArray& itemName, T&& data) :
object(qMove(data)) type(type),
{ itemName(qMove(itemName)),
object(qMove(data))
} {
ItemType type = ItemType::Object; }
QByteArray itemName;
std::variant<PDFObject, PDFArray, PDFDictionary> object; ItemType type = ItemType::Object;
}; QByteArray itemName;
std::variant<PDFObject, PDFArray, PDFDictionary> object;
std::vector<Item> m_items; };
};
std::vector<Item> m_items;
class PDFDocumentBuilder };
{
public: class PDFFORQTLIBSHARED_EXPORT PDFDocumentBuilder
/// Creates a new blank document (with no pages) {
explicit PDFDocumentBuilder(); public:
/// Creates a new blank document (with no pages)
/// explicit PDFDocumentBuilder();
explicit PDFDocumentBuilder(const PDFDocument* document);
///
/// Resets the object to the initial state. explicit PDFDocumentBuilder(const PDFDocument* document);
/// \warning All data are lost
void reset(); /// Resets the object to the initial state.
/// \warning All data are lost
/// Create a new blank document with no pages. If some document void reset();
/// is edited at call of this function, then it is lost.
void createDocument(); /// Create a new blank document with no pages. If some document
/// is edited at call of this function, then it is lost.
PDFDocument build(); void createDocument();
/// Builds a new document. This function can throw exceptions,
/// if document being built was invalid.
PDFDocument build();
/// If object is reference, the dereference attempt is performed
/// and object is returned. If it is not a reference, then self
/// is returned. If dereference attempt fails, then null object
/// is returned (no exception is thrown).
const PDFObject& getObject(const PDFObject& object) const;
/// Returns dictionary from an object. If object is not a dictionary,
/// then nullptr is returned (no exception is thrown).
const PDFDictionary* getDictionaryFromObject(const PDFObject& object) const;
/// Returns object by reference. If dereference attempt fails, then null object
/// is returned (no exception is thrown).
const PDFObject& getObjectByReference(PDFObjectReference reference) const;
/* START GENERATED CODE */ /* START GENERATED CODE */
/// Square annotation displays rectangle (or square). When opened, they display pop-up window /// Square annotation displays rectangle (or square). When opened, they display pop-up window
@ -216,18 +234,67 @@ public:
void updateTrailerDictionary(PDFInteger objectCount); void updateTrailerDictionary(PDFInteger objectCount);
/* END GENERATED CODE */ /// Appends a new page after last page.
/// \param mediaBox Media box of the page (size of paper)
private: PDFObjectReference appendPage(QRectF mediaBox);
PDFObjectReference addObject(PDFObject object);
void mergeTo(PDFObjectReference reference, PDFObject object);
QRectF getPopupWindowRect(const QRectF& rectangle) const; /// Creates page tree root for the catalog. This function is only called when new document is being
QString getProducerString() const; /// created. Do not call this function manually.
PDFObjectReference createCatalogPageTreeRoot();
PDFObjectStorage m_storage;
PDFVersion m_version;
}; /* END GENERATED CODE */
} // namespace pdf private:
PDFObjectReference addObject(PDFObject object);
#endif // PDFDOCUMENTBUILDER_H void mergeTo(PDFObjectReference reference, PDFObject object);
void appendTo(PDFObjectReference reference, PDFObject object);
QRectF getPopupWindowRect(const QRectF& rectangle) const;
QString getProducerString() const;
PDFObjectReference getPageTreeRoot() const;
PDFInteger getPageTreeRootChildCount() const;
PDFObjectStorage m_storage;
PDFVersion m_version;
};
// Implementation
inline
const PDFObject& PDFDocumentBuilder::getObject(const PDFObject& object) const
{
if (object.isReference())
{
// Try to dereference the object
return m_storage.getObject(object.getReference());
}
return object;
}
inline
const PDFDictionary* PDFDocumentBuilder::getDictionaryFromObject(const PDFObject& object) const
{
const PDFObject& dereferencedObject = getObject(object);
if (dereferencedObject.isDictionary())
{
return dereferencedObject.getDictionary();
}
else if (dereferencedObject.isStream())
{
return dereferencedObject.getStream()->getDictionary();
}
return nullptr;
}
inline
const PDFObject& PDFDocumentBuilder::getObjectByReference(PDFObjectReference reference) const
{
return m_storage.getObject(reference);
}
} // namespace pdf
#endif // PDFDOCUMENTBUILDER_H

View File

@ -0,0 +1,299 @@
// Copyright (C) 2020 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#include "pdfdocumentwriter.h"
#include "pdfconstants.h"
#include "pdfvisitor.h"
#include "pdfparser.h"
#include <QFile>
namespace pdf
{
class PDFWriteObjectVisitor : public PDFAbstractVisitor
{
public:
explicit PDFWriteObjectVisitor(QIODevice* device) :
m_device(device)
{
}
virtual void visitNull() override;
virtual void visitBool(bool value) override;
virtual void visitInt(PDFInteger value) override;
virtual void visitReal(PDFReal value) override;
virtual void visitString(const PDFString* string) override;
virtual void visitName(const PDFString* name) override;
virtual void visitArray(const PDFArray* array) override;
virtual void visitDictionary(const PDFDictionary* dictionary) override;
virtual void visitStream(const PDFStream* stream) override;
virtual void visitReference(const PDFObjectReference reference) override;
PDFObject getDecryptedObject();
private:
void writeName(const QByteArray& string);
QIODevice* m_device;
};
void PDFWriteObjectVisitor::visitNull()
{
m_device->write("null ");
}
void PDFWriteObjectVisitor::visitBool(bool value)
{
if (value)
{
m_device->write("true ");
}
else
{
m_device->write("false ");
}
}
void PDFWriteObjectVisitor::visitInt(PDFInteger value)
{
m_device->write(QString::number(value).toLatin1());
m_device->write(" ");
}
void PDFWriteObjectVisitor::visitReal(PDFReal value)
{
// Jakub Melka: we use 5 digits, because they are specified
// in PDF 1.7 specification, appendix C, Table C.1, where it is defined,
// that number of significant digits of precision is 5.
m_device->write(QString::number(value, 'f', 5).toLatin1());
m_device->write(" ");
}
void PDFWriteObjectVisitor::visitString(const PDFString* string)
{
const QByteArray& data = string->getString();
if (data.indexOf('(') != -1 ||
data.indexOf(')') != -1 ||
data.indexOf('\\') != -1)
{
m_device->write("<");
m_device->write(data.toHex());
m_device->write(">");
}
else
{
m_device->write("(");
m_device->write(data);
m_device->write(")");
}
m_device->write(" ");
}
void PDFWriteObjectVisitor::writeName(const QByteArray& string)
{
m_device->write("/");
for (const char character : string)
{
if (PDFLexicalAnalyzer::isRegular(character))
{
m_device->write(&character, 1);
}
else
{
m_device->write("#");
m_device->write(QByteArray(&character, 1).toHex());
}
}
m_device->write(" ");
}
void PDFWriteObjectVisitor::visitName(const PDFString* name)
{
writeName(name->getString());
}
void PDFWriteObjectVisitor::visitArray(const PDFArray* array)
{
m_device->write("[ ");
acceptArray(array);
m_device->write("] ");
}
void PDFWriteObjectVisitor::visitDictionary(const PDFDictionary* dictionary)
{
m_device->write("<< ");
for (size_t i = 0, count = dictionary->getCount(); i < count; ++i)
{
writeName(dictionary->getKey(i));
dictionary->getValue(i).accept(this);
}
m_device->write(">> ");
}
void PDFWriteObjectVisitor::visitStream(const PDFStream* stream)
{
visitDictionary(stream->getDictionary());
m_device->write("stream");
m_device->write("\x0D\x0A");
m_device->write(*stream->getContent());
m_device->write("\x0D\x0A");
m_device->write("endstream");
}
void PDFWriteObjectVisitor::visitReference(const PDFObjectReference reference)
{
visitInt(reference.objectNumber);
visitInt(reference.generation);
m_device->write("R ");
}
PDFOperationResult PDFDocumentWriter::write(const QString& fileName, const PDFDocument* document)
{
QFile file(fileName);
if (file.open(QFile::WriteOnly | QFile::Truncate))
{
PDFOperationResult result = write(&file, document);
file.close();
return result;
}
else
{
return tr("File '%1' can't be opened for writing. %2").arg(fileName, file.errorString());
}
}
PDFOperationResult PDFDocumentWriter::write(QIODevice* device, const PDFDocument* document)
{
if (!device->isWritable())
{
return tr("Device is not writable.");
}
const PDFObjectStorage& storage = document->getStorage();
const PDFObjectStorage::PDFObjects& objects = storage.getObjects();
const size_t objectCount = objects.size();
if (storage.getSecurityHandler()->getMode() != EncryptionMode::None)
{
return tr("Writing of encrypted documents is not supported.");
}
// Write header
PDFVersion version = document->getInfo()->version;
device->write(QString("%PDF-%1.%2").arg(version.major).arg(version.minor).toLatin1());
writeCRLF(device);
device->write("% PDF producer: ");
device->write(PDF_LIBRARY_NAME);
writeCRLF(device);
writeCRLF(device);
writeCRLF(device);
// Write objects
std::vector<PDFInteger> offsets(objectCount, -1);
for (size_t i = 0; i < objectCount; ++i)
{
const PDFObjectStorage::Entry& entry = objects[i];
if (entry.object.isNull())
{
continue;
}
// Jakub Melka: we must mark actual position of object
offsets[i] = device->pos();
PDFWriteObjectVisitor visitor(device);
writeObjectHeader(device, PDFObjectReference(i, entry.generation));
entry.object.accept(&visitor);
writeObjectFooter(device);
}
// Write cross-reference table
PDFInteger xrefOffset = device->pos();
device->write("xref");
writeCRLF(device);
device->write(QString("0 %1").arg(objectCount).toLatin1());
writeCRLF(device);
for (size_t i = 0; i < objectCount; ++i)
{
const PDFObjectStorage::Entry& entry = objects[i];
PDFInteger generation = entry.generation;
if (i == 0)
{
generation = 65535;
}
PDFInteger offset = offsets[i];
if (offset == -1)
{
offset = 0;
}
QString offsetString = QString::number(offset).rightJustified(10, QChar('0'), true);
QString generationString = QString::number(generation).rightJustified(5, QChar('0'), true);
device->write(offsetString.toLatin1());
device->write(" ");
device->write(generationString.toLatin1());
device->write(" ");
device->write(entry.object.isNull() ? "f" : "n");
writeCRLF(device);
}
device->write("trailer");
writeCRLF(device);
PDFWriteObjectVisitor trailerVisitor(device);
storage.getTrailerDictionary().accept(&trailerVisitor);
writeCRLF(device);
device->write("startxref");
writeCRLF(device);
device->write(QString::number(xrefOffset).toLatin1());
writeCRLF(device);
// Write footer
device->write("%%EOF");
return true;
}
void PDFDocumentWriter::writeCRLF(QIODevice* device)
{
device->write("\x0D\x0A");
}
void PDFDocumentWriter::writeObjectHeader(QIODevice* device, PDFObjectReference reference)
{
QString objectHeader = QString("%1 %2 obj").arg(QString::number(reference.objectNumber)).arg(QString::number(reference.generation));
device->write(objectHeader.toLatin1());
writeCRLF(device);
}
void PDFDocumentWriter::writeObjectFooter(QIODevice* device)
{
device->write("endobj");
writeCRLF(device);
}
} // namespace pdf

View File

@ -0,0 +1,57 @@
// Copyright (C) 2020 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#ifndef PDFDOCUMENTWRITER_H
#define PDFDOCUMENTWRITER_H
#include "pdfdocument.h"
#include "pdfprogress.h"
#include "pdfutils.h"
#include <QIODevice>
namespace pdf
{
/// Class used for writing PDF documents to the desired target device (or file,
/// buffer, etc.). If writing is not successful, then error message is returned.
class PDFFORQTLIBSHARED_EXPORT PDFDocumentWriter
{
Q_DECLARE_TR_FUNCTIONS(pdf::PDFDocumentWriter)
public:
explicit inline PDFDocumentWriter(PDFProgress* progress) :
m_progress(progress)
{
}
PDFOperationResult write(const QString& fileName, const PDFDocument* document);
PDFOperationResult write(QIODevice* device, const PDFDocument* document);
private:
void writeCRLF(QIODevice* device);
void writeObjectHeader(QIODevice* device, PDFObjectReference reference);
void writeObjectFooter(QIODevice* device);
/// Progress indicator
PDFProgress* m_progress;
};
} // namespace pdf
#endif // PDFDOCUMENTWRITER_H

View File

@ -15,7 +15,6 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>. // along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#ifndef PDFUTILS_H #ifndef PDFUTILS_H
#define PDFUTILS_H #define PDFUTILS_H
@ -497,6 +496,33 @@ static inline bool isFuzzyComparedPointsSame(const QPointF& p1, const QPointF& p
return squaredDistance < squaredTolerance; return squaredDistance < squaredTolerance;
} }
/// Storage for result of some operation. Stores, if operation was successful, or not and
/// also error message, why operation has failed. Can be converted explicitly to bool.
class PDFOperationResult
{
public:
inline PDFOperationResult(bool success) :
m_success(success)
{
}
inline PDFOperationResult(QString message) :
m_success(false),
m_errorMessage(qMove(message))
{
}
explicit operator bool() const { return m_success; }
const QString& getErrorMessage() const { return m_errorMessage; }
private:
bool m_success;
QString m_errorMessage;
};
} // namespace pdf } // namespace pdf
#endif // PDFUTILS_H #endif // PDFUTILS_H

View File

@ -340,6 +340,13 @@ return annotationObject;</property>
<property name="objectType">DictionaryItemSimple</property> <property name="objectType">DictionaryItemSimple</property>
<property name="value">WrapName("Catalog")</property> <property name="value">WrapName("Catalog")</property>
</QObject> </QObject>
<QObject class="codegen::GeneratedPDFObject">
<property name="objectName"></property>
<property name="items"/>
<property name="dictionaryItemName">Pages</property>
<property name="objectType">DictionaryItemSimple</property>
<property name="value">createCatalogPageTreeRoot()</property>
</QObject>
</property> </property>
<property name="dictionaryItemName"></property> <property name="dictionaryItemName"></property>
<property name="objectType">Dictionary</property> <property name="objectType">Dictionary</property>
@ -553,5 +560,170 @@ return annotationObject;</property>
<property name="functionDescription">This function is used to update trailer dictionary. Must be called each time the final document is being built.</property> <property name="functionDescription">This function is used to update trailer dictionary. Must be called each time the final document is being built.</property>
<property name="returnType">_void</property> <property name="returnType">_void</property>
</QObject> </QObject>
<QObject class="codegen::GeneratedFunction">
<property name="objectName"></property>
<property name="items">
<QObject class="codegen::GeneratedAction">
<property name="objectName"></property>
<property name="items">
<QObject class="codegen::GeneratedParameter">
<property name="objectName"></property>
<property name="items"/>
<property name="parameterName">mediaBox</property>
<property name="parameterType">_QRectF</property>
<property name="parameterDescription">Media box of the page (size of paper)</property>
</QObject>
</property>
<property name="actionType">Parameters</property>
<property name="variableName"></property>
<property name="variableType">_void</property>
<property name="code"></property>
</QObject>
<QObject class="codegen::GeneratedAction">
<property name="objectName"></property>
<property name="items">
<QObject class="codegen::GeneratedPDFObject">
<property name="objectName"></property>
<property name="items">
<QObject class="codegen::GeneratedPDFObject">
<property name="objectName"></property>
<property name="items"/>
<property name="dictionaryItemName">Type</property>
<property name="objectType">DictionaryItemSimple</property>
<property name="value">WrapName("Page")</property>
</QObject>
<QObject class="codegen::GeneratedPDFObject">
<property name="objectName"></property>
<property name="items"/>
<property name="dictionaryItemName">Parent</property>
<property name="objectType">DictionaryItemSimple</property>
<property name="value">getPageTreeRoot()</property>
</QObject>
<QObject class="codegen::GeneratedPDFObject">
<property name="objectName"></property>
<property name="items"/>
<property name="dictionaryItemName"></property>
<property name="objectType">Dictionary</property>
<property name="value"></property>
</QObject>
<QObject class="codegen::GeneratedPDFObject">
<property name="objectName"></property>
<property name="items"/>
<property name="dictionaryItemName">MediaBox</property>
<property name="objectType">DictionaryItemSimple</property>
<property name="value">mediaBox</property>
</QObject>
</property>
<property name="dictionaryItemName"></property>
<property name="objectType">Dictionary</property>
<property name="value"></property>
</QObject>
</property>
<property name="actionType">CreateObject</property>
<property name="variableName">pageReference</property>
<property name="variableType">_PDFObjectReference</property>
<property name="code"></property>
</QObject>
<QObject class="codegen::GeneratedAction">
<property name="objectName"></property>
<property name="items">
<QObject class="codegen::GeneratedPDFObject">
<property name="objectName"></property>
<property name="items">
<QObject class="codegen::GeneratedPDFObject">
<property name="objectName"></property>
<property name="items"/>
<property name="dictionaryItemName">Kids</property>
<property name="objectType">DictionaryItemSimple</property>
<property name="value">std::initializer_list&lt;PDFObjectReference>{ pageReference }</property>
</QObject>
<QObject class="codegen::GeneratedPDFObject">
<property name="objectName"></property>
<property name="items"/>
<property name="dictionaryItemName">Count</property>
<property name="objectType">DictionaryItemSimple</property>
<property name="value">getPageTreeRootChildCount() + 1</property>
</QObject>
</property>
<property name="dictionaryItemName"></property>
<property name="objectType">Dictionary</property>
<property name="value"></property>
</QObject>
</property>
<property name="actionType">CreateObject</property>
<property name="variableName">updatedTreeRoot</property>
<property name="variableType">_PDFObject</property>
<property name="code"></property>
</QObject>
<QObject class="codegen::GeneratedAction">
<property name="objectName"></property>
<property name="items"/>
<property name="actionType">Code</property>
<property name="variableName"></property>
<property name="variableType">_void</property>
<property name="code">appendTo(getPageTreeRoot(), updatedTreeRoot);
return pageReference;</property>
</QObject>
</property>
<property name="functionType">Structure</property>
<property name="functionName">appendPage</property>
<property name="functionDescription">Appends a new page after last page.</property>
<property name="returnType">_PDFObjectReference</property>
</QObject>
<QObject class="codegen::GeneratedFunction">
<property name="objectName"></property>
<property name="items">
<QObject class="codegen::GeneratedAction">
<property name="objectName"></property>
<property name="items">
<QObject class="codegen::GeneratedPDFObject">
<property name="objectName"></property>
<property name="items">
<QObject class="codegen::GeneratedPDFObject">
<property name="objectName"></property>
<property name="items"/>
<property name="dictionaryItemName">Type</property>
<property name="objectType">DictionaryItemSimple</property>
<property name="value">WrapName("Pages")</property>
</QObject>
<QObject class="codegen::GeneratedPDFObject">
<property name="objectName"></property>
<property name="items"/>
<property name="dictionaryItemName">Kids</property>
<property name="objectType">DictionaryItemSimple</property>
<property name="value">WrapEmptyArray()</property>
</QObject>
<QObject class="codegen::GeneratedPDFObject">
<property name="objectName"></property>
<property name="items"/>
<property name="dictionaryItemName">Count</property>
<property name="objectType">DictionaryItemSimple</property>
<property name="value">0</property>
</QObject>
</property>
<property name="dictionaryItemName"></property>
<property name="objectType">Dictionary</property>
<property name="value"></property>
</QObject>
</property>
<property name="actionType">CreateObject</property>
<property name="variableName">pageTreeRoot</property>
<property name="variableType">_PDFObjectReference</property>
<property name="code"></property>
</QObject>
<QObject class="codegen::GeneratedAction">
<property name="objectName"></property>
<property name="items"/>
<property name="actionType">Code</property>
<property name="variableName"></property>
<property name="variableType">_void</property>
<property name="code">return pageTreeRoot;</property>
</QObject>
</property>
<property name="functionType">Structure</property>
<property name="functionName">createCatalogPageTreeRoot</property>
<property name="functionDescription">Creates page tree root for the catalog. This function is only called when new document is being created. Do not call this function manually.</property>
<property name="returnType">_PDFObjectReference</property>
</QObject>
</property> </property>
</root> </root>