Skip to content

Commit

Permalink
SAM-2502 - Inline images in print pdf do not display
Browse files Browse the repository at this point in the history
Updated default properties
  • Loading branch information
jonespm committed Mar 13, 2015
1 parent 99241f6 commit 12424a2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2886,6 +2886,10 @@
# Default: false
#samigo.removePubAssessment.restricted.afterStart=true

# In the PDF print output, setting this to true will remove all HTML formatting from the questions and answers (This was a legacy setting just added incase someone was using it or it was causing problems)
# Default: false
# samigo.pdf.convertformattedtext=true

#########################################
# WORKSITE SETUP/SITE INFO
#########################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public String getIntro() {
* @param intro in html
*/
public void setIntro(String intro) {
this.intro = FormattedText.convertPlaintextToFormattedText(FormattedText.convertFormattedTextToPlaintext(FormattedText.unEscapeHtml(intro)));
this.intro = convertFormattedText(FormattedText.unEscapeHtml(intro));
}

/**
Expand Down Expand Up @@ -375,7 +375,7 @@ public String prepDocumentPDF() {

if (!(item.getItemData().getTypeId().equals(TypeIfc.FILL_IN_BLANK) || item.getItemData().getTypeId().equals(TypeIfc.FILL_IN_NUMERIC))) {
contentBuffer.append("<br />");
contentBuffer.append(FormattedText.convertPlaintextToFormattedText(FormattedText.convertFormattedTextToPlaintext(item.getItemData().getText())));
contentBuffer.append(convertFormattedText(item.getItemData().getText()));
contentBuffer.append("<br />");
}
if (item.getItemData().getItemAttachmentList() != null && item.getItemData().getItemAttachmentList().size() > 0) {
Expand Down Expand Up @@ -409,7 +409,7 @@ public String prepDocumentPDF() {
contentBuffer.append("<br />");
}
contentBuffer.append("<br />");
contentBuffer.append(FormattedText.convertPlaintextToFormattedText(FormattedText.convertFormattedTextToPlaintext(item.getItemData().getText())));
contentBuffer.append(convertFormattedText(item.getItemData().getText()));
contentBuffer.append("<br />");
}

Expand Down Expand Up @@ -478,10 +478,10 @@ public String prepDocumentPDF() {
if (matching.getText() == null) break;

contentBuffer.append("<tr><td colspan='10'>");
contentBuffer.append(FormattedText.convertPlaintextToFormattedText(FormattedText.convertFormattedTextToPlaintext(matching.getText())));
contentBuffer.append(convertFormattedText(matching.getText()));
contentBuffer.append("</td>");
contentBuffer.append("<td colspan='10'>");
contentBuffer.append(FormattedText.convertPlaintextToFormattedText(FormattedText.convertFormattedTextToPlaintext(answer)));
contentBuffer.append(convertFormattedText(answer));
contentBuffer.append("</td></tr>");
}

Expand Down Expand Up @@ -576,14 +576,14 @@ private String getContentAnswer(ItemContentsBean item, PublishedAnswer answer, P
contentBuffer.append(". ");
}

contentBuffer.append(FormattedText.convertPlaintextToFormattedText(FormattedText.convertFormattedTextToPlaintext(answer.getText())));
contentBuffer.append(convertFormattedText(answer.getText()));
contentBuffer.append("</td>");
contentBuffer.append("<td colspan='9'>");
contentBuffer.append("<h6>");
contentBuffer.append(commonMessages.getString("feedback"));
contentBuffer.append(": ");
if (answer.getGeneralAnswerFeedback() != null && !answer.getGeneralAnswerFeedback().equals(""))
contentBuffer.append(FormattedText.convertPlaintextToFormattedText(FormattedText.convertFormattedTextToPlaintext(answer.getGeneralAnswerFeedback())));
contentBuffer.append(convertFormattedText(answer.getGeneralAnswerFeedback()));
else
contentBuffer.append("--------");
contentBuffer.append("</h6>");
Expand All @@ -595,7 +595,7 @@ private String getContentAnswer(ItemContentsBean item, PublishedAnswer answer, P
contentBuffer.append(". ");
}

contentBuffer.append(FormattedText.convertPlaintextToFormattedText(FormattedText.convertFormattedTextToPlaintext(answer.getText())));
contentBuffer.append(convertFormattedText(answer.getText()));
contentBuffer.append("</td>");
}
contentBuffer.append("</td>");
Expand All @@ -604,7 +604,7 @@ private String getContentAnswer(ItemContentsBean item, PublishedAnswer answer, P
if (item.getItemData().getTypeId().equals(TypeIfc.TRUE_FALSE)) {
contentBuffer.append("<td colspan='1'><img src='/samigo-app/images/radiounchecked.gif' /></td>");
contentBuffer.append("<td colspan='19'>");
contentBuffer.append(FormattedText.convertPlaintextToFormattedText(FormattedText.convertFormattedTextToPlaintext(answer.getText())));
contentBuffer.append(convertFormattedText(answer.getText()));
contentBuffer.append("</td>");
}

Expand Down Expand Up @@ -656,7 +656,7 @@ else if (item.getItemData().getTypeId().equals(TypeIfc.ESSAY_QUESTION)) {
contentBuffer.append(commonMessages.getString("feedback"));
contentBuffer.append(": ");
if (item.getItemData().getGeneralItemFeedback() != null && !item.getItemData().getGeneralItemFeedback().equals(""))
contentBuffer.append(FormattedText.convertPlaintextToFormattedText(FormattedText.convertFormattedTextToPlaintext(item.getItemData().getGeneralItemFeedback())));
contentBuffer.append(convertFormattedText(item.getItemData().getGeneralItemFeedback()));
else
contentBuffer.append("--------");
}
Expand All @@ -672,14 +672,14 @@ else if (item.getItemData().getTypeId().equals(TypeIfc.ESSAY_QUESTION)) {
contentBuffer.append(printMessages.getString("correct_feedback"));
contentBuffer.append(": ");
if (item.getItemData().getCorrectItemFeedback() != null && !item.getItemData().getCorrectItemFeedback().equals(""))
contentBuffer.append(FormattedText.convertPlaintextToFormattedText(FormattedText.convertFormattedTextToPlaintext(item.getItemData().getCorrectItemFeedback())));
contentBuffer.append(convertFormattedText(item.getItemData().getCorrectItemFeedback()));
else
contentBuffer.append("--------");
contentBuffer.append("<br />");
contentBuffer.append(printMessages.getString("incorrect_feedback"));
contentBuffer.append(": ");
if (item.getItemData().getInCorrectItemFeedback() != null && !item.getItemData().getInCorrectItemFeedback().equals(""))
contentBuffer.append(FormattedText.convertPlaintextToFormattedText(FormattedText.convertFormattedTextToPlaintext(item.getItemData().getInCorrectItemFeedback())));
contentBuffer.append(convertFormattedText(item.getItemData().getInCorrectItemFeedback()));
else
contentBuffer.append("--------");
}
Expand All @@ -689,6 +689,15 @@ else if (item.getItemData().getTypeId().equals(TypeIfc.ESSAY_QUESTION)) {
return contentBuffer.toString();
}

public String convertFormattedText(String text) {
//To preserve old behavior, set this to true
//Possibly consider using jsoup with a whitelist so some formatted text gets though, I'm not sure why this was here in the first place
if (ServerConfigurationService.getBoolean("samigo.pdf.convertformattedtext",false)) {
return FormattedText.convertPlaintextToFormattedText(FormattedText.convertFormattedTextToPlaintext(text));
}
return text;
}

public void getPDFAttachment() {
prepDocumentPDF();
ByteArrayOutputStream pdf = getStream();
Expand Down

0 comments on commit 12424a2

Please sign in to comment.