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

Fixes Producer metadata manipulation in Stamper #256

Merged
merged 1 commit into from
Sep 14, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,6 @@ buildNumber.properties
*.html

*.pdf
#Allow pdf as source resources for testing
!openpdf/src/test/resources/*.pdf

Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void close(Map<String, String> moreInfo) throws IOException {
skipInfo = iInfo.getNumber();
}
if (oldInfo != null && oldInfo.get(PdfName.PRODUCER) != null) {
producer = oldInfo.getAsString(PdfName.PRODUCER).toString();
producer = oldInfo.getAsString(PdfName.PRODUCER).toUnicodeString();
}
if (producer == null) {
producer = Document.getVersion();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package com.lowagie.text.pdf.metadata;

import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfWriter;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Map;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfWriter;

public class ProducerTest {

private static final String PRODUCER = "Producer";

@Test
void changeProducerLineTest() throws IOException {
public void changeProducerLineTest() throws IOException {
String expected = "New Producer.";

Document document = new Document();
Expand All @@ -40,4 +43,18 @@ void changeProducerLineTest() throws IOException {

reader.close();
}

@Test
public void testMetadataProducerStamperIssue254 () throws IOException {
File origin = new File("src/test/resources/pdf_form_metadata_issue_254.pdf");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfReader reader = new PdfReader(origin.getAbsolutePath());
PdfStamper stamp = new PdfStamper(reader, baos);
stamp.close();
byte[] data = baos.toByteArray();
String sData = new String(data);
Assertions.assertTrue(sData.contains("(LibreOffice 6.0; modified using OpenPDF"));


}
}
Binary file not shown.