Swiftpack.co - fummicc1/csv2img as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by fummicc1.
fummicc1/csv2img v1.6.1
csv to image / pdf converter using Swift
⭐️ 6
🕓 10 weeks ago
iOS macOS
.package(url: "https://github.com/fummicc1/csv2img.git", from: "v1.6.1")

Csv2mg_bg

Csv2ImageApp

Convert Csv into png image.

iOS App

Demo

MacOS App

Demo

Csv2Img (Library)

Convert Csv into png image.

Usage

You cloud convert csv into image / pdf in 3 ways.

  1. Via raw String.
 let rawCsv = """
 a,b,c
 1,2,3
 4,5,6
 7,8,9
 10,11,12
 """
let csv = Csv.loadFromString(rawCsv)
let image = try await csv.generate(exportType: .png)
 Output:
 | a  | b  | c  |
 | 1  | 2  | 3  |
 | 4  | 5  | 6  |
 | 7  | 8  | 9  |
 | 10 | 11 | 12 |
  1. Via Local file.
 let rawCsv = """
 a,b,c
 1,2,3
 4,5,6
 7,8,9
 10,11,12
 """
let url = URL(
    fileURLWithPath: "/Users/fumiyatanaka/Downloads/sample.csv"
)
rawCsv.data(using: .utf8)?.write(to: url)
// ----- ↑Just prepared for explanation. -----
let csv = Csv.loadFromDisk(url)
let data = try await csv.generate(fontSize: 12, exportType: .png)
 Output:
 | a  | b  | c  |
 | 1  | 2  | 3  |
 | 4  | 5  | 6  |
 | 7  | 8  | 9  |
 | 10 | 11 | 12 |
  1. Via network resource
let rawCsv = """
 a,b,c
 1,2,3
 4,5,6
 7,8,9
 10,11,12
 """
let url = URL(
    string: "https://raw.githubusercontent.com/fummicc1/csv2img/main/Fixtures/sample_1.csv"
)
// ----- ↑Just prepared for explanation. -----
let csv = Csv.loadFromNetwork(url)
let data = try await csv.generate(fontSize: 12, exportType: .png)
 Output:
 | a  | b  | c  |
 | 1  | 2  | 3  |
 | 4  | 5  | 6  |
 | 7  | 8  | 9  |
 | 10 | 11 | 12 |

Output Image

sample

CsvBuilder (Helper Library for Csv2Img)

A helper library to generate Csv in Csv2Img library.

How to use

  1. Define custom type which conform to CsvComposition.
import Foundation
import Csv2Img


public struct ExampleComposition: CsvComposition {
    @CsvRows(column: "age")
    public var ages: [String]

    @CsvRows(column: "name")
    public var names: [String]

    public init() { }
}
  1. Build Csv
let composition: ExampleComposition = .init()
composition.ages.append(contentsOf: ["98", "99", "100"])
composition.names.append(contentsOf: ["Yamada", "Tanaka", "Sato"])
let csv = try! composition.build()
Result
スクリーンショット 2022-08-26 12 54 22

Csv2ImgCmd (CLI)

A command line tool which generates png-image from csv. (Using Csv2Img library)

Usage

Coomand line interface using Csv2Img library.

If you have a csv file on your computer, you cloud use this flag with --local, -l.

./Csv2ImgCmd --local ~/Downloads/sample.csv ./output.png

If you would like to convert csv file on the internet, you cloud use this flag with --network, -n.

./Csv2ImgCmd --network \
https://raw.githubusercontent.com/fummicc1/csv2img/main/Sources/Csv2ImgCmd/Resources/sample_1.csv \
output.png

Contributing

Pull requests, bug reports and feature requests are welcome 🚀

License

MIT LICENSE

GitHub

link
Stars: 6
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics