-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ddi-pdf exporter written in Jython
- Loading branch information
Showing
28 changed files
with
11,458 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"formatName": "ddi_pdf", | ||
"harvestable": false, | ||
"availableToUsers": true, | ||
"mediaType": "application/pdf", | ||
"displayName": "DDI pdf codebook", | ||
"prerequisiteFormatName": "ddi" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from java.io import ByteArrayInputStream, ByteArrayOutputStream, File | ||
from java.lang import System | ||
from java.util import Base64 | ||
from javax.xml.transform import TransformerFactory | ||
from javax.xml.transform.sax import SAXResult | ||
from javax.xml.transform.stream import StreamSource | ||
from org.apache.fop.apps import FopFactory, MimeConstants | ||
|
||
localeEnvVar = System.getenv().get("LANG") if System.getenv().get("LANG") else "en" | ||
if localeEnvVar.index(".") > 0: | ||
localeEnvVar = localeEnvVar[0 : localeEnvVar.index(".")] | ||
if localeEnvVar.index("_") > 0: | ||
localeEnvVar = localeEnvVar[0 : localeEnvVar.index("_")] | ||
|
||
fopFactory = FopFactory.newInstance(File(".").toURI()) | ||
foUserAgent = fopFactory.newFOUserAgent() | ||
out = ByteArrayOutputStream() | ||
fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out) | ||
|
||
factory = TransformerFactory.newInstance() | ||
factory.setURIResolver( | ||
lambda href, base: StreamSource(File(path + "/xslt/" + href)) | ||
) | ||
transformer = factory.newTransformer(StreamSource(File(path + "/xslt/ddi-to-fo.xsl"))) | ||
transformer.setParameter("language-code", localeEnvVar) | ||
src = StreamSource(ByteArrayInputStream(Base64.getDecoder().decode(x["base64"]))) | ||
saxRes = SAXResult(fop.getDefaultHandler()) | ||
|
||
transformer.transform(src, saxRes) | ||
|
||
res["base64"] = Base64.getEncoder().encodeToString(out.toByteArray()) |
Oops, something went wrong.