Archive | editing RSS for this section

gifsicle on Cygwin

Installing gifsicle on Cygwin is really easy, which it has to be if I am to do it. The website includes binaries for many platforms (Linux, Windows, even DOS), but not for Cygwin. Because care is taken when putting the code together, building it on Cygwin is trivial. Yay! I have an ‘installs' folder inside my /home/username folder on Cygwin, and I did the compile in there. Note that if the version number changes the wget line and the working directory name have to be changed accordingly.

$ cd installs

$ mkdir gifsicle

$ cd gifsicle

$ wget  http://www.lcdf.org/gifsicle/gifsicle-1.91.tar.gz

$ tar xvzf gifsicle-1.91.tar.gz

$ cd gifsicle-1.91

$ ./configure

$ make

$ make install

And that is it! Excellent.

Now, I installed it to take an existing animated gif and loop it.

$ gifsicle.exe -i banner.gif --loopcount=forever > banner2.gif

And that works easily!

For working with animated gifs, gifsicle is really the only tool!

I’m in the mood for using exclamation marks!

 

gif

Advertisements

PowerPoint embed fonts

If you don’t embed fonts in a PowerPoint file, you cannot be sure how it will look an any computer other than the one used to write it — unless you stick to the most common fonts (Arial, Times New Roman, that sort of thing).

To embed the fonts in the PPTX file (Office 365 on Windows 10):

File → Save As → More options → Tools → Save Options → Embed fonts in this file

It’s a lot of clicks.

Showing where to find the tools menu.

The ‘Tools’ menu and ‘Save Options’ — not where you might expect it.

 

Then when you try to save, you might get something like:

Warning that a font is not available for embedding.

Warning!

Now, in some cases that means you need to install the font, but if it is installed and you still get that message then that means the font is not licensed for embedding. So you can either live with it or change it.

To change it

Home → Replace → Replace Fonts

and fill out the dialogue box. But I found that this (possibly) did not work. When I clicked ‘Replace’ it put the ‘With’ font into the ‘Replace’ box and when I went to save I still got the ‘Font not available’ error. Since I’m not sure where in the document the font is used, I’m not sure whether it was replaced but somehow still listed as ‘required’, or just not replaced.

This movie shows how the Search box suddenly gets changed to the wrong font when I press ‘Replace’. It seems to search for the one I want to replace with, not the one I want to replace…


 

So I dunno.

Note: Animated gif (above) made using PowerPoint (Insert → Screen Recording to make an mp4 and then ffmpeg to make the animated gif, since WordPress does not like mp4s. ($ ffmpeg.exe -i example.mp4 frames.gif).

Too much

GIMP, transparency and PowerPoint

This is just something I worked out how to do recently. It’s simple and I think looks quite good.

Let’s say I’m putting together a PowerPoint presentation because I have to. I want to show an example of a document I have put together, a sort of sheaf of pages or screens.

I open GIMP and create a new image that is big enough in pixels to contain everything I want.

File → New

Then I open the images I want to combine into the one image. I’m going to use this and this, or something very similar.

I open them in GIMP as layers into my empty image.

Open → Open as Layers

Then in the new now-not-blank image, Layer → Scale Layer and enter the desired height.

Repeat with the second image, using the same height (in this case).

Position as desired.

(Now, this helps:

Edit → Preferences → Tool Options → Set Layer or Path as active (https://ubuntuforums.org/showthread.php?t=1656588))

Could rotate etc, but not for now.

Layer  Transparency → Add Alpha Channel

Now, there are a few ways to make the background transparent. In this case, I can just go:

Layer  Transparency → Color to Alpha

And I get a screen like this:

Screenshot

The Color to Alpha dialogue

If I click on the eyedropper beside the ‘Color’ box (the one currently showing a white rectangle) I can then click on the black of the background to get this:

Screenshot

Showing the transparent regions as chequerboard patterns.

Note the colour rectangle has turned black and the black background is now denoted as transparent/Alpha by the pattern.

I can then export to png, say, to get a graphic with transparency. But, the Color to Alpha option has a problem. In this case, I have other layers in front of the background. But let’s imagine you had a single layer and wanted to make a red border transparent. If you make all the red transparent, that will include the red component of compound colours, like orange. So any colour that has a red component will be changed. I can illustrate this by flattening this image, so it is a single layer, then repeating the process.

Image  Flatten Image

Then do the same as above — add an Alpha channel and then make black into Alpha. My screenshot now looks like this:

Screenshot, showing that making black transparent has removed blacks from the images and changed their colours.

When I flatten first.

The blacks have been made transparent everywhere, so the darknesses of all the tones have changed — not what I wanted. Instead, I need to use the fuzzy select tool. After adding the Alpha channel, I can do this:

Tools → Selection Tools → Fuzzy Select

Then I click on a visible bit of the background. Then hit Delete. That should select the background and then delete it, leaving only the transparent Alpha channel. Here’s the screenshot — looks OK.

Screenshot -- looks good.

The image after using the Fuzzy Select tool.

And now I have what I want. In this case, I may as well keep the image with the layers, since that allows more flexible editing at a later date, but this Fuzzy Select business is useful if the image is a single layer, say a bitmap that cannot easily be separated into layers. The fuzzy select is clever, but may not always highlight exactly what is wanted, especially if colours blend into each other. YMMV.

Anyway, once the transparency is as desired, I can Export as a png. I just use the defaults. Now, Here is the resulting png on a very simple page in PowerPoint. I have used PPT options to add shadows to bottom and right; note that PPT is clever enough to only shadow the non-transparent bits of the image. Maybe you take that for granted. I, in my ignorance, was quite pleased.

Screenshot.

PPT only puts shadows behind non-transparent pixels.

Transparency lets images overlap more naturally, lets your slide background and theme show through more regularly, and generally gives a more professional appearance since you can get away from that look of simply having a bunch of rectangles.

 

FWIW

ERROR NAME; undefined COMMAND; Prolog OPERAND STACK;

Well, wanted to print a PDF. I am using Debian 9.5 and printing from Atril to a Brother HL-5340D; pretty standard stuff.

PDF viewed fine, but give these errors on printing (just scanned them in):

Scan of pages showing errors

Errors on printing a PDF — the text after ‘COMMAND;’ was not always the same, as you can see.

Nuts. Tried running pdf2ps and printing the .ps file, but no good. Tried running the .ps through ps2ps and then converting the new .ps to PDF using ps2pdf, but that did not work either.

pdf2sjvu worked, in that it gave a printable file (just ran the converter, opened the .djvu file in Atril and printed it).

Tried running pdftops (note ‘to’ instead of ‘2’) and then printing the resulting .ps file from Atril. That also worked.

The .ps file from pdftops was 13 MB. The .djvu file was 241 KB. Running ps2pdf on the .ps file from pdftops gave a 4.9 MB .pdf, which also printed.

The conversion to DjVu is lossy — there are noticeable differences between the .djvu file and the .ps and .pdf. But not enough to be a problem.

Conclusion: If fidelity is important, error can be avoided using pdftops. If file size is important, pdf2djvu is an option.

pdftops is part of the xpdf package. pdf2ps is part of Ghostscript. pdf2ps is perfectly good in many circumstances, but does not seem to avoid propagating this error, whatever the error is. Possibly there are command line options that would fix the issue.

DjVu is not used all that much, but was designed to reduce file sizes when storing documents digitally. It has many nice features, but is unlikely to ever be a major player.

Bye.

Making a nice icon — Windows

OK, I downloaded the useful Free PDF Accessibility Checker (PAC 3) from https://www.access-for-all.ch/en/pdf-lab/pdf-accessibility-checker-pac.html.

Note: I am running Windows 10.

To install you just unzip the archive to somewhere convenient and then (in my case) double-click on ‘PAC English.bat’ — there is no need to actually install as such, which is great because users without administrator rights can use it.

I right-clicked on the bat file and got Windows to make a shortcut, which I then put on the desktop. Now — I wanted an icon.

(1) Fired up GIMP. File → Create → Screenshot and clicked ‘Take a screenshot of the entire screen’. Left the dialogue box open and …

(2) Double-clicked the PAC 3 shortcut. The little initialisation dialogue came up, and it has a nice graphic on it.

(3) Clicked ‘Snap’ on the GIMP dialogue.

(4) Cropped out the little icon I wanted. The startup dialogue box looked like this:

Screen shotAnd I thought the yellow and blue shape in the middle would be good. Cropping in GIMP — Tools  Transform Tools Crop, then box what you want and hit Enter.

(5) That gave this:

Image showing the bit that's going to be the icon(6) Now, you can just export that to a ‘.ico’ file from GIMP, but I decided to make it a bit nicer.

Layer  Transparency  Add Alpha Channel

Layer  Transparency  Colour to Alpha, and clicked ‘OK’

GIMP is clever enough to default to turning the white background into the alpha channel. That made it transparent.

(7) File  Export As…, and replaced the ‘.png’ in the file name with ‘.ico’ and made sure ‘Select File Type (By Extension)’ was listed. Could have pulled down the Select File Type menu and chosen Windows icon or whatever it says. Noted where I saved the file.

(8) On the PAC 3 shortcut, right-clicked and chose Properties  Change Icon…  Browse

Browsed to where I saved the .ico file and selected it. Done.

There is one little trick; if you want to update the icon and then update the shortcut to the new look, change the file name of the icon and reselect it, or Windows might not know that the icon has changed. If you don’t do this, Windows might update to the new icon if you reload the desktop or whatever, but renaming gives you backups of the older versions.

Here’s how the PAC 3 icon looks on the desktop:

Screen shot of the new icon on the desktop.

The transparency is a nice touch.

Iconik.

Brittle gum in abeyance

For a while I had a business website for Brittle gum editing, but I let it lapse (on purpose) when I started at Biotext. Now I just have a page on this blog — here, and pasted in below, since that way I get a blog post out of it as well…


Brittle gum editing was the little company I set up when I freelanced. Brittle gum refers to the trees that are scattered about where I live, not a dental condition.

I made up an icon/logo from a panel on our lead-light front door. I am not a graphic designer…

I now work at Biotext, publishers of the Australian Manual of Scientific Style and writers, editors and designers specialising in technical and government content. As a result, I am not maintaining the Brittle gum website, and this page now serves as a placeholder for Brittle gum’s web presence, which has otherwise ceased.

If you’d like to get in touch with me about Brittle gum editing, please send an email to darren.goossens@gmail.com.

me at good readsme at Research Gate -- not much happening there these days!me at twitterme at linked inme at orcid (researcher ID -- not likely to be very busy any more!)me at wordpress -- my main presence and this blog

 


Old content — nostalgia…

screenshot showing menus and images on the old front page

Brittle gum editing — old front page

Screen shot, mostly with a CV and picture of me, when I did not look so old.

Brittle gum editing — old ‘about us’ page.

Simple use of tesseract OCR on a multipage PDF

Using the command line to OCR a PDF file. Done in Cygwin. First, converted pages of the PDF to PPM files, which tesseract can read. Chose 300 dpi.

$ pdftoppm -r 300 pdf-filename.pdf page

The PDF is ‘pdf-filename.pdf’ and the PPM files will have names of the form ‘page-??.ppm’ since the conversion will add ‘-??.ppm’ to the given stem, where ?? is the page number.

Then, run tesseract

$ for f in *.ppm ; do tesseract $f $f ; done

So this loops over all files with ppm as the extension and runs tesseract, and just gives the file name itself as the stem of the output. That means we’ll end up with a bunch of files with names like ‘page-03.ppm.txt’. I could have used basename to chop off the ppm, but there’s just no need.

Next, combine the txt files.

$ cat *.ppm.txt > pdf-filename.txt

This shows another reason for keeping the .ppm in the file name — if I have other .txt files in the subdirectory, they will not get caught up in the cat.

If you are a very thorough person, you might call your final text file something like ‘pdf-filename-tesseractOCR.txt’ or something, to preserve some information about provenance.

This OCR engine is pretty good.

Once the text file has been examined, don’t need the .ppm and ppm.txt files, so

$ rm page-??.ppm*

Of course, if you are surer of what’s in the folder, you might go

$ rm *ppm*

Now, clearly this could all be wrapped up in a very simple script, something like this (script has some improvements over command noted above):

$ cat ~/bin/OCR-pdf.sh

#!/bin/bash
echo "1. Converting to png (limit 9999 pages or your disk space)"
gs -dBATCH -dNOPAUSE -sDEVICE=pnggray -r600 -dUseCropBox -sOutputFile=ZZZZpage-%04d.png "$1" 2> /dev/null > /dev/null
echo -n 2. Performing OCR
for f in ZZZZpage-????.png ; do echo -n . ; tesseract $f $f 2> /dev/null > /dev/null ; done
echo done.
prename=`basename "$1" .pdf
newname="$prename.txt"
echo 3. Creating text file "$newname"
cat ZZZZpage-????.png.txt > "$newname"
rm ZZZZpage-????.png ZZZZpage-????.png.txt
echo 4. Cleaning up

Where I’ve added a few bells and whistles. Note that the error output is all discarded (‘2> /dev/null’ means ‘send output stream 2 (stderr) to /dev/null, which makes it disappear) so if something does not work these bits should be removed.

‘echo -n’ means ‘echo but do not add a linefeed’. I have read that this does not always work, though in a bash implementation it should be fine.

This requires a working GhostScript interpreter. Other conversion paths are possible; the standard tesseract uses Leptonica, which can read ppm and png and other files, so pdftoppm as used above works, though ppm files are big and not compressed, which is why I changed to png — I note that the gs-based version picked up some text that the pdftoppm version did not, possibly because I went up to 600 dpi, but there may be some other factor at work, I can’t say for sure..

 

FWIW (for what it’s worth)

 

Word not checking spelling of comments, or not underlining words spelt wrong

If Word is not checking the comments, it is probably because the Comment Text style has got Do not check spelling or grammar selected.

If it is not underlining the misspelt words in the main text, your body style (probably Normal but it could be Body Text or something) probably has that box checked. Or a setting in File → Options → Proofing could be turned off.

Here is how to fix it.

Open the styles pane.

Screenshot.

Opening the Styles pane.

Then select a comment as if editing it. This should cause the Comment Text style in the Styles pane to be highlighted. Right click on Comment Text (or click the little down arrow beside it) and select Modify…

Screenshot

Modify the style

Then select Format (arrow 1) and Language (not shown) and then uncheck Do not check spelling or grammar (arrow 2).

Screenshot

Uncheck the box! It is already unchecked in this image.

Now the style should not be telling the spell checker to skip over it.

In my experience, this sometimes happens when a document created/modified in Word 2010 is then edited in a later version of Word, though I really don’t know exactly how it happens.

If that does not work, the Comment Text style may be inheriting Do not check from its parent style — usually Normal (you can see in the image above that Normal is in the ‘Style based on:’ field — that’s the parent style that Comment Text is inheriting many properties from). So do the same for Normal and then try again. Doing this for Normal will also make sure that the red wiggly line appears under misspelt words. If you are finding that Word will do the spell check when you click Spelling & Grammar from the Review ribbon, but is not highlighting errors, this could be why.

If that does not work — or you may try this first, I don’t know — go to File → Options → Proofing and go to the bottom. Uncheck Hide spelling errors in this document only (and also, if you want, Hide grammar…) and maybe click Recheck.

screenshot

More boxes — uncheck Hide spelling errors in this document only (and also if you want Hide grammar…) and maybe click Recheck.

Not sure if all steps necessary, but this was what I ended up doing.

YMMVW (your mileage may vary wildly)

WIldcard Search & Replace and Track Changes in Word

Begin rant.

 

I noted this bug once before. Put simply, if Track Changes is turned on in Microsoft Word and you try to do a wild card search and replace, it transposes the replace and mucks it up.

For example, I created a document with the word ‘card’ in it (as in wildcard), and then opened the Search and Replace box and selected Use wildcards and gave it the following instruction:

Find: ([a-c])r([d-e])

Replace with: \1OO\2

A word of explanation: Round brackets denote a numbered field. [a-c] means any character in the range a to c. So this command will look for patterns a b or c followed by r followed by d or e. The first matching character will be called group 1 and the third group 2. So the replace command should print the first group, then OO where the r was and then the second group, so that ‘card’ goes to ‘caOOd’.

But it does not. It prints ‘cadOO’ — group 1, then group 2 then OO — it transposes the fields. This is illustrated in the image below.

Screen shot from Word 97.

The search and replace box in Word. Track changes information omitted for clarity, but it is turned on.

Now, this is a pain of a bug for an editor who likes to save themselves some work in Word. Why? Because the client should get to see and OK/reject all the changes we make, and for that we use track changes, but this search and replace only works properly with track changes turned off.

So I can either forgo the tracking and edit quickly or edit manually. (Note: I know that in this example I did not need to use wildcards; it is just a demo!)

The really annoying thing is that the screen shot above is from Office 97. That is 21 years ago. This bug is present in the current version of Word, as of November 2018. This bug is 21 years old. This bug is allowed to vote, drink and fornicate. This surely says something about the culture at Microsoft. They sure don’t aim for quality. Maybe not enough people have complained and they’ve got a culture of fixing squeaky wheels instead of aiming for excellence. Probably they spell it ‘eksalense’.

Whatever. It’s pretty underwhelming.

Take home message is that if you can’t get it to work, it is not your fault! Solutions are either (1) forgo the change tracking and turn it off to do this, or (2) write your own Word macro to do it. Neither is very satisfactory.

I’ve long felt that MS has added very little valuable functionality to Word (or Excel) since Office 97 (and the equation editor has gone backwards), but I did not realise just how little progress had been made. Wow.

 

Rant ends.

Aligning equations in Word

Note to self

The Word equation editor is pretty badly broken by design. But it is possible to align on equals.

(1) Author equations one by one on consecutive lines with no gaps between.

(2) Select from exactly the first character of the first equation to the last of the last. Not one character extra either side! There must be no ‘non-equation’ objects in the block. If Word is doing ‘smart’ (ie dumb) automatic things with mouse selection, you may find it preferable to use the keyboard to select the block.

(3) Right-click and choose ‘Align at =’ or whatever the form of words might be.

 

Noted.