[Confluence 3.5.13] Content Page in html
Asked by Marcin Rybo?owicz:

How can I get html content of page when I heve page ID? I am writing plugin for confluence (java api) and I need content of page in html (source of page).


Answers:
author: Joe Clark
body: You need to use the *PageManager* API to retrieve the content of the page, and then use the *WikiStyleRenderer* API to convert the wiki markup into the HTML markup for the page.

Here's a code snippet:

```
public class MyExampleClass{    private final PageManager pageManager;    private final WikiStyleRenderer wikiStyleRenderer;	public MyExampleClass(PageManager pageManager, WikiStyleRenderer wikiStyleRenderer)	{	    this.pageManager = pageManager;		this.wikiStyleRenderer = wikiStyleRenderer;	}     public String getHtmlForPage(long pageId)	{	    Page page = pageManager.getPage(pageId);	    PageContext pageContext = page.toPageContext();        String contentToRender = page.getContent();        return wikiStyleRenderer.convertWikiToXHtml(pageContext, contentToRender);	}}
```

comments: author: Jesse Noble
body: Even better!


author: Jesse Noble
body: Hey Marcin,

I've been doing a lot of research on your question, and I've been struggling to find an inbuilt method to display HTML code for the page.

What I have found is the following: [Wiki Markup Converters](http://techwiki.openstructs.org/index.php/Wiki_converters "Wiki Markup Converter List")

The best one on there appears to be [Wiky](http://goessner.net/articles/wiky/ "Wiky"). It is written in Javascript and is bi-directional. It can convert your wiki markup to HTML, then convert the generated HTML back to wiki markup (should you need the function)

Hope this helps you.

comments: author: Marcin Rybo?owicz
body: Thank you very much!


author: Jesse Noble
body: Marcin,

I hope I have understood your question correctly. Confluence has the ability to allow you to export a space or a page in HTML (usually so it can be used for a website), this will allow you to view a page in HTML.

Directions are as follows:

1. Go to a page in the space, open the '**Browse** ' menu and select '**Advanced**'.

2. Click '**HTML Export** ' in the left-hand panel.  
   This option will only be visible if you have 'Export Space' permission.
3. Select the check box '**Include Comments**' if you want to include comments for the pages you are exporting.
4. Select the pages you want to export by selecting the check boxes in the tree view of pages displayed. By default, all pages are selected. You have the option to '**Select All** ' or '**Deselect All** ' pages.  
   If you select the check box of a page that contains one or more child or descendant pages, all of these child and descendant pages will also be selected. Similarly, if you clear the check box of such a page, all of its child and descendant pages will also be cleared. This provides a convenient method of exporting subtrees, for example, chapters or sections within a document.
5. Click '**Export**'. This will create a zipped archive of HTML files.
6. When the export process has finished, download the zipped archive as prompted and extract the files into a folder.

More detailed information can be viewed at: Confluence 3.5 Documentation - Export to HTML

Hope that answers your issue!

comments: author: Marcin Rybo?owicz
body: Thanks for your answer!

I am writing confluence plugin and I want to take page as html code and process this string. I can use getContent() method (from Page class) but I get wiki markup. What class or method can I use in order to get html code page?


Tags: content

html

page