Skip to content

Commit

Permalink
SAK-44880: SAMIGO - Error on log when printing PDF assessment that co…
Browse files Browse the repository at this point in the history
…ntains a BASE64 image (sakaiproject#8950)
  • Loading branch information
jesusmmp authored Jan 15, 2021
1 parent dda1035 commit 72492f8
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
import java.util.ArrayList;
import java.util.HashMap;

import com.lowagie.text.DocListener;
import com.lowagie.text.html.simpleparser.StyleSheet;
import lombok.extern.slf4j.Slf4j;

import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.content.api.ContentResource;
import org.sakaiproject.content.cover.ContentHostingService;

import com.lowagie.text.DocListener;
import com.lowagie.text.Image;
import com.lowagie.text.html.simpleparser.StyleSheet;
import com.lowagie.text.pdf.codec.Base64;

import lombok.extern.slf4j.Slf4j;

/**
*
* @author Joshua Ryan <a href="mailto:[email protected]">[email protected]</a>
Expand Down Expand Up @@ -176,6 +179,23 @@ else if (src.startsWith("temp://")) {
log.error(e.getMessage(), e);
}
}
else if (src.startsWith("data:image/")) {
Image img = null;
final String base64Data = src.substring(src.indexOf(",") + 1);
try {
img = Image.getInstance(Base64.decode(base64Data));
} catch (Exception e) {
log.warn("Failed retrieving image", e.toString());
}
if (img != null) {
try {
document.add(img);
}
catch (Exception e) {
log.warn("Image couldn't be added to the document", e.toString());
}
}
}
//nothing fancy for normal images
else {
super.startElement(tag, h);
Expand Down

0 comments on commit 72492f8

Please sign in to comment.