How do I embed source code or HTML in Open Office Org Presentations without using screenshots?

这一生的挚爱 提交于 2019-12-02 16:06:42

Some people says that copying code from Eclipse editor works well (UPDATE: Proven FALSE). Another alternative is exporting to RTF (can also export line numbers), or to clipboard, from Highlight and then opening/pasting it in OpenOffice.org. (UPDATE: Proven TRUE)

Here is a Highlight GUI screen shot:

You can also switch from OpenOffice.org to LibreOffice, and get COOoder from here.

Daniel Reis

This answer is perfect for the job:

I have exactly the same problem, but with PHP code rather than C. My almost-solution is to copy the code as HTML in Kate and paste it into a temporary Open Office Writer document. That converts it to Open Office's own styled text format, and from there you can copy and paste it into Impress. Aside from the slightly annoying double-step copy-and-paste, this mostly works fine except that lines that were entirely in bold lose their emboldening and I have to manually fix them. A few other strange bugs can occur too - Impress's import of styled text from OOWriter appears to be a bit buggy.

You can do this easily

  • copy the text from you favorite editor
  • go to impress, make a new text field
  • press CTRL + SHIFT + V (or Edit → Paste Contents)
  • and then choose Rich Text Format (RTF).

I have tested this with LibreOffice 4.2.8 under Ubuntu.

Update: I have released this macro as a LibreOffice extension. You can install it from the official site: Code Highlighter


I had the same problem but for Java and finally I found a native solution using Python macro which is tested in LibreOffice 5.

Installation

Step 1: Install libreoffice-script-provider-python:

sudo apt-get install libreoffice-script-provider-python

Step 2: Install pygments for Python 3:

sudo pip3 install python3-pygments

Step 3: Download Highlight.py

Step 4: Copy the Highlight.py to /usr/lib/libreoffice/share/Scripts/python/

sudo cp Highlight.py /usr/lib/libreoffice/share/Scripts/python/

Step 5: Set the Read-Only permission to the script.

sudo chmod 0444 /usr/lib/libreoffice/share/Scripts/python/Highlight.py

Step 6: Open the LibreOffice Writer and goto Tools -> Customize -> Keyboard

  • Select the LibreOffice option button (Available on top left corner)
  • Select any desired shortcut
  • Select share/Highlight/Highlight_source_code under the Functions Category
  • Click on the Modify button to set the shortcut

Usage

LibreOffice Impress

  • Open LibreOffice Impress.
  • Insert a Text Box (Insert -> Text Box).
  • Copy and paste any code snippet into that Text Box.
  • Create a new Style (Right click on an existing style -> New...)
  • Name the Style as code-<language>
  • Apply the style to your code snippet Text Box.
  • Select the Text Box.
  • Use your shortcut keys to execute the macro.

LibreOffice Writer/Calc

  • Open LibreOffice Writer/Calc.
  • Insert a Text Box (Insert -> Text Box).
  • Copy and paste any code snippet into that Text Box.
  • Right click on the Text Box and select 'Description'.
  • Add a description in the following format: code-<language>
  • Select the Text Box
  • Use your shortcut keys to execute the macro.

UPDATE:

I have added custom style support to this extension. Use code-<language> for default style and code-<language>-<style> for custom style. Available styles are listed in my Git Hub page.

For example Code-Java-Emacs will colorize the Java code using Emacs style.

For more details, visit to the Git Hub link: libreoffice-code-highlighter

If you are familiar with LaTeX, you should consider using beamer to create your presentation. The wikipedia page has pointers to many tutorials and documents. The user guide is probably the best one I've found.

This can give you all the power of LaTeX for source code snippets (listings package or any other you prefer) along with the rest of the usual features of LaTeX that you're used to. It comes bundled with a score of really nice themes.

You can easly use a table with 1 line and 1 column, copy and past your code from your favorit IDE, open office will preserve your code style.

Pasting from Eclipse into OpenOffice Impress directly seems to lose the coloring. However, first pasting into OO Writer and from there into OO Impress does work.

I do this all the time with open office with source code under Windows. View the code in your favorite editor (emacs, notepad, ...), and select/copy the text of interest. Make a text box in open office, and paste. This works because all of Windows tools share a global cut buffer. I don't use Linux enough to know if it has such a shared cut-buffer, if it doesn't, I kind of understand your problem.( If it does, I really don't understand your problem). My solution of course doesn't get nicely formatted/highlighted code by itself.

Specific steps: In Open Office Impress ("Presentation") with a slide open, click the box labelled "T" on the lower tool bar (or push F2). Then click on the slide roughly where you want the the text, and drag to make the box about the right size. Click in box and you can enter text. For code, I cut from some editor window, and paste after selecting the text box. If you click on the outline of the text box, you can change the font (courier new is good for code) and print size.

After you get the text sized right, you can revisit specific substrings, and select/bold or select/color if you want fancy text.

You might consider cutting and pasting from JavaDoc or Doxygen output; you are likely to get the formatting data along with the text.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!