PDF: add support for the Author field

[ChangeLog][QtGui][QPdfWriter] It is now possible to set the Author
information for a PDF file.

Change-Id: I27cb409d37cb79d9476a4da0c82d4a6d35f5fe8d
Reviewed-by: Albert Astals Cid <aacid@kde.org>
This commit is contained in:
Giuseppe D'Angelo 2024-07-11 14:08:35 +02:00
parent 3270232cca
commit a0a0828566
4 changed files with 33 additions and 0 deletions

View File

@ -1742,6 +1742,8 @@ void QPdfEnginePrivate::writeInfo(const QDateTime &date)
printString(title); printString(title);
write("\n/Creator "); write("\n/Creator ");
printString(creator); printString(creator);
write("\n/Author ");
printString(author);
write("\n/Producer "); write("\n/Producer ");
printString(QString::fromLatin1("Qt " QT_VERSION_STR)); printString(QString::fromLatin1("Qt " QT_VERSION_STR));
@ -1847,6 +1849,13 @@ int QPdfEnginePrivate::writeXmpDocumentMetaData(const QDateTime &date)
w.writeEndElement(); w.writeEndElement();
w.writeEndElement(); w.writeEndElement();
w.writeEndElement(); w.writeEndElement();
w.writeStartElement(dcNS, "creator");
w.writeStartElement(rdfNS, "Seq");
w.writeStartElement(rdfNS, "li");
w.writeCharacters(author);
w.writeEndElement();
w.writeEndElement();
w.writeEndElement();
w.writeEndElement(); w.writeEndElement();
// PDF // PDF

View File

@ -265,6 +265,7 @@ public:
QString outputFileName; QString outputFileName;
QString title; QString title;
QString creator; QString creator;
QString author;
QUuid documentId = QUuid::createUuid(); QUuid documentId = QUuid::createUuid();
bool embedFonts; bool embedFonts;
int resolution; int resolution;

View File

@ -211,6 +211,26 @@ void QPdfWriter::setDocumentId(const QUuid &documentId)
d->engine->d_func()->documentId = documentId; d->engine->d_func()->documentId = documentId;
} }
/*!
\since 6.9
Returns the author of the document.
*/
QString QPdfWriter::author() const
{
Q_D(const QPdfWriter);
return d->engine->d_func()->author;
}
/*!
\since 6.9
Sets the author of the document to \a author.
*/
void QPdfWriter::setAuthor(const QString &author)
{
Q_D(QPdfWriter);
d->engine->d_func()->author = author;
}
/*! /*!
\reimp \reimp
*/ */

View File

@ -39,6 +39,9 @@ public:
QUuid documentId() const; QUuid documentId() const;
void setDocumentId(const QUuid &documentId); void setDocumentId(const QUuid &documentId);
QString author() const;
void setAuthor(const QString &author);
bool newPage() override; bool newPage() override;
void setResolution(int resolution); void setResolution(int resolution);