Class: P3libIndesign

Inherits:
Object
  • Object
show all
Defined in:
lib/refx/engine/p3lib/p3lib_indesign.rb

Overview

library with indesign class methods

Class Method Summary collapse

Class Method Details

.closeAllDocsNoSave(inDesignApp) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/refx/engine/p3lib/p3lib_indesign.rb', line 160

def self.closeAllDocsNoSave(inDesignApp)
  begin
    inDesignApp.documents.get.each do |doc|
      doc.close(:saving => :no)
      P3libLogger::log("Closing all Indesign open documents:", '')
    end
  rescue
    P3libLogger::log("unable to close all open documents", "",'error')
  end

end

.export_to_png(inDesignApp, doc, dest) ⇒ Object

Latest export method using CoreGraphics cli app orig is the inbetween pdf file which us used to generate a PNG with alpha channel



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/refx/engine/p3lib/p3lib_indesign.rb', line 30

def self.export_to_png(inDesignApp, doc, dest)

  orig = dest+'.pdf'

  # TODO make preference
  native = false

  # inDesigns PNG export is only available in CS6 and doesn't work well for layers (in case of embedded PSD's)
  if(native && inDesignApp.to_s == "app(\"/Applications/Adobe InDesign CS6/Adobe InDesign CS6.app\")" && !dest.index('layer'))

    nativeExportToPNG(inDesignApp, doc, dest)

  else
    P3libLogger::log('Exporting to PNG using PDF as between file','','debug')

    inDesignApp.transparency_preference.blending_space.set(:to => :CMYK)
    inDesignApp.PDF_export_preferences.acrobat_compatibility.set(:to => :acrobat_8)
    begin

      ll = P3LibIndesignlocalization.new(inDesignApp)
      preset = ll.translate('[Smallest File Size]')
      inDesignApp.export(doc, :format => :PDF_type, :to => MacTypes::FileURL.path(orig).hfs_path, :timeout => 0, :showing_options => false, :using => preset)
    rescue Exception => e
      P3libLogger::log('PNG export failed: '+ e.message, 'error')
    end

    P3libImage::convertImgToFiletype(orig,dest,'png')
    FileUtils.rm(orig)

  end
end

.exportToPNG(inDesignApp, doc, outputPath, orig, dest, pixWidth, pixHeight) ⇒ Object

Latest export method using CoreGraphics cli app orig is the inbetween pdf file which us used to generate a PNG with alpha channel FIXME Depreciated



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/refx/engine/p3lib/p3lib_indesign.rb', line 65

def self.exportToPNG(inDesignApp, doc, outputPath, orig, dest, pixWidth, pixHeight)

  # TODO make preference
  native = false

  # inDesigns PNG export is only available in CS6 and doesn't work well for layers (in case of embedded PSD's)
  if(native && inDesignApp.to_s == "app(\"/Applications/Adobe InDesign CS6/Adobe InDesign CS6.app\")" && !dest.index('layer'))

    nativeExportToPNG(inDesignApp, doc, dest)

  else
    P3libLogger::log('Exporting to PNG using PDF as between file','','debug')

    inDesignApp.transparency_preference.blending_space.set(:to => :CMYK)
    inDesignApp.PDF_export_preferences.acrobat_compatibility.set(:to => :acrobat_8)
    begin

      ll = P3LibIndesignlocalization.new(inDesignApp)
      preset = ll.translate('[Smallest File Size]')
      inDesignApp.export(doc, :format => :PDF_type, :to => MacTypes::FileURL.path(orig).hfs_path, :timeout => 0, :showing_options => false, :using => preset)
    rescue Exception => e
      P3libLogger::log('PNG export failed: '+ e.message, 'error')
    end

    P3libImage::convertImgToFiletype(orig,dest,'png')
    FileUtils.rm(orig)

  end
end

.nativeExportToPNG(inDesignApp, doc, dest) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/refx/engine/p3lib/p3lib_indesign.rb', line 95

def self.nativeExportToPNG(inDesignApp, doc, dest)

  if(!dest.index('image'))

    begin
      inDesignApp.export(doc, :format => :PNG_format, :to => MacTypes::FileURL.path(dest).hfs_path, :timeout => 0, :showing_options => false)
    rescue Exception => e
      P3libLogger::log('PNG export failed: '+ e.message, 'error')
    end
  else
    # If is type image the image could be a PSD which can't be exported using inDesign's PNG export
    # Use HTML export instead (apparently Indesign can export PSD as PNG, it can't do so using the PNG export method)

    # Turn preview after export off
    doc.HTML_export_preference.view_document_after_export.set(:to => false)

    # Some other export preferences - not tested yet
    #doc.HTML_export_preference.image_conversion.set(:to => :PNG)
    #doc.HTML_export_preference.image_export_resolution(:to => 150)
    #doc.HTML_export_preference.CSS_export_option.set(:to => :none)
    #doc.HTML_export_preference.ignore_object_conversion_settings.set(:to => false)
    #doc.HTML_export_preference.level.set(:to => 6) #PNG level

    # Export HTML
    begin
      inDesignApp.export(doc, :format => :HTML, :to => MacTypes::FileURL.path(dest+'.html').hfs_path, :timeout => 0, :showing_options => false)
    rescue Exception => e
      P3libLogger::log('HTML export failed: '+ e.message)
    end

    # Copy PNG file from the HTML's web-resources folder to destination
    Dir.foreach(dest+'-web-resources/image'){|f|
      if(f != '.' && f != '..')
        FileUtils.cp(dest+'-web-resources/image/'+f, dest)
      end
    }

    # Clean up - prevents folders postfixed with numbers at reindex
    FileUtils.rm_rf(dest+'-web-resources/')
    FileUtils.rm(dest+'.html')

  end
end

.open_doc_with_locked_fallback(indd_app, doc) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/refx/engine/p3lib/p3lib_indesign.rb', line 9

def self.open_doc_with_locked_fallback(indd_app, doc)
  begin
    return indd_app.open(MacTypes::FileURL.path(doc).hfs_path)
  rescue StandardError => e
    if File.exists?(doc)

      P3libLogger::log('File may be locked, try to open a copy',e.to_s,'info')
      new_doc = '/tmp/'+P3libUtil::helper_newtempname(6)+'.indd'
      FileUtils.copy(doc, new_doc )
      return indd_app.open(MacTypes::FileURL.path(new_doc).hfs_path)
    end
  end
end

.p3imgutils_pathObject



23
24
25
26
# File 'lib/refx/engine/p3lib/p3lib_indesign.rb', line 23

def self.p3imgutils_path
  p3imgutils_path = File.expand_path('../../p3imgutils', __FILE__)
  return p3imgutils_path
end

.placeImageOnItem(item, absolute_img_src) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/refx/engine/p3lib/p3lib_indesign.rb', line 140

def self.placeImageOnItem(item, absolute_img_src)
  if(File.exists?(absolute_img_src) && File.readable?(absolute_img_src) && File.file?(absolute_img_src))


    begin
      P3libLogger::log("placing item normal", MacTypes::FileURL.path(absolute_img_src).to_s)
      item.place(MacTypes::FileURL.path(absolute_img_src))
    rescue
      begin
        P3libLogger::log("placing item hfs", MacTypes::FileURL.path(absolute_img_src).hfs_path.to_s)
        item.place(MacTypes::FileURL.path(absolute_img_src).hfs_path)
      rescue
        P3libLogger::log("unable to place item", "")
      end
    end
  else
    P3libLogger::log("image file not usable", absolute_img_src)
  end
end