mirror of
https://github.com/sismics/docs.git
synced 2024-11-25 23:27:57 +01:00
trim crappy characters
This commit is contained in:
parent
f227335e14
commit
8b039c61ed
@ -200,7 +200,7 @@ public class PdfUtil {
|
|||||||
.addText("Created by " + documentDto.getCreator()
|
.addText("Created by " + documentDto.getCreator()
|
||||||
+ " on " + dateFormat.format(new Date(documentDto.getCreateTimestamp())), true)
|
+ " on " + dateFormat.format(new Date(documentDto.getCreateTimestamp())), true)
|
||||||
.newLine()
|
.newLine()
|
||||||
.addText(Strings.nullToEmpty(documentDto.getDescription()).replaceAll("[\r\n]", ""))
|
.addText(documentDto.getDescription())
|
||||||
.newLine();
|
.newLine();
|
||||||
if (!Strings.isNullOrEmpty(documentDto.getSubject())) {
|
if (!Strings.isNullOrEmpty(documentDto.getSubject())) {
|
||||||
pdfPage.addText("Subject: " + documentDto.getSubject());
|
pdfPage.addText("Subject: " + documentDto.getSubject());
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package com.sismics.docs.core.util.pdf;
|
package com.sismics.docs.core.util.pdf;
|
||||||
|
|
||||||
import java.io.Closeable;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
import org.apache.pdfbox.pdmodel.PDPage;
|
import org.apache.pdfbox.pdmodel.PDPage;
|
||||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||||
import org.apache.pdfbox.pdmodel.font.PDFont;
|
import org.apache.pdfbox.pdmodel.font.PDFont;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around PDFBox for high level abstraction of PDF writing.
|
* Wrapper around PDFBox for high level abstraction of PDF writing.
|
||||||
*
|
*
|
||||||
@ -102,7 +102,10 @@ public class PdfPage implements Closeable {
|
|||||||
if (text == null) {
|
if (text == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove \r\n non breakable space
|
||||||
|
text = text.replaceAll("[\r\n]", "").replace("\u00A0", " ");
|
||||||
|
|
||||||
pdContent.setFont(font, fontSize);
|
pdContent.setFont(font, fontSize);
|
||||||
int start = 0;
|
int start = 0;
|
||||||
int end = 0;
|
int end = 0;
|
||||||
|
@ -251,14 +251,6 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
Assert.assertTrue(relations.getJsonObject(0).getBoolean("source"));
|
Assert.assertTrue(relations.getJsonObject(0).getBoolean("source"));
|
||||||
Assert.assertEquals("My super title document 1", relations.getJsonObject(0).getString("title"));
|
Assert.assertEquals("My super title document 1", relations.getJsonObject(0).getString("title"));
|
||||||
|
|
||||||
// Export a document in PDF format
|
|
||||||
Response response = target().path("/document/" + document1Id).request()
|
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token)
|
|
||||||
.get();
|
|
||||||
InputStream is = (InputStream) response.getEntity();
|
|
||||||
byte[] pdfBytes = ByteStreams.toByteArray(is);
|
|
||||||
Assert.assertTrue(pdfBytes.length > 0);
|
|
||||||
|
|
||||||
// Create a tag
|
// Create a tag
|
||||||
json = target().path("/tag").request()
|
json = target().path("/tag").request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token)
|
||||||
@ -271,7 +263,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token)
|
||||||
.post(Entity.form(new Form()
|
.post(Entity.form(new Form()
|
||||||
.param("title", "My new super document 1")
|
.param("title", "My new super document 1")
|
||||||
.param("description", "My new super description for document 1")
|
.param("description", "My new super description for document\r\n\u00A0 1")
|
||||||
.param("subject", "My new subject for document 1")
|
.param("subject", "My new subject for document 1")
|
||||||
.param("identifier", "My new identifier for document 1")
|
.param("identifier", "My new identifier for document 1")
|
||||||
.param("publisher", "My new publisher for document 1")
|
.param("publisher", "My new publisher for document 1")
|
||||||
@ -291,7 +283,15 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
.param("title", "My super title document 2")
|
.param("title", "My super title document 2")
|
||||||
.param("language", "eng")), JsonObject.class);
|
.param("language", "eng")), JsonObject.class);
|
||||||
Assert.assertEquals(document2Id, json.getString("id"));
|
Assert.assertEquals(document2Id, json.getString("id"));
|
||||||
|
|
||||||
|
// Export a document in PDF format
|
||||||
|
Response response = target().path("/document/" + document1Id).request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token)
|
||||||
|
.get();
|
||||||
|
InputStream is = (InputStream) response.getEntity();
|
||||||
|
byte[] pdfBytes = ByteStreams.toByteArray(is);
|
||||||
|
Assert.assertTrue(pdfBytes.length > 0);
|
||||||
|
|
||||||
// Search documents by query
|
// Search documents by query
|
||||||
json = target().path("/document/list")
|
json = target().path("/document/list")
|
||||||
.queryParam("search", "new")
|
.queryParam("search", "new")
|
||||||
|
Loading…
Reference in New Issue
Block a user