mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Document info setters
This commit is contained in:
@@ -64,6 +64,12 @@ void PDFObjectFactory::endDictionaryItem()
|
||||
std::get<PDFDictionary>(dictionaryItem.object).addEntry(qMove(topItem.itemName), qMove(std::get<PDFObject>(topItem.object)));
|
||||
}
|
||||
|
||||
PDFObjectFactory& PDFObjectFactory::operator<<(const QDateTime& dateTime)
|
||||
{
|
||||
addObject(PDFObject::createString(std::make_shared<PDFString>(PDFEncoding::converDateTimeToString(dateTime))));
|
||||
return *this;
|
||||
}
|
||||
|
||||
PDFObjectFactory& PDFObjectFactory::operator<<(const QPointF& point)
|
||||
{
|
||||
*this << point.x();
|
||||
@@ -497,6 +503,56 @@ PDFInteger PDFDocumentBuilder::getPageTreeRootChildCount() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
PDFObjectReference PDFDocumentBuilder::getDocumentInfo() const
|
||||
{
|
||||
if (const PDFDictionary* trailerDictionary = getDictionaryFromObject(m_storage.getTrailerDictionary()))
|
||||
{
|
||||
PDFObject object = trailerDictionary->get("Info");
|
||||
if (object.isReference())
|
||||
{
|
||||
return object.getReference();
|
||||
}
|
||||
}
|
||||
|
||||
return PDFObjectReference();
|
||||
}
|
||||
|
||||
PDFObjectReference PDFDocumentBuilder::getCatalogReference() const
|
||||
{
|
||||
if (const PDFDictionary* trailerDictionary = getDictionaryFromObject(m_storage.getTrailerDictionary()))
|
||||
{
|
||||
PDFObject object = trailerDictionary->get("Root");
|
||||
if (object.isReference())
|
||||
{
|
||||
return object.getReference();
|
||||
}
|
||||
}
|
||||
|
||||
return PDFObjectReference();
|
||||
}
|
||||
|
||||
void PDFDocumentBuilder::updateDocumentInfo(PDFObject info)
|
||||
{
|
||||
PDFObjectReference infoReference = getDocumentInfo();
|
||||
if (!infoReference.isValid())
|
||||
{
|
||||
PDFObjectFactory objectFactory;
|
||||
objectFactory.beginDictionary();
|
||||
objectFactory.endDictionary();
|
||||
infoReference = addObject(objectFactory.takeObject());
|
||||
|
||||
// Update the trailer dictionary
|
||||
objectFactory.beginDictionary();
|
||||
objectFactory.beginDictionaryItem("Info");
|
||||
objectFactory << infoReference;
|
||||
objectFactory.endDictionaryItem();
|
||||
objectFactory.endDictionary();
|
||||
m_storage.updateTrailerDictionary(objectFactory.takeObject());
|
||||
}
|
||||
|
||||
mergeTo(infoReference, info);
|
||||
}
|
||||
|
||||
/* START GENERATED CODE */
|
||||
|
||||
PDFObjectReference PDFDocumentBuilder::appendPage(QRectF mediaBox)
|
||||
@@ -1819,14 +1875,6 @@ PDFObject PDFDocumentBuilder::createTrailerDictionary(PDFObjectReference catalog
|
||||
{
|
||||
PDFObjectFactory objectBuilder;
|
||||
|
||||
objectBuilder.beginDictionary();
|
||||
objectBuilder.beginDictionaryItem("Size");
|
||||
objectBuilder << 1;
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.beginDictionaryItem("Root");
|
||||
objectBuilder << catalog;
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.beginDictionaryItem("Info");
|
||||
objectBuilder.beginDictionary();
|
||||
objectBuilder.beginDictionaryItem("Producer");
|
||||
objectBuilder << getProducerString();
|
||||
@@ -1838,6 +1886,16 @@ PDFObject PDFDocumentBuilder::createTrailerDictionary(PDFObjectReference catalog
|
||||
objectBuilder << WrapCurrentDateTime();
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.endDictionary();
|
||||
PDFObjectReference infoDictionary = addObject(objectBuilder.takeObject());
|
||||
objectBuilder.beginDictionary();
|
||||
objectBuilder.beginDictionaryItem("Size");
|
||||
objectBuilder << 1;
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.beginDictionaryItem("Root");
|
||||
objectBuilder << catalog;
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.beginDictionaryItem("Info");
|
||||
objectBuilder << infoDictionary;
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.endDictionary();
|
||||
PDFObject trailerDictionary = objectBuilder.takeObject();
|
||||
@@ -1845,6 +1903,126 @@ PDFObject PDFDocumentBuilder::createTrailerDictionary(PDFObjectReference catalog
|
||||
}
|
||||
|
||||
|
||||
void PDFDocumentBuilder::setDocumentAuthor(QString author)
|
||||
{
|
||||
PDFObjectFactory objectBuilder;
|
||||
|
||||
objectBuilder.beginDictionary();
|
||||
objectBuilder.beginDictionaryItem("Author");
|
||||
objectBuilder << author;
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.endDictionary();
|
||||
PDFObject info = objectBuilder.takeObject();
|
||||
updateDocumentInfo(qMove(info));
|
||||
}
|
||||
|
||||
|
||||
void PDFDocumentBuilder::setDocumentCreationDate(QDateTime creationDate)
|
||||
{
|
||||
PDFObjectFactory objectBuilder;
|
||||
|
||||
objectBuilder.beginDictionary();
|
||||
objectBuilder.beginDictionaryItem("CreationDate");
|
||||
objectBuilder << creationDate;
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.endDictionary();
|
||||
PDFObject info = objectBuilder.takeObject();
|
||||
updateDocumentInfo(qMove(info));
|
||||
}
|
||||
|
||||
|
||||
void PDFDocumentBuilder::setDocumentCreator(QString creator)
|
||||
{
|
||||
PDFObjectFactory objectBuilder;
|
||||
|
||||
objectBuilder.beginDictionary();
|
||||
objectBuilder.beginDictionaryItem("Creator");
|
||||
objectBuilder << creator;
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.endDictionary();
|
||||
PDFObject info = objectBuilder.takeObject();
|
||||
updateDocumentInfo(qMove(info));
|
||||
}
|
||||
|
||||
|
||||
void PDFDocumentBuilder::setDocumentKeywords(QString keywords)
|
||||
{
|
||||
PDFObjectFactory objectBuilder;
|
||||
|
||||
objectBuilder.beginDictionary();
|
||||
objectBuilder.beginDictionaryItem("Keywords");
|
||||
objectBuilder << keywords;
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.endDictionary();
|
||||
PDFObject info = objectBuilder.takeObject();
|
||||
updateDocumentInfo(qMove(info));
|
||||
}
|
||||
|
||||
|
||||
void PDFDocumentBuilder::setDocumentProducer(QString producer)
|
||||
{
|
||||
PDFObjectFactory objectBuilder;
|
||||
|
||||
objectBuilder.beginDictionary();
|
||||
objectBuilder.beginDictionaryItem("Producer");
|
||||
objectBuilder << producer;
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.endDictionary();
|
||||
PDFObject info = objectBuilder.takeObject();
|
||||
updateDocumentInfo(qMove(info));
|
||||
}
|
||||
|
||||
|
||||
void PDFDocumentBuilder::setDocumentSubject(QString subject)
|
||||
{
|
||||
PDFObjectFactory objectBuilder;
|
||||
|
||||
objectBuilder.beginDictionary();
|
||||
objectBuilder.beginDictionaryItem("Subject");
|
||||
objectBuilder << subject;
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.endDictionary();
|
||||
PDFObject info = objectBuilder.takeObject();
|
||||
updateDocumentInfo(qMove(info));
|
||||
}
|
||||
|
||||
|
||||
void PDFDocumentBuilder::setDocumentTitle(QString title)
|
||||
{
|
||||
PDFObjectFactory objectBuilder;
|
||||
|
||||
objectBuilder.beginDictionary();
|
||||
objectBuilder.beginDictionaryItem("Title");
|
||||
objectBuilder << title;
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.endDictionary();
|
||||
PDFObject info = objectBuilder.takeObject();
|
||||
updateDocumentInfo(qMove(info));
|
||||
}
|
||||
|
||||
|
||||
void PDFDocumentBuilder::setLanguage(QString language)
|
||||
{
|
||||
PDFObjectFactory objectBuilder;
|
||||
|
||||
objectBuilder.beginDictionary();
|
||||
objectBuilder.beginDictionaryItem("Lang");
|
||||
objectBuilder << language;
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.endDictionary();
|
||||
PDFObject updatedCatalog = objectBuilder.takeObject();
|
||||
mergeTo(getCatalogReference(), updatedCatalog);
|
||||
}
|
||||
|
||||
|
||||
void PDFDocumentBuilder::setLanguage(QLocale locale)
|
||||
{
|
||||
PDFObjectFactory objectBuilder;
|
||||
|
||||
setLanguage(locale.name());
|
||||
}
|
||||
|
||||
|
||||
void PDFDocumentBuilder::updateTrailerDictionary(PDFInteger objectCount)
|
||||
{
|
||||
PDFObjectFactory objectBuilder;
|
||||
@@ -1853,7 +2031,8 @@ void PDFDocumentBuilder::updateTrailerDictionary(PDFInteger objectCount)
|
||||
objectBuilder.beginDictionaryItem("Size");
|
||||
objectBuilder << objectCount;
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.beginDictionaryItem("Info");
|
||||
objectBuilder.endDictionary();
|
||||
PDFObject trailerDictionary = objectBuilder.takeObject();
|
||||
objectBuilder.beginDictionary();
|
||||
objectBuilder.beginDictionaryItem("Producer");
|
||||
objectBuilder << getProducerString();
|
||||
@@ -1862,10 +2041,9 @@ void PDFDocumentBuilder::updateTrailerDictionary(PDFInteger objectCount)
|
||||
objectBuilder << WrapCurrentDateTime();
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.endDictionary();
|
||||
objectBuilder.endDictionaryItem();
|
||||
objectBuilder.endDictionary();
|
||||
PDFObject trailerDictionary = objectBuilder.takeObject();
|
||||
PDFObject updatedInfoDictionary = objectBuilder.takeObject();
|
||||
m_storage.updateTrailerDictionary(qMove(trailerDictionary));
|
||||
updateDocumentInfo(qMove(updatedInfoDictionary));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -106,6 +106,7 @@ public:
|
||||
PDFObjectFactory& operator<<(WrapString string);
|
||||
PDFObjectFactory& operator<<(AnnotationLineEnding lineEnding);
|
||||
PDFObjectFactory& operator<<(const QPointF& point);
|
||||
PDFObjectFactory& operator<<(const QDateTime& dateTime);
|
||||
|
||||
/// Treat containers - write them as array
|
||||
template<typename Container, typename ValueType = decltype(*std::begin(std::declval<Container>()))>
|
||||
@@ -616,6 +617,53 @@ public:
|
||||
PDFObject createTrailerDictionary(PDFObjectReference catalog);
|
||||
|
||||
|
||||
/// Set document author.
|
||||
/// \param author Author
|
||||
void setDocumentAuthor(QString author);
|
||||
|
||||
|
||||
/// Set document creation date.
|
||||
/// \param creationDate Creation date/time
|
||||
void setDocumentCreationDate(QDateTime creationDate);
|
||||
|
||||
|
||||
/// Set document creator.
|
||||
/// \param creator Creator
|
||||
void setDocumentCreator(QString creator);
|
||||
|
||||
|
||||
/// Set document keywords.
|
||||
/// \param keywords Keywords
|
||||
void setDocumentKeywords(QString keywords);
|
||||
|
||||
|
||||
/// Set document producer.
|
||||
/// \param producer Producer
|
||||
void setDocumentProducer(QString producer);
|
||||
|
||||
|
||||
/// Set document subject.
|
||||
/// \param subject Subject
|
||||
void setDocumentSubject(QString subject);
|
||||
|
||||
|
||||
/// Set document title.
|
||||
/// \param title Title
|
||||
void setDocumentTitle(QString title);
|
||||
|
||||
|
||||
/// Set document language.
|
||||
/// \param language Document language. It should be a language identifier, as defined in ISO 639
|
||||
/// and ISO 3166. For example, "en-US", where first two letter means language code (en =
|
||||
/// english), and the latter two is country code (US - United States).
|
||||
void setLanguage(QString language);
|
||||
|
||||
|
||||
/// Set document language.
|
||||
/// \param locale Locale, from which is language determined
|
||||
void setLanguage(QLocale locale);
|
||||
|
||||
|
||||
/// This function is used to update trailer dictionary. Must be called each time the final document is
|
||||
/// being built.
|
||||
/// \param objectCount Number of objects (including empty ones)
|
||||
@@ -632,6 +680,9 @@ private:
|
||||
QString getProducerString() const;
|
||||
PDFObjectReference getPageTreeRoot() const;
|
||||
PDFInteger getPageTreeRootChildCount() const;
|
||||
PDFObjectReference getDocumentInfo() const;
|
||||
PDFObjectReference getCatalogReference() const;
|
||||
void updateDocumentInfo(PDFObject info);
|
||||
|
||||
PDFObjectStorage m_storage;
|
||||
PDFVersion m_version;
|
||||
|
Reference in New Issue
Block a user