Skip to content

Instantly share code, notes, and snippets.

@eyalroz
Last active December 27, 2016 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyalroz/9b3bb9ad3507cf7204ecc597c76572a3 to your computer and use it in GitHub Desktop.
Save eyalroz/9b3bb9ad3507cf7204ecc597c76572a3 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# sgn2pdf
# by Eyal Rozenberg <eyalroz@technion.ac.il>
# version: 2016-12-27
#
# Extracts a PDF file from an Israeli courts' .sgn PDF document envelope
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# The text of the GNU General Public License is available at:
# <http://www.gnu.org/licenses/>.
#
#
# TODO: Support taking the input and output filenames from the command-line arguments
exec 3<&0 # tie (new) file descriptor 3 to what is currently the standard input
exec 4>&1 # tie (new) file descriptor 4 to what is currently the standard output
if [[ $# > 0 ]]; then
exec 3<$1
shift
fi
if [[ $# > 0 ]]; then
exec 4>$1
shift
fi
exec <&3 >&4
sed -r 's/^.*<DocumentContent[^>]*>//; s/<\/Document.*$//;' | base64 -d -i >&4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment