aboutsummaryrefslogtreecommitdiffstats
path: root/lib/alaveteli_text_masker.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/alaveteli_text_masker.rb')
-rw-r--r--lib/alaveteli_text_masker.rb35
1 files changed, 24 insertions, 11 deletions
diff --git a/lib/alaveteli_text_masker.rb b/lib/alaveteli_text_masker.rb
index 68ff0d318..5d836f66c 100644
--- a/lib/alaveteli_text_masker.rb
+++ b/lib/alaveteli_text_masker.rb
@@ -28,9 +28,7 @@ module AlaveteliTextMasker
end
def apply_pdf_masks!(text, options = {})
- uncompressed_text = nil
- uncompressed_text = AlaveteliExternalCommand.run("pdftk", "-", "output", "-", "uncompress",
- :stdin_string => text)
+ uncompressed_text = uncompress_pdf(text)
# if we managed to uncompress the PDF...
if !uncompressed_text.blank?
# then censor stuff (making a copy so can compare again in a bit)
@@ -39,19 +37,13 @@ module AlaveteliTextMasker
# if the censor rule removed something...
if censored_uncompressed_text != uncompressed_text
# then use the altered file (recompressed)
- recompressed_text = nil
- if AlaveteliConfiguration::use_ghostscript_compression == true
- command = ["gs", "-sDEVICE=pdfwrite", "-dCompatibilityLevel=1.4", "-dPDFSETTINGS=/screen", "-dNOPAUSE", "-dQUIET", "-dBATCH", "-sOutputFile=-", "-"]
- else
- command = ["pdftk", "-", "output", "-", "compress"]
- end
- recompressed_text = AlaveteliExternalCommand.run(*(command + [{:stdin_string=>censored_uncompressed_text}]))
+ recompressed_text = compress_pdf(censored_uncompressed_text)
if recompressed_text.blank?
# buggy versions of pdftk sometimes fail on
# compression, I don't see it's a disaster in
# these cases to save an uncompressed version?
recompressed_text = censored_uncompressed_text
- logger.warn "Unable to compress PDF; problem with your pdftk version?"
+ Rails.logger.warn "Unable to compress PDF; problem with your pdftk version?"
end
if !recompressed_text.blank?
text.replace recompressed_text
@@ -62,6 +54,27 @@ module AlaveteliTextMasker
private
+ def uncompress_pdf(text)
+ AlaveteliExternalCommand.run("pdftk", "-", "output", "-", "uncompress", :stdin_string => text)
+ end
+
+ def compress_pdf(text)
+ if AlaveteliConfiguration::use_ghostscript_compression
+ command = ["gs",
+ "-sDEVICE=pdfwrite",
+ "-dCompatibilityLevel=1.4",
+ "-dPDFSETTINGS=/screen",
+ "-dNOPAUSE",
+ "-dQUIET",
+ "-dBATCH",
+ "-sOutputFile=-",
+ "-"]
+ else
+ command = ["pdftk", "-", "output", "-", "compress"]
+ end
+ AlaveteliExternalCommand.run(*(command + [ :stdin_string => text ]))
+ end
+
# Replace text in place
def apply_binary_masks!(text, options = {})
# Keep original size, so can check haven't resized it