圧縮フォルダを解凍する。画像が複数含まれるので分割する。フォルダごとにpdfに変換
とりあえず完成
@@ -17,7 +17,7 @@ | ||
17 | 17 | End Sub |
18 | 18 | |
19 | 19 | Private Sub IDisposable_Dispose() Implements IDisposable.Dispose |
20 | - ' IfExistDirDelete(Path) | |
20 | + 'todo:後片付け IfExistDirDelete(Path) | |
21 | 21 | End Sub |
22 | 22 | |
23 | 23 | ''' <summary> |
@@ -29,9 +29,10 @@ | ||
29 | 29 | ' |
30 | 30 | 'btnExecute |
31 | 31 | ' |
32 | - Me.btnExecute.Location = New System.Drawing.Point(41, 81) | |
32 | + Me.btnExecute.Location = New System.Drawing.Point(55, 101) | |
33 | + Me.btnExecute.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) | |
33 | 34 | Me.btnExecute.Name = "btnExecute" |
34 | - Me.btnExecute.Size = New System.Drawing.Size(75, 23) | |
35 | + Me.btnExecute.Size = New System.Drawing.Size(100, 29) | |
35 | 36 | Me.btnExecute.TabIndex = 0 |
36 | 37 | Me.btnExecute.Text = "実行" |
37 | 38 | Me.btnExecute.UseVisualStyleBackColor = True |
@@ -38,9 +39,10 @@ | ||
38 | 39 | ' |
39 | 40 | 'TextBox1 |
40 | 41 | ' |
41 | - Me.TextBox1.Location = New System.Drawing.Point(41, 40) | |
42 | + Me.TextBox1.Location = New System.Drawing.Point(55, 50) | |
43 | + Me.TextBox1.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) | |
42 | 44 | Me.TextBox1.Name = "TextBox1" |
43 | - Me.TextBox1.Size = New System.Drawing.Size(483, 19) | |
45 | + Me.TextBox1.Size = New System.Drawing.Size(643, 22) | |
44 | 46 | Me.TextBox1.TabIndex = 1 |
45 | 47 | Me.TextBox1.Text = "D:\ZIP\(一般コミック) [横山光輝] 三国志 全60巻" |
46 | 48 | ' |
@@ -47,20 +49,23 @@ | ||
47 | 49 | 'lstLog |
48 | 50 | ' |
49 | 51 | Me.lstLog.FormattingEnabled = True |
50 | - Me.lstLog.ItemHeight = 12 | |
51 | - Me.lstLog.Location = New System.Drawing.Point(41, 128) | |
52 | + Me.lstLog.ItemHeight = 15 | |
53 | + Me.lstLog.Location = New System.Drawing.Point(25, 156) | |
54 | + Me.lstLog.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) | |
52 | 55 | Me.lstLog.Name = "lstLog" |
53 | - Me.lstLog.Size = New System.Drawing.Size(120, 88) | |
56 | + Me.lstLog.ScrollAlwaysVisible = True | |
57 | + Me.lstLog.Size = New System.Drawing.Size(696, 349) | |
54 | 58 | Me.lstLog.TabIndex = 2 |
55 | 59 | ' |
56 | 60 | 'Form1 |
57 | 61 | ' |
58 | - Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!) | |
62 | + Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 15.0!) | |
59 | 63 | Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font |
60 | - Me.ClientSize = New System.Drawing.Size(600, 261) | |
64 | + Me.ClientSize = New System.Drawing.Size(800, 567) | |
61 | 65 | Me.Controls.Add(Me.lstLog) |
62 | 66 | Me.Controls.Add(Me.TextBox1) |
63 | 67 | Me.Controls.Add(Me.btnExecute) |
68 | + Me.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4) | |
64 | 69 | Me.Name = "Form1" |
65 | 70 | Me.Text = "Form1" |
66 | 71 | Me.ResumeLayout(False) |
@@ -24,10 +24,10 @@ | ||
24 | 24 | Dim allPath = TextBox1.Text '全冊フォルダ |
25 | 25 | '全冊フォルダのzipファイルを列挙するし以下を繰り返す。 |
26 | 26 | Dim files As String() = System.IO.Directory.GetFiles(allPath, "*.zip", System.IO.SearchOption.AllDirectories) |
27 | - If 0 < files.Count Then | |
28 | - Dim zipFilePath = files(0) 'todo:test用とりあえず一個だけ試す。 | |
27 | + For Each zipFilePath In files | |
28 | + log.Info(zipFilePath) | |
29 | 29 | zipToPdf(zipFilePath) |
30 | - End If | |
30 | + Next | |
31 | 31 | |
32 | 32 | log.Info("処理終了") |
33 | 33 | End Sub |
@@ -52,7 +52,8 @@ | ||
52 | 52 | |
53 | 53 | '解凍処理 |
54 | 54 | System.IO.Compression.ZipFile.ExtractToDirectory(zipFilePath, srcFiles.Path) |
55 | - | |
55 | + Dim width As Integer | |
56 | + Dim height As Integer | |
56 | 57 | filename_count = 1 |
57 | 58 | 'tempフォルダのjpegファイルを列挙し以下を繰り返す |
58 | 59 | Dim files As String() = System.IO.Directory.GetFiles(srcFiles.Path, "*.jpg", System.IO.SearchOption.AllDirectories) |
@@ -65,8 +66,8 @@ | ||
65 | 66 | '左側画像を保存する。 |
66 | 67 | Else |
67 | 68 | Dim image As New Bitmap(filepath) |
68 | - Dim width As Integer = image.Width / 2 | |
69 | - Dim height As Integer = image.Height | |
69 | + width = image.Width / 2 | |
70 | + height = image.Height | |
70 | 71 | Dim desRect As New Drawing.Rectangle(0, 0, width, height) |
71 | 72 | Dim destImage As New Bitmap(width, height) |
72 | 73 | Dim g = Graphics.FromImage(destImage) |
@@ -86,7 +87,8 @@ | ||
86 | 87 | '2つに分割し右側をfilename_count.jpeg,左側をfilename_count+1.jpegとして保存する |
87 | 88 | 'tempフォルダをpdf化する |
88 | 89 | 'A4サイズを横向きで |
89 | - Dim pdfDocument = New Document(PageSize.A4.Rotate(), 0, 0, 0, 0) | |
90 | + Dim psize As New iTextSharp.text.Rectangle(Width, Height) | |
91 | + Dim pdfDocument = New Document(psize, 0, 0, 0, 0) | |
90 | 92 | '出力先のファイル名 |
91 | 93 | Dim makePdfFilePath = zipFilePath.Replace(".zip", "pdf") |
92 | 94 | Dim fileStream = New FileStream(makePdfFilePath, FileMode.Create) |
@@ -93,7 +95,11 @@ | ||
93 | 95 | Dim writer = PdfWriter.GetInstance(pdfDocument, fileStream) |
94 | 96 | 'PDFドキュメントを開く |
95 | 97 | pdfDocument.Open() |
96 | - pdfDocument.Add(New Paragraph("test")) | |
98 | + files = System.IO.Directory.GetFiles(tempFiles.Path, "*.jpg", System.IO.SearchOption.AllDirectories) | |
99 | + For Each filepath As String In files | |
100 | + Dim img = iTextSharp.text.Image.GetInstance(New Uri(filepath)) | |
101 | + pdfDocument.Add(img) | |
102 | + Next | |
97 | 103 | 'PDFドキュメントを閉じる |
98 | 104 | pdfDocument.Close() |
99 | 105 |