|
8 | 8 |
|
9 | 9 | import Foundation
|
10 | 10 | import TPPDF
|
| 11 | +import UIKit |
11 | 12 |
|
12 | 13 | class ExperimentFactory: ExampleFactory {
|
13 | 14 | func generateDocument() -> [PDFDocument] {
|
14 |
| - let document = PDFDocument(format: .a4) |
15 |
| - |
16 |
| - let items = (0..<40).map { $0.description } |
17 |
| - |
18 |
| - // Simple bullet point list |
19 |
| - let featureList = PDFList(indentations: [ |
20 |
| - (pre: 10.0, past: 20.0), |
21 |
| - (pre: 20.0, past: 20.0), |
22 |
| - (pre: 40.0, past: 20.0), |
23 |
| - ]) |
24 |
| - |
25 |
| - // By adding the item first to a list item with the dot symbol, all of them will inherit it |
26 |
| - featureList |
27 |
| - .addItem(PDFListItem(symbol: .dot) |
28 |
| - .addItems(items.map { item in |
29 |
| - PDFListItem(content: item) |
30 |
| - })) |
31 |
| - document.add(list: featureList) |
32 |
| - |
33 |
| - document.add(space: 20) |
34 |
| - |
35 |
| - // Numbered list with unusual indentation |
36 |
| - let weirdIndentationList = PDFList(indentations: [ |
37 |
| - (pre: 10.0, past: 20.0), |
38 |
| - (pre: 40.0, past: 30.0), |
39 |
| - (pre: 20.0, past: 50.0), |
40 |
| - ]) |
41 |
| - |
42 |
| - weirdIndentationList |
43 |
| - .addItems(items.enumerated().map { arg in |
44 |
| - PDFListItem(symbol: .numbered(value: "\(arg.offset + 1)"), content: arg.element) |
45 |
| - }) |
46 |
| - document.add(list: weirdIndentationList) |
47 |
| - |
| 15 | + let document = PDFDocument(format: .b5) |
| 16 | + document.add(.contentCenter, text: "Some Test Name") |
| 17 | + let images = [ |
| 18 | + "file:///Users/Philip/Downloads/test_images/0000.jpg", |
| 19 | + "file:///Users/Philip/Downloads/test_images/0001.jpg", |
| 20 | + "file:///Users/Philip/Downloads/test_images/0002.jpg", |
| 21 | + "file:///Users/Philip/Downloads/test_images/0003.jpg", |
| 22 | + "file:///Users/Philip/Downloads/test_images/0004.jpg", |
| 23 | + "file:///Users/Philip/Downloads/test_images/0005.jpg", |
| 24 | + "file:///Users/Philip/Downloads/test_images/0006.jpg", |
| 25 | + "file:///Users/Philip/Downloads/test_images/0007.jpg", |
| 26 | + "file:///Users/Philip/Downloads/test_images/0008.jpg", |
| 27 | + "file:///Users/Philip/Downloads/test_images/0009.jpg", |
| 28 | + ] |
| 29 | + images[0..<images.count].compactMap({ imageFileUrl -> PDFImage? in |
| 30 | + guard let imageURL = URL(string: imageFileUrl), |
| 31 | + let image = UIImage(contentsOfFile: imageURL.path(percentEncoded: false)), |
| 32 | + image.size != .zero |
| 33 | + else { |
| 34 | + return nil |
| 35 | + } |
| 36 | + |
| 37 | + let pdfImage = PDFImage(image: image) |
| 38 | + return pdfImage |
| 39 | + }).forEach({ pdfImage in |
| 40 | + document.add(image: pdfImage) |
| 41 | + }) |
48 | 42 | return [document]
|
49 | 43 | }
|
50 | 44 | }
|
0 commit comments