Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project metadata wrongly encoded in PDF exported from print layout on Windows #40265

Closed
agiudiceandrea opened this issue Nov 24, 2020 · 1 comment · Fixed by #40574
Closed
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Project

Comments

@agiudiceandrea
Copy link
Contributor

Describe the bug

On Windows, if the project metadata (title, author, subject, ...) contain characters not supported or not well mapped by the system 8 bit codepage, then the metadata of the PDF file exported from the print layout (using the "Export RDF metadata" option) are wrongly encoded.

Project metadata with the string Test Eλληνικά Русский ÀÇÑ ŞÖÜ ŁĞÇŞ
image

Metadata of the exported PDF with the wrongly encoded string Test E??????? ??????? ÀÇÑ SÖÜ LGÇS
image

Test project
Test_project.zip

QGIS and OS versions

QGIS 3.10.x, 3.16.x, 3.17-master
Windows 7 / 10, windows-1252 system codepage

Additional context

The issue doesn't occur if the print layout is exported as GeoPDF instead of PDF: this previously unreported issue was fixed for GeoPDF with #40156

I think the issue is due to the use of QString::toLocal8Bit() instead of QString::toUtf8() in

GDALSetMetadataItem( outputDS.get(), "CREATION_DATE", creationDateString.toLocal8Bit().constData(), nullptr );
GDALSetMetadataItem( outputDS.get(), "AUTHOR", mGeoPdfExportDetails.author.toLocal8Bit().constData(), nullptr );
const QString creator = QStringLiteral( "QGIS %1" ).arg( Qgis::version() );
GDALSetMetadataItem( outputDS.get(), "CREATOR", creator.toLocal8Bit().constData(), nullptr );
GDALSetMetadataItem( outputDS.get(), "PRODUCER", creator.toLocal8Bit().constData(), nullptr );
GDALSetMetadataItem( outputDS.get(), "SUBJECT", mGeoPdfExportDetails.subject.toLocal8Bit().constData(), nullptr );
GDALSetMetadataItem( outputDS.get(), "TITLE", mGeoPdfExportDetails.title.toLocal8Bit().constData(), nullptr );
const QgsAbstractMetadataBase::KeywordMap keywords = mGeoPdfExportDetails.keywords;
QStringList allKeywords;
for ( auto it = keywords.constBegin(); it != keywords.constEnd(); ++it )
{
allKeywords.append( QStringLiteral( "%1: %2" ).arg( it.key(), it.value().join( ',' ) ) );
}
const QString keywordString = allKeywords.join( ';' );
GDALSetMetadataItem( outputDS.get(), "KEYWORDS", keywordString.toLocal8Bit().constData(), nullptr );
and/or in
GDALSetMetadataItem( outputDS.get(), "CREATION_DATE", creationDateString.toLocal8Bit().constData(), nullptr );
GDALSetMetadataItem( outputDS.get(), "AUTHOR", mLayout->project()->metadata().author().toLocal8Bit().constData(), nullptr );
const QString creator = QStringLiteral( "QGIS %1" ).arg( Qgis::version() );
GDALSetMetadataItem( outputDS.get(), "CREATOR", creator.toLocal8Bit().constData(), nullptr );
GDALSetMetadataItem( outputDS.get(), "PRODUCER", creator.toLocal8Bit().constData(), nullptr );
GDALSetMetadataItem( outputDS.get(), "SUBJECT", mLayout->project()->metadata().abstract().toLocal8Bit().constData(), nullptr );
GDALSetMetadataItem( outputDS.get(), "TITLE", mLayout->project()->metadata().title().toLocal8Bit().constData(), nullptr );
const QgsAbstractMetadataBase::KeywordMap keywords = mLayout->project()->metadata().keywords();
QStringList allKeywords;
for ( auto it = keywords.constBegin(); it != keywords.constEnd(); ++it )
{
allKeywords.append( QStringLiteral( "%1: %2" ).arg( it.key(), it.value().join( ',' ) ) );
}
const QString keywordString = allKeywords.join( ';' );
GDALSetMetadataItem( outputDS.get(), "KEYWORDS", keywordString.toLocal8Bit().constData(), nullptr );

@agiudiceandrea agiudiceandrea added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Nov 24, 2020
@gioman gioman added the Project label Nov 24, 2020
nyalldawson pushed a commit to nyalldawson/QGIS that referenced this issue Dec 18, 2020
@agiudiceandrea
Copy link
Contributor Author

Issue fixed by #40574
image

nyalldawson pushed a commit that referenced this issue Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants