def optimize_file target
::Dir::Tmpname.create ['asciidoctor-pdf-', '.pdf'] do |tmpfile|
filename_o = ::Pathname.new target
filename_tmp = ::Pathname.new tmpfile
if (pdfmark = filename_o.sub_ext '.pdfmark').file?
inputs = [target, pdfmark.to_s].join ::File::PATH_SEPARATOR
else
inputs = target
end
d = { CannotEmbedFontPolicy: '/Warning', CompatibilityLevel: @compatibility_level, NEWPDF: false, Printed: false }
case @compliance
when 'PDF/A', 'PDF/A-1', 'PDF/A-2', 'PDF/A-3'
d[:PDFA] = ((@compliance.split '-', 2)[1] || 1).to_i
d[:ShowAnnots] = false
when 'PDF/X', 'PDF/X-1', 'PDF/X-3'
d[:PDFX] = true
d[:ShowAnnots] = false
end
(::RGhost::Convert.new inputs).to :pdf, filename: filename_tmp.to_s, quality: @quality, d: d
filename_o.binwrite filename_tmp.binread
end
nil
end