Search This Blog

Saturday, October 6, 2007

Auto-Convert HTML to PDF in OpenOffice 2.3 on Windows

Figuring this out took me quite a while, but I finally managed to make OpenOffice 2.3 convert HTML pages to PDF from the command line. The big problem was that all the examples I found had slightly different requirements, so the code didn't work for me (especially when starting soffice with "-invisible"). Here's how to do it:

We need three macros, one for the document conversion, one as a helper to save further typing by easing the creation of OO PropertyValues and one to quit OpenOffice after that. So you need to open an OpenOffice app and select "Extras -> Macros -> Manage Macros -> OpenOffice.org Basic..." from the main menu. The window that pops up should already point to "My Macros / Standard / Module1", if not, navigate there. Click on the "Edit" button and insert the following in the end of the editor window:

Sub EndOO
StarDesktop.Terminate()
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

sub PDFExporting( iFile As String, targetFile As String )
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim oDoc as object
dim dispatcher as object
dim oDesk as object
rem ----------------------------------------------------------------------
rem load the document

inURL = ConvertToURL( iFile )

oDesk = createUNOService("com.sun.star.frame.Desktop")

oDoc = oDesk.loadComponentFromURL( inURL, "_blank", 0, Array(_
MakePropertyValue( "Hidden", True ) ) )

rem get access to the document
document = oDoc.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(3) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = ConvertToURL(targetFile)
args1(1).Name = "FilterName"
args1(1).Value = "writer_pdf_Export"
args1(2).Name = "FilterData"
args1(2).Value = Array(_
Array("UseLosslessCompression",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("Quality",0,90,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("ReduceImageResolution",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("MaxImageResolution",0,600,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("UseTaggedPDF",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("ExportNotes",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("UseTransitionEffects",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("FormsType",0,1,com.sun.star.beans.PropertyState.DIRECT_VALUE),_
Array("",0,,com.sun.star.beans.PropertyState.DIRECT_VALUE))
args1(3).Name = "SelectionOnly"
args1(3).Value = true

rem the actual conversion
dispatcher.executeDispatch(document, ".uno:ExportToPDF", "", 0, args1())

end sub


Now just save the changes and close everything. The OpenOffice part is finished, now let's just put a small batch file in our path that does the calling and knows the path to OpenOffice. Open your text editor and insert the following without any newlines (make sure that the path to soffice.exe is correct):

"C:\Program Files\OpenOffice.org 2.3\program\soffice.exe" -invisible macro:///Standard.Module1.PDFExporting("%1","%2") macro:///Standard.Module1.EndOO()


Save the text file in your windows directory (usually C:\WINDOWS) with the name oo2pdf.cmd.

Now you can call it from the command line with the complete paths to the input html and output pdf as parameters:

oo2pdf "C:\Documents and Settings\MyUserName\MyDocuments\input.html" "C:\Documents and Settings\MyUserName\Desktop\output.pdf"


Added: With thanks to John (see the comment), here's the bash command line for *nix-ish operating systems:
soffice -invisible macro:///Standard.Module1.PDFExporting\(infile.htm,outfile.pdf\) macro:///Standard.Module1.EndOO\(\)

Wednesday, May 9, 2007

New Chapters for my FanFics

If you have been following my Harry Potter 7th-year fanfic, you might be happy to hear that both the German and English version have a new Chapter. If you don't know my fics please have a look and let me know what you think.

English: Harry Potter and the Fifth Soul

German: Harry Potter und die Fünfte Seele

Tuesday, April 17, 2007

Yes, I'm still alive...

...though I'm suffering under a heavy wheather's-nice-but-have-to-work syndrome. On Sunday I was trecking again, together with two friends. We went to Gmunden (some of you may have heared of the famous Gmundener Porcelain) and from there up to the Traunstein. It's a really beautiful mountain with a breathtaking view over the Traun Lake from the top. The weather was unbelievable, it was 26°C in the shadow while we had to wade through a half meter of snow for the last 200 height meters. The treck starts 400 meters above zero and goes up to almost 1700 meters, with a lot of ladders and steel ropes. Nothing for trainer tourists :) I hope to get some photos this week from Peter (he shot like crazy, I'm still astounded that his memory stick didn't burst) to publish on picasa, then I'll put a link here.

If you happen to be in the area and aren't opposed to a bit of casual climbing, you should definitely try the Naturfreunde-Steig there.

Thursday, March 15, 2007

Mountain Trecking

Yes, I know mid March is a bit early, but the weather was just soo good and, seeing I didn't have anything better to do for my holydays, I went on a three day tour in the Bavarian Alps, close to Berchtesgaden. I really had a good time there, and as there weren't many tourists -- too little snow to do serious wintersports, too much for the unexperienced hiker -- it was really peaceful and relaxing. I made some photos that are worth taking a look at, here's the link to the Picasa galleries:

Alpine Trecking - Day1 - Wimbachklamm



Alpine Trecking - Day2 - Hirchbichl



Alpine Trecking - Day3 - Kueroint-Alm and Gruenstein

If I find the time, I'll write a bit more about the tour itself. In any case, if you happen to be in the area in spring and have sunny weather, each of those three tours can be easily made in a day and has its own beauty.

Saturday, March 3, 2007

From ff.net to ebook for the PDA

Hi there!

Ever had your back hurting from sitting in front of the computer for too long, reading stories on fanfiction.net or fictionpress.com? I for one had, so I decided to use my Pocket PC as an ebook reader. After a lot of tries and errors I found the best way to move the stories to my PocketPC is to download everything, combine the different chapters in a single file and export them in tagged PDF format.

For everyone not familiar with PDF, it's an open, print orientated document format. The "tagged" part means that paragraphs and pages have special markers, so the reader application knows which parts should stay together, and where it is allowed to enter line breaks. Normal PDFs don't have that kind of markup, which will have you scrolling left and right like a berserk, which seriously dulls the whole reading experience. Though the Adobe Reader for PocketPC/Windows Mobile can tag documents when you copy them to the device via Microsoft ActiveSync, this doesn't work very well (in fact, it often chokes on bigger docs) so I don't recommend this.

I've also found that just copying+pasting into a document often leads to strange font interpretations, which in turn lead to error messages or crashes on the PDA.

So what I do is the following:
  • Download all the chapters lokally;
  • Extract only the story parts, without all the fancy JavaScript parts
  • Convert everything to UTF-8 charset
  • Combine all chapters into a single HTML document
  • Open the HTML file with OpenOffice.org writer (Version 2)
  • Export to PDF with the "Create tagged PDF" option enabled
Of course, being a computer programmer, the first four steps were a lot too tedious for my taste, so I wrote a small Perl application that does it for me and only needs the story id and the output filename for the HTML. It can't be found online, but if you need it, let me know.

Friday, March 2, 2007

Bored? Maybe I can help :)

I didn't believe it first, but a short fic I wrote for the usenet group alt.fiction.original made first place in the monthly challenge. Admittedly, it's not as competitive as a regular writing contest, but it isn't the "making first" part that brushes my ego anyway. What made my day is that my (written) English has improved so much.

If you like a bit of mystery, take a look at it, and let me know what you think.

This story is based upon the painting "Wheatfield with Crows" by Vincent Van Gogh, which you can view at http://tinyurl.com/2vkeb2

People Watching

If you could see me at one of those very moments, you would probably scream aloud and run off in panic, or stand frozen to the spot and shiver all over. That's how everyone has reacted so far. And I can understand that sentiment. I can almost feel the veins in my eyes pop from the excitement, my raven black hair getting stuck in a sweaty mess, and finally, when my fangs slowly break her skin and blood starts dripping down over my pale chin, it must be unearthly to behold.

You wouldn't dare ask me how I came to be what I am. I've told each of them, given myself in to the illusion of honesty, and, deep down, pleading for just a tiny bit of understanding. Which, of course, isn't to be found in the eyes of the girl whose live I am about to slowly drink. They wouldn't understand, and I doubt they even comprehend what I am telling them. That it has all been Vincent's fault.

It was my first trip to Amsterdam, and at that time - barely fifteen years of age - spending your holiday in Amsterdam was far from being exciting. I had tried everything I could think of to persuade them to go somewhere sunny, like the Canaries or Italy, but this time I was simply outnumbered. Ela, my sister, had been bubbling weeks in advance about museums and buildings, while Mom had just kept going on about those 'beautiful canals' with their 'lovely little boats', and how much fun it would be.

Of course, Dad didn't dare to oppose Mom. He was much too fearful to have her wrath hanging over him for two weeks, without any means to get away. And they didn't let me stay at home either, I guess they knew me too well. Though they didn't know about the packet of cigarettes that I had hidden in the attic, which would have made me the king of the lake this summer - at least for a few days. And they didn't know about that cute blonde girl, Susie, who had let me know rather straightforward that she wouldn't mind a bit of snogging in exchange for a smoke.

But that had to wait, for now I was perched in the small breakfast room of the run down guest house with the rest of my family, sulkily spooning cereals into my mouth and trying to shut out all the annoyingly excited tittering of the females. Dad didn't seem too eager about his bacon and
eggs either, and we both were glad when we could finish breakfast and head for the city.

To be honest, Amsterdam IS a beautiful city, but you will understand shortly why I'll never be able to appreciate the view.

After breakfast we walked through the old town for a bit, which, in my mind, wasn't an appropriate activity for a boy, and thus didn't heighten my mood at all. When we arrived at the central railway station we took a tram to the Van Gogh Museum. Strangely, I can still remember that the
bright yellow wagons with their red doors had the number 5 on them, and ever since that day I haven't been able to suppress a shiver each time I came across a tram or bus with that number.

But first things first. Though it was, in my opinion, rather early in the morning, the museum itself -- an absolutely ugly assortment of concrete blocks - was far from deserted. I convinced my parents to let me go on my own, and we agreed to meet at half past eleven at the cafeteria. While the others made their round, oohing and aahing at the silly squares on the walls, I went looking for a good spot where I could exercise my most popular pastime. I called it 'People Watching', but it was more than just watching.

What I was playing was a little mind game, picking out two of the people in the crowd and imagining how one could kill the other.

Now you're surely thinking, ah, see, he's been not quite right in his head all along. You're wrong. It's just that I was a rather bored fifteen year old with a gushing imagination who loved to read crime novels and horror stories. And I wouldn't simply go for the quick kill.
Each of my 'victims' got a detailed personality and background, and the crime itself -- or mystery, depending on the mood of the day -- would have been worth ninety minutes of movie time. Or at least I thought so.

I had barely finished off victim number three - a stern looking old lady, who had her heart frozen by a cheery girl of about ten that was in fact a witch under a glamour charm -- when I saw her. About my age, a bit pale, with a bush of red hair and big -- or even huge, if an insensitive prat like myself was able to notice them from almost fifty feet away -- brown, nearly black eyes. Like myself, she was sitting on one of the coloured, waist high plastic cubes that were scattered everywhere, and from the looks of it, she was playing her own game of 'People Watching'.

When she suddenly lifted her head and looked straight at me, I was mesmerised. She herself seemed curious, raising an eyebrow and frowning. I kept staring at her, wondering if her clothing was a Netherlandish thing, as it would have fit more into 'Alice in Wonderland' than into our current time. A long, plaided skirt and a frilly white blouse with lots of tiny red bows. With a knowing smile she jumped down from the cube and strode over to me. I wouldn't have been able to look at anything else, even if I had tried, and for a second I felt a
disturbingly cold knot in my stomach. But it vanished as quick as it had come, and now I was looking forward to getting to know her.

I should have taken this moment and bolted away as quick as my feet would have carried me. Yet I didn't, and maybe I never had the chance anyway.

Then she was standing before me, just an arm length away, and asked me something in Dutch. I didn't understand a word of it. I mumbled 'sorry', and she repeated it in English. Her voice sounded older than she looked, and it carried something, a timbre, that made the hairs on my arms stand.

If you want to know what we talked, I'm at a loss. I only remember the sound of her voice, and my mouth answering out of its own will, and the next thing being led in front of one of the paintings by her. It was one of the popular ones, titled 'Wheat Field with Crows'.

It's a bit disturbing to watch it, for the normal eye at least. The better part of it shows just what the title says, a golden wheat field, over which a swarm of black birds approaches. It's divided by a gravel road that looses itself in the distances. What really hurts the eye is
the unnatural blue sky that fades to blackness, carrying a foreboding that is accentuated by two moons rising from the horizon.

"Look at it," her voice told me, "look very close."

If someone should tell you to do so, jump, run, flee, but, by all that's holy, do not look! Though I did look, and had I still a heart, it would beat like mad now just thinking of what I saw.

One moment I was standing in a boring museum, the other I found myself in the middle of nowhere. Though the view hadn't really changed, the wheat field in front of me, the black birds approaching under the nightly sky. And that was the moment I became aware that I was doomed, that something was so completely wrong about the situation that I
wouldn't be able to mend it. The birds were in fact approaching, and rather quickly at that. And though they were really close to me, I couldn't hear the faintest sound of crowing or wings flapping.

Have you ever encountered a swarm of bats on a warm summer night? If yes, you know this feeling, that there should be some kind of noise. If you're lucky, they fly so close to you that you can hear it, only for a second, the soft, high pitched whistling of air streaming over their featherless body.

That day, I was 'lucky'. Though the whistling was a lot louder than I could have anticipated, and when one of them flew a turn around me and set its feet on the floor before me, I was by no means prepared for the sight that greeted me. The thing, the monstrosity, however you like to call it, folded its wings and rose upright, watching me with huge, almost black eyes. The bit of red fur on its head reflected the moonlight, and when it began to speak to me I knew it was her.

"Welcome, young hunter." She greeted me, exposing two sets of long, needle sharp fangs as she did so.

I was frozen in my place, and recognizing her intention, I search frantically for words. "Why me?" Was all I managed to mutter.

"Oh don't you see it," she purred, "you're a hunter, like we are. You could never be anything else."

My eyes met hers again, silently begging to be spared, but we both knew there was no way out. After I had fought the wave of pure terror that washed over my nerves, I gave in, and felt -- relieved? As if I had always known, deep down inside, that this day would come. Maybe it was just her magic that was working on me, I'll never know for sure.

Then I knew what to do, without being told, and I fell to my knees before her, inclining my head to give her access to my nape. I closed my eyes and waited for it, feeling her soft, furry body touch me briefly, before her fangs penetrated my skin, only some small pricks at first,
but quickly turning into searing fire that ran all through my veins.

You wouldn't have expected dying -- at least clinically - to be an enjoyable experience, would you? Thank God it didn't take long, and when the pain ebbed away, she started to giggle, her voice carrying through the night like the sound of a most lovely wind chime. The other creatures -- hunters, I should call my fellows now - whistled from all around us.

"I was Vincent's favourite," she told me in a sultry voice, "and you'll be mine. No go, hunt for me."

Since then, if you look close at the painting, you can make out an additional 'crow' just where the sky turns to black. But don't look for too long.

And if you happen to be a teenage girl and ever see a boy of about fifteen, with raven black hair, too pale skin and a faraway look in his eyes - jump, run, flee, but by all that's holy, don't get curious!

After all, it may be me, playing 'People Watching'.

Hope you liked it.

Tuesday, January 30, 2007

Hi There...

...and welcome to my assorted personal ramblings. I just "moved in", so there's nothing exciting to be found yet. Let's just see what comes up over time.

Have a good time
-BitPoet