<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lev Shuvalov&#160; &#187; linux</title>
	<atom:link href="http://shuvalov.com/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://shuvalov.com</link>
	<description>system administrator</description>
	<lastBuildDate>Mon, 10 Oct 2011 17:31:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>convert .html, .doc, .rtf etc to .sxw and .pdf through OpenOffice in command line</title>
		<link>http://shuvalov.com/convert-html-doc-rtf-etc-to-sxw-and-pdf-through-openoffice-in-command-line/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=convert-html-doc-rtf-etc-to-sxw-and-pdf-through-openoffice-in-command-line</link>
		<comments>http://shuvalov.com/convert-html-doc-rtf-etc-to-sxw-and-pdf-through-openoffice-in-command-line/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 16:02:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[doc]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[ooo]]></category>
		<category><![CDATA[pdf]]></category>

		<guid isPermaLink="false">http://administrator-system.com/system-administrator/?p=101</guid>
		<description><![CDATA[convert .html, .doc, .rtf etc to .sxw and .pdf through OpenOffice in command line I have got a task to convert files form MS Word, RTF, HTML formats to SXW ( OpenOffice 1.0 Text Document ) and PDF formats in command line. I have found a solution on forum http://www.oooforum.org/ and it was nontrivial to [...]]]></description>
			<content:encoded><![CDATA[<p>convert .html, .doc, .rtf etc to .sxw and .pdf through OpenOffice in command line</p>
<p>I have got a task to convert files form MS Word, RTF, HTML formats to SXW ( OpenOffice 1.0 Text Document ) and PDF formats in command line. </p>
<p>I have found a solution on forum  <a href="http://www.oooforum.org/">http://www.oooforum.org/</a> and it was nontrivial to me. Needs to write StarBasic module and execute  <a href="http://www.openoffice.org/">OpenOffice</a> in invisible mode by DOS batch file or BASH script.</p>
<pre>
"soffice" -invisible "macro:///MyLibrary.MyModule.MyFunction(/fullpath/filename.ext)"
</pre>
<p>If you have a different type of transformation you can to change my or write your own function with a different filter.  In code of its you have to use a internal name of choosen filter according to <a href="http://shuvalov.com/storage/book/openoffice/filter_description.html">that list </a>.  Certainly, that filter should be available for Import or Export depends on what you are going to do to read or to save. If you will not define some filter then <a href="http://www.openoffice.org/">OpenOffice</a> will read or save in a default format.</p>
<p>Steps:</p>
<p>1. Execute <a href="http://www.openoffice.org/">OpenOffice</a></p>
<pre>
$ soffice
</pre>
<p>2. Create a library.</p>
<pre>
Under <a href="http://www.openoffice.org/">OpenOffice</a> 1.1.x in main menu Tools | Marcos | Macro...
  Then press the button  "Organizer...".
  Choose the tab  "Libraries".
  Click on the library name.
  And press the button "New..."

Under <a href="http://www.openoffice.org/">OpenOffice</a> 1.9.x in main menu Tools | Marcos | Organize Macros | OpenOffice.org...
  Then press the button  "Organizer...".
  Choose the tab  "Libraries".
  Press the button "New..." 

Name the library. In my case it is "LevShuvalov".
</pre>
<p>3. Create a module in just created library</p>
<pre>
You still in the "Macro Organizer" pop-up window.
Choose the tab "Modules".
Press the button "New Module..." for <a href="http://www.openoffice.org/">OpenOffice</a> 1.1.x and "New..." for <a href="http://www.openoffice.org/">OpenOffice</a> 1.9.x.

Name the module. In my case it is "Convert". And press the button "Edit"
</pre>
<p>4. Download <a href="http://shuvalov.com/storage/LevShuvalov/openoffice/LevShuvalov_Convert.bas">a recent versoin of the module</a>. Or copy-paste the code below, but in this case be careful with line feeds.</p>
<pre>
REM  *****  BASIC  *****
'
' This module for command line conversion HTML, DOC, RTF etc to SXW and PDF through OpenOffice.
'
' Code is based on answers, examplas and functions by Danny Brewer (God bless him) on:
' http://www.oooforum.org/forum/viewtopic.phtml?
' t=3772&#038;start=0&#038;postdays=0&#038;postorder=asc&#038;highlight=object+variable+set+storetourl
' list of filters internal names from:
' http://framework.openoffice.org/files/documents/25/897/filter_description.html

'****************************************************************************
' Copyright (c) 2003 Danny Brewer, 2005 Lev Shuvalov
'
' Anyone may run this code.
' If you wish to modify or distribute this code, then
' you are granted a license to do so under the terms
' of the Gnu Lesser General Public License.
' See:  http://www.gnu.org/licenses/lgpl.html
'****************************************************************************
'
' 2005-05-25 tested OpenOffice 1.1.4 and 1.9.104
' 2005-05-25 replace Left(cFile, Len(cFile) - 4) + ".ext" to   cutExtension( cFile ) + ".ext"
' 2005-05-25 add function cutExtension. Filename could be without extension,
'                     also extension could be longer or shorter than 3 characters
' 2005-05-24 tested on OpenOffice 1.1.1 and 1.9.95
' 2005-05-24 initial

Sub HTMLtoSXW( cFile )
  If Not FileExists ( cFile ) Then exit Sub
  oDoc = StarDesktop.loadComponentFromURL( ConvertToURL( cFile ), "_blank", 0,_
   Array( MakePropertyValue( "Hidden", true), MakePropertyValue( "FilterName", "HTML (StarWriter)")))
  ' Save the document using no filter.  Thus saves a native Writer document.
  oDoc.storeToURL( ConvertToURL( cutExtension( cFile ) + ".sxw" ) , Array() )
  oDoc.close( True )
End Sub

' need for OpenOffice 1.1.1, under 1.9.x possible to use AsPDF
Sub HTMLtoPDF( cFile )
  If Not FileExists ( cFile ) Then exit Sub
  oDoc = StarDesktop.loadComponentFromURL( ConvertToURL( cFile ), "_blank", 0,_
   Array( MakePropertyValue( "Hidden", true), MakePropertyValue( "FilterName", "HTML (StarWriter)")))
  oDoc.storeToURL( ConvertToURL( cutExtension( cFile ) + ".pdf" ),_
   Array(MakePropertyValue( "FilterName", "writer_pdf_Export" )) )
  oDoc.close( True )
End Sub

Sub AsSXW( cFile )
  If Not FileExists ( cFile ) Then exit Sub
  oDoc = StarDesktop.loadComponentFromURL( ConvertToURL( cFile ) , "_blank", 0,_
   Array( MakePropertyValue( "Hidden", true) ) )
  ' Save the document using no filter.  Thus saves a native Writer document.
  oDoc.storeToURL( ConvertToURL(  cutExtension( cFile ) + ".sxw" ), Array() )
  oDoc.close( True )
End Sub

Sub AsPDF(cFile)
  If Not FileExists ( cFile ) Then exit Sub

  Dim strFilterSubName as String
  oDoc = StarDesktop.loadComponentFromURL( ConvertToURL( cFile ), "_blank", 0,_
   array(MakePropertyValue("Hidden", true)) )
  If not IsNull(oDoc) Then
    strFilterSubName = ""
    ' select appropriate filter
    If oDoc.SupportsService("com.sun.star.presentation.PresentationDocument") Then
      strFilterSubName = "impress_pdf_Export"
    ElseIf oDoc.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then
      strFilterSubName = "calc_pdf_Export"
    ElseIf oDoc.SupportsService("com.sun.star.text.WebDocument") Then
      strFilterSubName = "writer_web_pdf_Export"
    ElseIf oDoc.SupportsService("com.sun.star.text.GlobalDocument") Then
      strFilterSubName = "writer_globaldocument_pdf_Export"
    ElseIf oDoc.SupportsService("com.sun.star.text.TextDocument") Then
      strFilterSubName = "writer_pdf_Export"
    ElseIf oDoc.SupportsService("com.sun.star.drawing.DrawingDocument") Then
      strFilterSubName = "draw_pdf_Export"
    ElseIf oDoc.SupportsService("com.sun.star.formula.FormulaProperties") Then
      strFilterSubName = "math_pdf_Export"
    ElseIf oDoc.SupportsService("com.sun.star.chart.ChartDocument") Then
      strFilterSubName = "chart_pdf_Export"
    Else
    '
    EndIf
  EndIf 

  If Len(strFilterSubName) > 0 Then
    oDoc.storeToURL( ConvertToURL( cutExtension( cFile ) + ".pdf" ),_
     Array(MakePropertyValue( "FilterName", strFilterSubName )) )
  EndIf
  oDoc.close(True)
End Sub

Function MakePropertyValue( Optional cName As String, Optional uValue )_
 As com.sun.star.beans.PropertyValue
  Dim oPropertyValue As New com.sun.star.beans.PropertyValue
  If Not IsMissing( cName ) Then
    oPropertyValue.Name = cName
  EndIf
  If Not IsMissing( uValue ) Then
    oPropertyValue.Value = uValue
  EndIf
  MakePropertyValue() = oPropertyValue
End Function

' cut last piece of filename which beginning with "."
Function cutExtension ( cFile )
  splitFilename = Split ( cFile, "." )
  uboundArray = UBound( splitFilename )
  If uboundArray > 0 Then '-------- filename has a part with dot
    ' assemble filename back without last part
    For index=0 to uboundArray - 1
      saveFilename = saveFilename + splitFilename(index) + "."
    Next index
    ' cut last "."
    cutExtension = Left( saveFilename, Len( saveFilename ) - 1 )
  Else '--------------------------- filename has not a part with dot
    cutExtension = cFile
  Endif
End Function
</pre>
<p>5. Save and compile the module.</p>
<p>6. Download a recent versoin of <a href="http://shuvalov.com/storage/LevShuvalov/openoffice/OOo_convert.bat">DOS batch file</a> or/and <a href="http://shuvalov.com/storage/LevShuvalov/openoffice/OOo_convert.sh">BASH script</a>. Or copy-paste text below:</p>
<pre>
@echo off
rem
rem  Run command line conversion HTML, DOC, RTF etc to SXW and PDF through OpenOffice.
rem
rem  2005-05-26  revision

set OfficeDir=C:Program FilesOpenOffice.org 1.9.104program
rem set OfficeDir=C:Program FilesOpenOffice.org1.1.1program

if "%1"=="" (
  echo:
  echo  Cannot find what file[s] need to convert
  echo:
  echo  usage:   OOo_convert.bat full_path_to_exact_file_or_wildcard
  echo  example:
  echo           OOo_convert.bat C:tmpconverttest.doc
  echo           OOo_convert.bat C:tmpconvert*.htm
  echo:
  exit
)

echo Converting...
  for %%c in ("%1") DO (
    echo %%c

    "%OfficeDir%soffice" -invisible "macro:///LevShuvalov.Convert.HTMLtoSXW(%%c)"
    rem "%OfficeDir%soffice" -invisible "macro:///LevShuvalov.Convert.HTMLtoPDF(%%c)"
    rem "%OfficeDir%soffice" -invisible "macro:///LevShuvalov.Convert.AsSXW(%%c)"
    rem "%OfficeDir%soffice" -invisible "macro:///LevShuvalov.Convert.AsPDF(%%c)"
  )
echo Done.
exit
</pre>
<p>or</p>
<pre>
#!/bin/bash
#
#  Run command line conversion HTML, DOC, RTF etc to SXW and PDF through OpenOffice.
#
#  2005-05-27  revision

OfficeDir="/home/users/lev/oo14"

if [ "$#" -lt "1" ]; then
  echo
  echo  "Cannot find what file(s) need to convert"
  echo
  echo  "usage:   OOo_convert.sh full_path_to_exact_file_or_wildcard"
  echo  "example:"
  echo  "         OOo_convert.sh /tmp/convert/test.doc"
  echo  "         OOo_convert.sh /tmp/convert/*htm"
  echo
  exit 1
fi

echo Converting...
  for file in "$@"
  do
    echo "$file"

    "$OfficeDir/soffice" -invisible "macro:///LevShuvalov.Convert.HTMLtoSXW($file)"
    #"$OfficeDir/soffice" -invisible "macro:///LevShuvalov.Convert.HTMLtoPDF($file)"
    #"$OfficeDir/soffice" -invisible "macro:///LevShuvalov.Convert.AsSXW($file)"
    #"$OfficeDir/soffice" -invisible "macro:///LevShuvalov.Convert.AsPDF($file)"
  done
echo Done.
exit 0
</pre>
<p>7. Under linux change permissions for OOo_convert.sh.</p>
<pre>
$chmod 750 OOo_convert.sh
</pre>
<p>8. Change the variable OfficeDir  and choose function for conversion then  you can run script. <b>Do not forget</b> to give a full path to a temporary directory / folder for conversion or to a exact file.</p>
<pre>
>OOo_convert.bat C:tmpconverttest.doc
</pre>
<p>or</p>
<pre>
$OOo_convert.sh /tmp/convert/test.doc
</pre>
<p>If you for some reason you remove line of code <code>If Not FileExists ( cFile ) Then exit Sub</code> and give an incorrect file name for conversion also if you give a relative path to a temporary directory or to a exact file. You will get error message under <a href="http://www.openoffice.org/">OpenOffice</a> 1.1.x  &#8220;<b>Object variable not set</b>&#8221; and under <a href="http://www.openoffice.org/">OpenOffice</a> 1.9.x &#8220;<b>URL seems to be unsupported one</b>&#8221;</p>
<p>If a chosen filter is incorrect for current file format you also will get &#8220;<b>URL seems to be unsupported one</b>&#8220;.</p>
<p>Many thanks to <b>Danny Brewer</b> who actually made these functions, I just collect them. <img src='http://shuvalov.com/system-administrator/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://shuvalov.com/convert-html-doc-rtf-etc-to-sxw-and-pdf-through-openoffice-in-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>commenting out a block of bash code</title>
		<link>http://shuvalov.com/commenting-out-a-block-of-bash-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=commenting-out-a-block-of-bash-code</link>
		<comments>http://shuvalov.com/commenting-out-a-block-of-bash-code/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 06:32:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[cli]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://administrator-system.com/system-administrator/?p=104</guid>
		<description><![CDATA[#!/bin/bash : &#60;&#60; COMMENTBLOCK echo "This line will not echo because the Bash interpreter will ignore it." COMMENTBLOCK]]></description>
			<content:encoded><![CDATA[<pre>
#!/bin/bash
:  &lt;&lt; COMMENTBLOCK
  echo "This line will not echo because the Bash interpreter will ignore it."
COMMENTBLOCK
</pre>
]]></content:encoded>
			<wfw:commentRss>http://shuvalov.com/commenting-out-a-block-of-bash-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>finding all executable files on the system</title>
		<link>http://shuvalov.com/finding-all-executable-files-on-the-system/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=finding-all-executable-files-on-the-system</link>
		<comments>http://shuvalov.com/finding-all-executable-files-on-the-system/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 15:41:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[cli]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://administrator-system.com/system-administrator/?p=102</guid>
		<description><![CDATA[find / -type f -perm +0111]]></description>
			<content:encoded><![CDATA[<p><code><br />
find / -type f -perm +0111<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://shuvalov.com/finding-all-executable-files-on-the-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

