Skip to content

Commit

Permalink
PDF: add support for the Author field
Browse files Browse the repository at this point in the history
[ChangeLog][QtGui][QPdfWriter] It is now possible to set the Author
information for a PDF file.

Change-Id: I27cb409d37cb79d9476a4da0c82d4a6d35f5fe8d
Reviewed-by: Albert Astals Cid <[email protected]>
  • Loading branch information
dangelog committed Aug 26, 2024
1 parent 3270232 commit a0a0828
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/gui/painting/qpdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,8 @@ void QPdfEnginePrivate::writeInfo(const QDateTime &date)
printString(title);
write("\n/Creator ");
printString(creator);
write("\n/Author ");
printString(author);
write("\n/Producer ");
printString(QString::fromLatin1("Qt " QT_VERSION_STR));

Expand Down Expand Up @@ -1847,6 +1849,13 @@ int QPdfEnginePrivate::writeXmpDocumentMetaData(const QDateTime &date)
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();

// PDF
Expand Down
1 change: 1 addition & 0 deletions src/gui/painting/qpdf_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class Q_GUI_EXPORT QPdfEnginePrivate : public QPaintEnginePrivate
QString outputFileName;
QString title;
QString creator;
QString author;
QUuid documentId = QUuid::createUuid();
bool embedFonts;
int resolution;
Expand Down
20 changes: 20 additions & 0 deletions src/gui/painting/qpdfwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,26 @@ void QPdfWriter::setDocumentId(const QUuid &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
*/
Expand Down
3 changes: 3 additions & 0 deletions src/gui/painting/qpdfwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class Q_GUI_EXPORT QPdfWriter : public QObject, public QPagedPaintDevice
QUuid documentId() const;
void setDocumentId(const QUuid &documentId);

QString author() const;
void setAuthor(const QString &author);

bool newPage() override;

void setResolution(int resolution);
Expand Down

0 comments on commit a0a0828

Please sign in to comment.