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

Fix issues with writing metadata to pdfs #8332

Merged
merged 4 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where an exception would occur when clicking on a DOI link in the preview pane [#7706](https://github.com/JabRef/jabref/issues/7706)
- We fixed an issue where XMP and embedded BibTeX export would not work [#8278](https://github.com/JabRef/jabref/issues/8278)
- We fixed an issue where the XMP and embedded BibTeX import of a file containing multiple schemas failed [#8278](https://github.com/JabRef/jabref/issues/8278)
- We fixed an issue where writing embedded BibTeX import fails due to write protection or bibtex already being present [#8332](https://github.com/JabRef/jabref/pull/8332)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.jabref.logic.bibtex.BibEntryWriter;
import org.jabref.logic.bibtex.FieldWriter;
import org.jabref.logic.bibtex.FieldWriterPreferences;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
import org.jabref.logic.util.StandardFileType;
import org.jabref.logic.util.io.FileUtil;
Expand Down Expand Up @@ -91,16 +92,28 @@ private void embedBibTex(String bibTeX, Path file, Charset encoding) throws IOEx
}
}

PDComplexFileSpecification fileSpecification;
if (names.containsKey(EMBEDDED_FILE_NAME)) {
fileSpecification = names.get(EMBEDDED_FILE_NAME);
} else {
fileSpecification = new PDComplexFileSpecification();
}
if (efTree != null) {
PDComplexFileSpecification fileSpecification = new PDComplexFileSpecification();
fileSpecification.setFile(EMBEDDED_FILE_NAME);
InputStream inputStream = new ByteArrayInputStream(bibTeX.getBytes(encoding));
fileSpecification.setFile(EMBEDDED_FILE_NAME);
PDEmbeddedFile embeddedFile = new PDEmbeddedFile(document, inputStream);
embeddedFile.setSubtype("text/x-bibtex");
embeddedFile.setSize(bibTeX.length());
fileSpecification.setEmbeddedFile(embeddedFile);

names.put(EMBEDDED_FILE_NAME, fileSpecification);
if (!names.containsKey(EMBEDDED_FILE_NAME)) {
try {
names.put(EMBEDDED_FILE_NAME, fileSpecification);
} catch (UnsupportedOperationException e) {
throw new IOException(Localization.lang("File '%0' is write protected.", file.toString()));
}
}

efTree.setNames(names);
nameDictionary.setEmbeddedFiles(efTree);
document.getDocumentCatalog().setNames(nameDictionary);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ Writing\ metadata\ for\ selected\ entries...=Writing metadata for selected entri
Writing\ metadata...=Writing metadata...

Embed\ BibTeXEntry\ in\ PDF.=Embed BibTeXEntry in PDF.
File\ '%0'\ is\ write\ protected.=File '%0' is write protected.
Write\ BibTeXEntry\ as\ XMP\ metadata\ to\ PDF.=Write BibTeXEntry as XMP metadata to PDF.
Write\ BibTeXEntry\ metadata\ to\ PDF.=Write BibTeXEntry metadata to PDF.
Write\ metadata\ to\ PDF\ files=Write metadata to PDF files
Expand Down