[BL] simple doc to png convertor

sindi keesan keesan at sdf.lonestar.org
Mon Apr 25 17:07:58 EDT 2005


On Mon, 25 Apr 2005, David Moberg wrote:

> ----- Original Message -----
> From: "sindi keesan" <keesan at sdf.lonestar.org>
>
>>>> The doc file has a lot of <FF) and @^ and then <89>PNG.  At the end
>>>> it has more <FF> and @^ and then something about WORD.
>>>>
>>>> I could probably just use a text editor to manually chop off the
>>>> beginning and end of this sort of doc file instead of wvware, but
>>>> can someone suggest a script which would delete all characters
>>>> before <89>PNG
>>>
>>> #!/bin/sh
>>> export POSIXLY_CORRECT=""
>>> expr index "`cat $1`" "`echo 3PNG | tr 3 '\211'`" >/tmp/1
>>> expr `cat /tmp/1` - 1 >/tmp/1
>>> expr `cat $1 | wc -c` - `cat /tmp/1` >/tmp/1
>>> tail -c `cat /tmp/1` $1
>>> rm -f /tmp/1
>>
>> I have non-busybox tail and busybox tr, wc, cat, and expr.
>
> wc and expr are probably fouling things up. Please try the full
> versions.

/a15/txtutils.tgz has tr, wc, cat, tail
/a11/sh_utils.tgz has expr
/n6/wget.tgz

Anything else I should install to replace busybox?

I again ran this script calling it doctopng (I created it by downloading 
your email and trimming off top and bottom).  doctopng doc1.doc > doc1.png

expr:  syntax error
tail:  doc1.doc invalid number of bytes

I have now /usr/bin/expr not busybox.

No /tmp/1 file was created.  I am running this as root in /tmp (the script 
and the starting .doc file are in /tmp).

>> How did <80>PNG become 3PNG?
>
> It didn't.
>
> echo 3PNG | tr 3 '\211'
>
> tr changes 3 to '\211' which equals <89>

If <89> is hexadecimal is that 8x16+1 (129)?
If so, what system is 3 and \211?


>> I downloaded this email and copied the above to a program doctopng,
>> chmod +x'ed it, and then typed doctopng doc1.doc > doctopng.png
>>
>> I get the error message:
>> tail: doc1.doc:  invalid number of bytes
>
> wc is probably not giving correct output. With the POSIXLY_CORRECT
> environment variable set to "", my wc gives the following output:
>
> $ wc -c file
> 345
>
> The number given should equal the filesize in bytes. There should
> only be one number. Also, there should be no indentation.
>
>> Are you using wc to count the number of bytes before PNG and then
>> trying to remove that number of bytes from the start of the file
>> with tail?
>
> Yes.

>>>> The png file ends with IEND<AE>B`<82>.  The WORD file continues
>>>> with many pages of @^ (to encourage you to get a larger hard
>>>> drive?) and <FF> and then the names of the two people working at
>>>> that office repeatedly, some comments on what is in the document
>>>> that they probably added, and various mentions of Microsoft Word
>>>> 9.0.  So I could also just chop that off.
>>>
>>> Do you want a script that does that, too?
>>
>> One that does both would be ideal so that I will have just the PNG part.
>> I had no idea it would be that complicated.  With pico I just
>> search on PNG and END and delete by blocking and Ctrl-K.
>
> Get this one working first. Another one to trim the end off will be much
> easier.
>
>>>> <82> is presumably a hex character and perhaps a shell script would
>>>> need to refer to it differently.
>>>
>>> Very differently for <89>. The method I used above is very ugly.
>>
>> Maybe there is a simpler way?
>
> Not likely. A C program would be simpler for me.
>
>> Yes, this file starts and ends exactly the same way as the one in the doc.
>> <89>PNG and IEND....<82>
>
> OK. I will work on a variant to trim the end off.



> David
> --

Sindi



More information about the BasLinux mailing list