Showing posts with label conversion. Show all posts
Showing posts with label conversion. Show all posts

Thursday, 7 August 2025

Converting images to pdf in Linux

Occasionally, I have to scan official papers (dead-tree-copy) and I'd like to keep the result small, and in one pdf.

So, a one liner command would be nice.

magick mrbear*.png -quality 10% -set filename:base "%[basename]" "%[filename:base].jpg"

The commandline above automatically creates an appropriate .jpg file for each mrbear*.png file. So mrbear_0001.png will cause a mrbear_0001.jpg.

Just what I wanted. Went from 8 megabytes picture to a 200 kb picture.

And then converting the new images over to a pdf file is ridiculously simple:

magick mrbear*.jpg mrbear.pdf

Magick!

References

DigitalOcean - Reduce File Size of Images in Linux - CLI and GUI methods
https://www.digitalocean.com/community/tutorials/reduce-file-size-of-images-linux
GitHub - Convert images but keep the original file name #6494
https://github.com/ImageMagick/ImageMagick/discussions/6494
ImageMagick
https://imagemagick.org/

Thursday, 2 January 2020

XMLGregorianCalendar off by a few days on dates before 1582

Oh, darn. Just got bit by this thing.

The customer had stored documents for which it did not know the date with date 01-01-0007.

When importing it via XML, it turned out wrong.

The reference [1] below explains why.

References

[1] StackOverflow - Date change when converting from XMLGregorianCalendar to Calendar
https://stackoverflow.com/questions/16321193/date-change-when-converting-from-xmlgregoriancalendar-to-calendar
Wikipedia - Proleptic Gregorian Calendar
https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar

Thursday, 13 July 2017

Enumerations in EclipseLink

I have a field in the database that does not match with an Enumeration.

So I needed to do a little conversion in EclipseLink, and I didn't know how.

Below is the answer on that one.

References

EclipseLink - @ObjectTypeConverter
https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Basic_Mappings/Default_Conversions_and_Converters/ObjectTypeConverter
EclipseLink - EclipseLink/Examples/JPA/EnumToCode
https://wiki.eclipse.org/EclipseLink/Examples/JPA/EnumToCode

Friday, 12 September 2014

Moving From Ant to Maven

My project "karchangame" is Ant-based, basically because when you create a new project in Netbeans, the Ant configuration is the default.

This has worked well for a long time, until I decided recently to upgrade some of the libraries that I use. Now, in Ant, you just download the libraries you need and put the jar-files in your classpath.

That works fine if your libraries are not complicated. But I noticed that some of my libraries are now dependant on yet other libraries.

In short, I just spent an hour in getting the libraries I need, then getting the required libraries of those libraries, ad infinitum.

Maven takes care of this whole slog, by putting the responsibility for defining the required libraries for a framework/library squarely on the shoulders of that framework/library.

What I was stuck with was finding the best way of changing my Ant-based project into a Maven-based project.

Moving from Ant to Maven


The easiest way that I could come up with is to create a brand new Maven-based project. The original was a Web Application, so the new Maven project should also be a Web Application. As far as I could tell every possibility for a new ant-based project is also available as a new maven-based project.

And then start moving files over to the appropriate place in the new Maven structure.

I really like the fact that Git actually detects these moves instead of like in the old days, when a move was an explicit delete and create of two non-related files, making you lose your entire history of that file.

The difference in the directory structure is as follows:
You do notice that Maven actually has a more layered structure, whereas Netbeans Ant basically dumps everything in the root.

So, the move basically entailed the following:
From antTo Maven
build.xmlpom.xml
-nb-configuration.xml
nbproject-
lib- (actually stored in your m2 repo)
src/confsrc/main/resources
src/javasrc/main/java
websrc/main/webapp
testsrc/test/java
buildtarget
dist/karchangame.wartarget/karchangame-1.0-SNAPSHOT.war

Pom.xml

I only needed to make a few changes to my pom.xml file, in order to get all the dependencies sorted out.

JMockit

Needed to add JMockit, or my testcode didn't compile.
<dependency>

    <groupId>org.jmockit</groupId>
    <artifactId>jmockit</artifactId>
    <version>1.10</version>
    <scope>test</scope>
</dependency>

AntiSamy

AntiSamy to prevent evil hackers from gaining access.
<dependency>
    <groupId>org.owasp.antisamy</groupId>
    <artifactId>antisamy</artifactId>
    <version>1.5.3</version>
</dependency>

URL Validation

<dependency>

    <groupId>commons-validator</groupId>
    <artifactId>commons-validator</artifactId>
    <version>1.4.0</version>
</dependency>
It's amazing to see Maven automatically download all the required libraries.

The last part was adding plantuml back into the mix. But I'll talk about that in the next Blog.

References

Apache Maven
http://maven.apache.org/
Netbeans - MavenBestPractices
http://wiki.netbeans.org/MavenBestPractices