Skip to content

Commit 8fa78e2

Browse files
committed
Fix widths of generated PDF
Fixes apache/grails-doc#250
1 parent 01d176e commit 8fa78e2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

grails-docs/src/main/groovy/grails/doc/PdfBuilder.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class PdfBuilder {
7171
private static String cleanupHtml(File htmlFile, String xml) {
7272
String result = cleanHtml ? Jsoup.parse(xml).outerHtml() : xml
7373
result = removeCssLinks(result)
74+
result = result.replaceAll('</head>', pdfCss() + '</head>')
7475
if(debugPdf) {
7576
File before = new File(htmlFile.absolutePath + '.before.xml')
7677
before.setText(xml, 'UTF-8')
@@ -106,6 +107,19 @@ class PdfBuilder {
106107
str
107108
}
108109

110+
static String pdfCss() {
111+
"""<style type="text/css">
112+
pre, code {
113+
font-size: 10px;
114+
}
115+
.contribute-btn, #navigation, #ref-button { display: none; }
116+
.paragraph, table, h2, h3, h4, h5, h6, li, pre, code {
117+
width: 595px;
118+
}
119+
</style>
120+
"""
121+
}
122+
109123
static void createPdf(String xml, File outputFile, File urlBase) {
110124
def dbf = DocumentBuilderFactory.newInstance()
111125
dbf.validating = false

0 commit comments

Comments
 (0)