[Dropped] Fix, bypass, or implement document checksums

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Locked
puppyledger
Posts: 9
Joined: Tue Apr 30, 2024 9:48 pm

[Dropped] Fix, bypass, or implement document checksums

Post by puppyledger »

LibreOffice 25.2.2.2
Windows 10

I bought a new label printer, and it works from libreoffice draw. (Yay!) I need to connect some templates (packing and shipping labels) up to a third party data source. It seems like libreoffice should be able to print from the CLI. It also seems all I really need to do is decompress the .odg file, do a few global match and replaces on the content.xml internal document, rezip it and throw it to the printer. This looks like it should work well enough from perl (or any language really) except...

There appears to be a checksum that makes third party document modifications fail when libreoffice does a subsequent read.

The goal here is to be able to rip a thousand packing slips without user input, and preferably with no screen usage. So I need to do one of:

1. Disable the checksum feature (is there a switch?)
2. Rechecksum the copied (save as) document (which algo, what internals does it check, and where is it stored?)
3. Look at an UNO example of a (open, modify, save-as) cycle that doesn't break the checksum. Preferably in python or C++.

Thanks in advance!
Last edited by MrProgrammer on Thu May 15, 2025 4:40 pm, edited 1 time in total.
Reason: Dropped: No attachments from puppyledger
LibreOffice 24.2.1.2 420(Build:2)
Void Linux 6.6.5 MUSL
User avatar
MrProgrammer
Moderator
Posts: 5322
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Fix, bypass, or implement document checksums

Post by MrProgrammer »

puppyledger wrote: Thu Apr 24, 2025 10:42 pm I need to connect some templates (packing and shipping labels) up to a third party data source
In OpenOffice/LibreOffice label creation from a data source is done with Mail Merge. This process replaces fields in the label template with values from records in the data source. No programming is needed. This will be much simpler than attempting to modify content.xml with an external program.
Using Mail Merge: Form letters, mailing labels, and envelopes

If this solved your problem please go to your first post use the Edit ✏️ button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
puppyledger
Posts: 9
Joined: Tue Apr 30, 2024 9:48 pm

Re: Fix, bypass, or implement document checksums

Post by puppyledger »

"This will be much simpler than attempting to modify content,xml with an external program."

I have to disagree. Updating an XML file is an order of magnitude simpler than building a database, or even porting one. I have a data source. It is dynamic. I do not need to or want to duplicate it. All I need is templating, and a postscript driver. This should be doable without even getting into UNO considering that XML and likely the checksum system is standards based. But if I have to do an open->edit->save_as->print, then that is what I'll do.

Still looking into it, if anybody can point me at any example that goes through the whole cycle I'd love to see it. Whatever language really. Just so long as it doesn't require the GUI

Thanks!
LibreOffice 24.2.1.2 420(Build:2)
Void Linux 6.6.5 MUSL
Bidouille
Volunteer
Posts: 648
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: Fix, bypass, or implement document checksums

Post by Bidouille »

puppyledger wrote: Fri Apr 25, 2025 6:49 am Just so long as it doesn't require the GUI
Without GUI, you should have posted in the External programs section. With a macro, it necessary to use GUI.
You don't say what language you know. There's a lot of classes and libraries that can handle ODF files.
User avatar
MrProgrammer
Moderator
Posts: 5322
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Fix, bypass, or implement document checksums

Post by MrProgrammer »

puppyledger wrote: Fri Apr 25, 2025 6:49 am Whatever language really. Just so long as it doesn't require the GUI
Perl has an ODF interface module. CPAN: An OpenDocument management interface

This module is an office document management interface. It allows the users to create or transform office documents, or to extract data from them. It can handle files which comply with the ODF standard and whose type is text (odt), spreadsheet (ods), presentation (odp) or drawing (odg). It interacts directly with the files and doesn't depend on a particular office software.

puppyledger wrote: Fri Apr 25, 2025 6:49 am I have a data source. It is dynamic. I do not need to or want to duplicate it.
Mail Merge uses Writer and Base. Base is not a database. It is the component which allows OpenOffice to connect with with many types of existing databases or text files.

puppyledger wrote: Fri Apr 25, 2025 6:49 am All I need is templating, and a [print] driver.
You have just described Mail Merge.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
puppyledger
Posts: 9
Joined: Tue Apr 30, 2024 9:48 pm

[Solved] Fix, bypass, or implement document checksums

Post by puppyledger »

To more correctly explain: I am running a bit of a frankensystem. Msys2 on windows 10, using the Python.org python rather than the one that installs from either libreoffice or msys2.

So I found this python2 tool, and was able to tweak it to python 3.

https://crcok.wordpress.com/2014/10/25/ ... in-python/

In sdraw my document format is just the 2.35x1.25 label (which actually works with the 2.25x1.25 labels from amazon) . Running the above tool does an in place string transliteration, so I am just going to modify it to transliterate whatever I pass from the CLI as an option. (if I pass -foo <arg> it inserts arg where string "foo" was in the label.) Then I can batch it like so:

./mylabeltool -inputfile label.odg -outputfile <recieptnum>.odg -foo bar -baz bam -etc etc.
/c/Program\ Files/LibreOffice/program/soffice.exe --headless --pt {ORGSTA T001} -p out.odg

With a little care for avoiding shell escapes, this should scale.

Thanks for ya'lls help. I get that there is a cononical way of doing this, and this ain't it. But it'll do.
LibreOffice 24.2.1.2 420(Build:2)
Void Linux 6.6.5 MUSL
Bidouille
Volunteer
Posts: 648
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: Fix, bypass, or implement document checksums

Post by Bidouille »

Attach the output file generated by

Code: Select all

./mylabeltool -inputfile label.odg -outputfile <recieptnum>.odg -foo bar -baz bam -etc etc. 
Jan_J
Posts: 189
Joined: Wed Apr 29, 2009 1:42 pm
Location: Poland

Re: Fix, bypass, or implement document checksums

Post by Jan_J »

Zipping contents.xml back to ODF bundle is a valid way for document modification. Metadata remain unchanged and may be outdated. No specific checksum is mandatory part internally in ODF, except these applied directly by ZIP format. But they should be updated during packing phase by the ZIP algorithm.

Maybe third party software use some checksums in nonstandard metadata to enable controlling consistence of documents.

The ODF standard states about order of elements inside ZIP container. I do not remember details, but if some software was complaining about it, repackaging in the required order was a remedy. This has nothing to do with checkums, however.

Maybe someone would have some other suggestions, if you deliver small sample file and its modified copy.
JJ ∙ https://forum.openoffice.org/pl/
LO (25.2|24.8) ∙ Python (3.12|3.10) ∙ Unicode 16 ∙ LᴬTEX 2ε ∙ XML ∙ Unix tools ∙ Linux (Rocky|CentOS)
Locked