Added support for printing to PDF directly within browser.

Web based printing to PDF is supported in Chrome only. This functionality is added to overcome differences between fonts available in the browser and the fonts available to decktape on the GitPitch server.
This commit is contained in:
David Russell 2017-02-23 11:07:23 +07:00
parent 97001336d9
commit 3b1103ecc6
9 changed files with 47 additions and 20 deletions

View File

@ -193,7 +193,8 @@ public class PitchController extends Controller {
String pitchme,
String notes,
String fragments,
String offline) {
String offline,
String webprint) {
PitchParams pp =
PitchParams.build(grsOnCall(grs),
@ -202,6 +203,8 @@ public class PitchController extends Controller {
(fragments == null) ? false : !Boolean.parseBoolean(fragments);
boolean isOffline =
(offline == null) ? false : Boolean.parseBoolean(offline);
boolean webPrinting =
(webprint == null) ? false : Boolean.parseBoolean(webprint);
Optional<SlideshowModel> ssmo = pitchService.cachedYAML(pp);
@ -222,7 +225,7 @@ public class PitchController extends Controller {
ssm = ssm.clone(pp);
return CompletableFuture.completedFuture(
ok(com.gitpitch.views.html.Slideshow.render(ssm,
deps, printing, isOffline)));
deps, printing, isOffline, webPrinting)));
} else {
@ -241,7 +244,7 @@ public class PitchController extends Controller {
log.info("slideshow: [ fetchd, online ] {}", pp);
return ok(com.gitpitch.views.html.Slideshow.render(fetched,
deps, printing, isOffline));
deps, printing, isOffline, webPrinting));
});
}

View File

@ -289,7 +289,8 @@ public class OfflineService {
pp.pitchme,
pp.notes,
ENABLED,
ENABLED)
ENABLED,
null)
.absoluteURL(isEncrypted(), hostname());
return diskService.download(pp, zipRoot,

View File

@ -161,6 +161,7 @@ public class PrintService {
pp.pitchme,
pp.notes,
PRINT_NO_FRAGS,
null,
null)
.absoluteURL(isEncrypted(),
hostname());

View File

@ -98,7 +98,7 @@ public class GitRepoRenderer {
_pp.branch,
_pp.theme,
_pp.pitchme,
_pp.notes, null, null).toString();
_pp.notes, null, null, null).toString();
this._markdownURL = com.gitpitch.controllers.routes.PitchController
.markdown(_pp.grs,
@ -441,6 +441,20 @@ public class GitRepoRenderer {
_pp.notes).toString();
}
public String printBrowserLink() {
return com.gitpitch.controllers.routes.PitchController.slideshow(_pp.grs,
_pp.user,
_pp.repo,
_pp.branch,
_pp.theme,
_pp.pitchme,
_pp.notes,
"false",
null,
"true").toString();
}
public String offlineLink() {
return com.gitpitch.controllers.routes.PitchController.offline(_pp.grs,

View File

@ -81,11 +81,6 @@
<script>
$(".dropdown-menu li a").click(function(){
// alert("DD: selected item");
// $(this).parents(".dropdown").find('.btn').html($(this).text() + ' <span class="caret"></span>');
// $(this).parents(".dropdown").find('.btn').val($(this).data('value'));
// alert("DD: selected item.text: " + $(this).text());
// alert("DD: selected item.data: " + $(this).data('value'));
$(".dropdown-toggle").html($(this).text() + ' <span class="caret">');
$(".dropdown-toggle").val($(this).data('value', $(this).data('value')));
});

View File

@ -1,6 +1,6 @@
@import com.gitpitch.views.html.frags._
@(ssm: com.gitpitch.models.SlideshowModel, deps: com.gitpitch.policies.Dependencies, printing: Boolean, offline: Boolean)
@(ssm: com.gitpitch.models.SlideshowModel, deps: com.gitpitch.policies.Dependencies, printing: Boolean, offline: Boolean, webPrinting: Boolean)
<!DOCTYPE html>
<html>
@ -13,7 +13,9 @@
<link rel="icon" href="@deps.gitpitchimg(offline)/favicon.ico"/>
<link href="@deps.revealjs(offline, ssm.fetchRevealVersionOverride())/css/reveal.css" rel="stylesheet" type="text/css"/>
<link href="@deps.revealjs(offline, ssm.fetchRevealVersionOverride())/css/theme/@ssm.fetchThemeCSS()" rel="stylesheet" type="text/css"/>
@if(printing) {
@if(webPrinting) {
<link href="@deps.revealjs(offline, ssm.fetchRevealVersionOverride())/css/print/pdf.css" rel="stylesheet" type="text/css"/>
} else {
<link href="@deps.revealjs(offline, ssm.fetchRevealVersionOverride())/css/print/paper.css" rel="stylesheet" type="text/css"/>
}
<link href="@deps.highlightjs(offline)/@ssm.fetchHighlightCSS()" rel="stylesheet" type="text/css"/>

View File

@ -46,13 +46,9 @@
</i></a>
</li>
<li>
@if(rndr.isValid()) {
<a href="@rndr.printLink()" target="_blank"><i class="fa fa-print" aria-hidden="true"> <span
style="font-family: Helvetica Neue" ,Helvetica,Arial,sans-serif;">Print</span></i></a>
} else {
<a title="Repo not found, print disabled."><i class="fa fa-print" aria-hidden="true"> <span
style="font-family: Helvetica Neue" ,Helvetica,Arial,sans-serif;">Print</span></i></a>
}
<a href="#popupPrint" role="button" data-toggle="modal-popover" data-placement="top"><i
class="fa fa-print" aria-hidden="true"> <span style="font-family: Helvetica Neue",Helvetica,Arial,sans-serif;">Print</span>
</i></a>
</li>
<li>
@if(rndr.isValid()) {

View File

@ -82,3 +82,18 @@
}
</div>
</div>
<div id="popupPrint" class="popover" style="text-align: center; font-size:1em">
<div class="arrow"></div>
<h5 class="popover-title">GitPitch Printing</h5>
<div class="popover-content">
@if(rndr.isValid()) {
<a href="@rndr.printLink()" target="_blank">Generate PDF on Server</a>
<hr style="margin-bottom: 10px; margin-top: 10px">
<a href="@rndr.printBrowserLink()" target="_blank">Generate PDF in Browser</a>
<hr style="margin-bottom: 10px; margin-top: 10px">
<p style="width:215px; font-size:0.8em; color: gray">Note: Browser support in <b>Chrome</b> only.
} else {
Repo not found, printing disabled.
}
</div>
</div>

View File

@ -24,7 +24,7 @@ GET /pitchme/offline/:grs/:user/:repo/:b/:t/PITCHME.zip com.gitpitch.cont
GET /pitchme/markdown/:grs/:user/:repo/:b/PITCHME.md com.gitpitch.controllers.PitchController.markdown(grs:String, user:String, repo:String, b:String, p:String ?= null)
# Serve PITCHME.md slideshow.
GET /pitchme/slideshow/:grs/:user/:repo/:b com.gitpitch.controllers.PitchController.slideshow(grs:String, user:String, repo:String, b:String, t:String ?= null, p:String ?= null, n:String ?= null, fragments:String ?= null, offline:String ?= null)
GET /pitchme/slideshow/:grs/:user/:repo/:b com.gitpitch.controllers.PitchController.slideshow(grs:String, user:String, repo:String, b:String, t:String ?= null, p:String ?= null, n:String ?= null, fragments:String ?= null, offline:String ?= null, webprint:String ?= null)
# Serve PITCHME.md landing page.
GET /:user/:repo/:b com.gitpitch.controllers.PitchController.landing(user:String, repo:String, b:String, grs:String ?= null, t:String ?= null, p:String?= null, n:String ?= null, offline:String ?= null)