質問編集履歴

2

プログラムの修正

2017/08/25 03:22

投稿

isson
isson

スコア18

test CHANGED
File without changes
test CHANGED
@@ -4,43 +4,49 @@
4
4
 
5
5
  ```
6
6
 
7
- @IBAction func CreatePDF(aView: UIView) {
7
+ @IBAction func CreatePDF(vi: UIView) {
8
8
 
9
-
9
+ print("pdfを作ります!")
10
+
11
+
10
12
 
11
13
  let pdfData = NSMutableData()
12
14
 
13
- UIGraphicsBeginPDFContextToFile(pdfData, CGRectZero, nil);
15
+ let documentsPath = NSHomeDirectory() + "/Documents" + "/test.pdf"
14
16
 
17
+ let vi = UIView(frame: vi.bounds)
15
18
 
16
-
17
- UIGraphicsBeginPDFPage()
19
+ UIGraphicsBeginPDFContextToData(pdfData, vi.bounds, nil)
18
20
 
19
21
 
20
22
 
21
-
23
+ UIGraphicsGetCurrentContext()
22
24
 
23
- let pdfContext = UIGraphicsGetCurrentContext()
25
+ UIGraphicsBeginPDFPageWithInfo(vi.bounds, nil);
24
-
25
-
26
-
27
- aView.layer.render(in: pdfContext!)
28
26
 
29
27
  UIGraphicsEndPDFContext()
30
28
 
31
29
 
32
30
 
33
- let documentDirectories = NSHomeDirectory() + "/Documents"
31
+ pdfData.write(toFile: documentsPath, atomically: true)
34
32
 
35
- let documentsFileName = documentDirectories + "/test.pdf"
33
+
36
34
 
37
- debugPrint(documentsFileName)
35
+ print(documentsPath)
38
36
 
39
37
  }
40
38
 
39
+
40
+
41
41
  ```
42
42
 
43
- このまではエラーが出てしまいま
43
+ test.pdfファイルは作成され、真っ白なPDFが来るだけで
44
+
45
+
46
+
47
+ Viewの表示内容がpdfDataに代入されてないからだと思うのですが・・・・
48
+
49
+
44
50
 
45
51
  アプリを初めて作り出しました。サイトを色々見たりしてるのですが難しくて先に進めません。
46
52
 

1

2017/08/25 03:22

投稿

isson
isson

スコア18

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  色々なサイトを見たのですがどうしても分からない状態です
4
4
 
5
-
5
+ ```
6
6
 
7
7
  @IBAction func CreatePDF(aView: UIView) {
8
8
 
@@ -38,7 +38,7 @@
38
38
 
39
39
  }
40
40
 
41
-
41
+ ```
42
42
 
43
43
  このままではエラーが出てしまいます
44
44