s2c-code-share

Automation Script Example: Converting Raster Images

Nov 20th, 2020 (edited)
414
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. in_dir  = ""
  2.  
  3. # Extract rasters from pdfs
  4. pdfs = s2c.list(in_dir, "pdf")
  5. for p in pdfs:
  6.     pp = p.open()
  7.     pp.save(s2c.FileType.RASTER, s2c.join(in_dir, p.get_name()))
  8.  
  9.  
  10. # Prepare vectorization preset
  11. preset = s2c.Preset()
  12. preset.load(s2c.Preset.Predefined.Electrical)
  13. preset.method = s2c.Preset.Method.Technical
  14. preset.option = s2c.Preset.Option.VectorizeOCR
  15. preset.language = s2c.Preset.Languages.German
  16.  
  17.  
  18. # Rotate rasters, apply image filters and vectorize them
  19. rasters = s2c.list(in_dir, "pcx")
  20. for r in rasters:
  21.     rr = r.open()
  22.     rr.rotate90()
  23.     rr.remove_speckles_and_holes(2, 0)
  24.     rr.smooth()
  25.     rr.save()
  26.  
  27.     # Vectorize
  28.     v = rr.vectorize(preset)
  29.     # Save to the same directory (.dxf will be added at the end)
  30.     v.save(rr.path)
  31.  
RAW Paste Data