Skip to content

Commit

Permalink
Merge pull request #256 from albfernandez/metadat_issue_254
Browse files Browse the repository at this point in the history
Fixes Producer metadata manipulation in Stamper
  • Loading branch information
andreasrosdal authored Sep 14, 2019
2 parents 9520117 + 6ceda3d commit 3e5a5d2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
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.

0 comments on commit 3e5a5d2

Please sign in to comment.