private String renderToHtml(AbstractPage page, ContentTree fullContentTree) { if (LOG.isDebugEnabled()) LOG.debug("Rendering to exported XHTML page id=" + page.getId() + " (" + page.getTitle() + ")"); PageContext context = page.toPageContext(); context.setBaseUrl(settingsManager.getGlobalSettings().getBaseUrl()); context.setOutputType(RenderContext.PDF); DefaultConversionContext conversionContext = new DefaultConversionContext(context); if (fullContentTree != null) { conversionContext.setContentTree(fullContentTree); } final String html = xhtmlRenderer.render(page, conversionContext); return renderPageTemplate(page.getTitle(), html); }
private ImmutableMap<Object, Object> createSearchResult(final I18NBean i18NBean, final FriendlyDateFormatter friendlyDateFormatter, ContentReportData contentReportData, final AbstractPage abstractPage) { final User creator = abstractPage.getCreator(); ImmutableMap.Builder<Object, Object> builder = ImmutableMap.builder() .put("title", abstractPage.getTitle()) .put("urlPath", contextPathHolder.getContextPath() + abstractPage.getUrlPath()) .put("creatorName", creator == null ? i18NBean.getText("anonymous.name") : creator.getName()) .put("creatorFullName", creator == null ? i18NBean.getText("anonymous.name") : creator.getFullName()) .put("friendlyModificationDate", i18NBean .getText(friendlyDateFormatter.getFormatMessage(abstractPage.getLastModificationDate()))) .put("sortableDate", Long.toString(abstractPage.getLastModificationDate().getTime())); if (contentReportData.hasCommentCounts()) { builder.put("commentCount", contentReportData.getCommentCount(abstractPage)); } if (contentReportData.hasLikeCounts()) { builder.put("likeCount", contentReportData.getLikeCount(abstractPage)); } return builder.build(); }
@Override public File createPdfForPage(User user, AbstractPage page, String contextPath, PageExportMetrics pageExportMetrics) throws ImportExportException { exportPermissionChecker.checkAuthorization(user, page); return createPdf(page, contextPath, LinkRenderingDetails.anchors(), page.getTitle(), pageExportMetrics, none()).getFile(); }
private RenderedPdfFile createPdf(AbstractPage page, String contextPath, LinkRenderingDetails linkDetails, String filePrefix, PageExportMetrics pageExportMetrics, DecorationPolicy decoration) throws ImportExportException { log.debug("Exporting page {}", page.getId()); final Document xhtml; if (page instanceof Page) { xhtml = createDocument((Page) page, linkDetails, decoration); } else { xhtml = createDocument((BlogPost) page); } final long startTime = System.currentTimeMillis(); try { pageExportMetrics.setPageId(page.getId()); pageExportMetrics.setPageRevision(page.getConfluenceRevision().hashCode()); final RenderedPdfFile result = renderPdf(contextPath, page.getTitle(), xhtml, filePrefix, pageExportMetrics); pageExportMetrics.getExportResults().setExportStatus(ExportStatus.OK); pageExportMetrics.getExportResults().setPdfPagesTotal(result.getNumPages()); pageExportMetrics.getExportResults().setPdfFileSizeBytes(result.getFile().length()); return result; } finally { pageExportMetrics.setTimeMs((int) (System.currentTimeMillis() - startTime)); } }
private File doCreatePdfForPage(User user, AbstractPage page, String contextPath) throws ImportExportException { exportPermissionChecker.checkAuthorization(user, page); Document xhtml; if (page instanceof Page) { ContentTree tree = newContentTree(); tree.addRootNode(new ContentNode((Page) page)); xhtml = intermediateHtmlBuilder.buildHtml(tree, page.getSpace(), LinkRenderingDetails.anchors(), DecorationPolicy.none()); } else if (page instanceof BlogPost) { xhtml = intermediateHtmlBuilder.buildHtml((BlogPost) page); } else { throw new IllegalArgumentException("Only pages and blog post are supported"); } String spaceKey = getSpaceKeyForExportFileName(page.getSpaceKey()); File pdf; try { String filename = spaceKey + "-" + ((page.getTitle() == null) ? page.getId() : page.getTitle().replaceAll("\\s", "")); if (!GeneralUtil.isSafeTitleForFilesystem(filename)) { filename = spaceKey + "-" + page.getId(); } pdf = flyingPdfDocumentConverter.convertXhtmlToPdf(filename, xhtml, contextPath); } catch (ImportExportException e) { if (e.getCause() instanceof FileNotFoundException) { String filename = spaceKey + "-" + page.getId(); pdf = flyingPdfDocumentConverter.convertXhtmlToPdf(filename, xhtml, contextPath); } else { throw e; } } return pdf; }