Commit 1cd55e86 by 施晓雨

增加输出图片的测试

parent e684dd72
......@@ -32,8 +32,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Kivii.Common.V4.0, Version=5.5.2020.9280, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Kivii.Common.5.5.2020.9280\lib\net40\Kivii.Common.V4.0.dll</HintPath>
<Reference Include="Kivii.Common.V4.0, Version=5.6.2021.5080, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Kivii.Common.5.6.2021.5080\lib\net40\Kivii.Common.V4.0.dll</HintPath>
</Reference>
<Reference Include="Kivii.Pdf.V4.0, Version=5.5.2020.11000, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Kivii.Pdf.5.5.2020.11000\lib\net40\Kivii.Pdf.V4.0.dll</HintPath>
......
......@@ -89,10 +89,16 @@
this.label26 = new System.Windows.Forms.Label();
this.label24 = new System.Windows.Forms.Label();
this.label25 = new System.Windows.Forms.Label();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.btnExportImages = new System.Windows.Forms.Button();
this.tbxExportImagesPath = new System.Windows.Forms.TextBox();
this.label30 = new System.Windows.Forms.Label();
this.btnSelectImagePath = new System.Windows.Forms.Button();
this.panel1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox1.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox4.SuspendLayout();
this.SuspendLayout();
//
// button1
......@@ -593,15 +599,7 @@
//
// groupBox3
//
this.groupBox3.Controls.Add(this.label27);
this.groupBox3.Controls.Add(this.btnStamp2);
this.groupBox3.Controls.Add(this.tbxPdfFilePath2);
this.groupBox3.Controls.Add(this.tbxSaveFolder2);
this.groupBox3.Controls.Add(this.btnSelectSaveFolder2);
this.groupBox3.Controls.Add(this.btnSelectFile2);
this.groupBox3.Controls.Add(this.label26);
this.groupBox3.Controls.Add(this.label24);
this.groupBox3.Controls.Add(this.label25);
this.groupBox3.Controls.Add(this.groupBox4);
this.groupBox3.Dock = System.Windows.Forms.DockStyle.Left;
this.groupBox3.Location = new System.Drawing.Point(441, 0);
this.groupBox3.Name = "groupBox3";
......@@ -612,7 +610,7 @@
//
// label27
//
this.label27.Location = new System.Drawing.Point(18, 90);
this.label27.Location = new System.Drawing.Point(838, 109);
this.label27.Name = "label27";
this.label27.Size = new System.Drawing.Size(331, 43);
this.label27.TabIndex = 7;
......@@ -620,7 +618,7 @@
//
// btnStamp2
//
this.btnStamp2.Location = new System.Drawing.Point(20, 227);
this.btnStamp2.Location = new System.Drawing.Point(840, 246);
this.btnStamp2.Name = "btnStamp2";
this.btnStamp2.Size = new System.Drawing.Size(75, 23);
this.btnStamp2.TabIndex = 6;
......@@ -630,21 +628,21 @@
//
// tbxPdfFilePath2
//
this.tbxPdfFilePath2.Location = new System.Drawing.Point(83, 30);
this.tbxPdfFilePath2.Location = new System.Drawing.Point(903, 49);
this.tbxPdfFilePath2.Name = "tbxPdfFilePath2";
this.tbxPdfFilePath2.Size = new System.Drawing.Size(218, 21);
this.tbxPdfFilePath2.TabIndex = 4;
//
// tbxSaveFolder2
//
this.tbxSaveFolder2.Location = new System.Drawing.Point(83, 182);
this.tbxSaveFolder2.Location = new System.Drawing.Point(903, 201);
this.tbxSaveFolder2.Name = "tbxSaveFolder2";
this.tbxSaveFolder2.Size = new System.Drawing.Size(218, 21);
this.tbxSaveFolder2.TabIndex = 4;
//
// btnSelectSaveFolder2
//
this.btnSelectSaveFolder2.Location = new System.Drawing.Point(317, 182);
this.btnSelectSaveFolder2.Location = new System.Drawing.Point(1137, 201);
this.btnSelectSaveFolder2.Name = "btnSelectSaveFolder2";
this.btnSelectSaveFolder2.Size = new System.Drawing.Size(32, 23);
this.btnSelectSaveFolder2.TabIndex = 5;
......@@ -654,7 +652,7 @@
//
// btnSelectFile2
//
this.btnSelectFile2.Location = new System.Drawing.Point(317, 30);
this.btnSelectFile2.Location = new System.Drawing.Point(1137, 49);
this.btnSelectFile2.Name = "btnSelectFile2";
this.btnSelectFile2.Size = new System.Drawing.Size(32, 23);
this.btnSelectFile2.TabIndex = 5;
......@@ -665,7 +663,7 @@
// label26
//
this.label26.AutoSize = true;
this.label26.Location = new System.Drawing.Point(18, 185);
this.label26.Location = new System.Drawing.Point(838, 204);
this.label26.Name = "label26";
this.label26.Size = new System.Drawing.Size(53, 12);
this.label26.TabIndex = 1;
......@@ -674,7 +672,7 @@
// label24
//
this.label24.AutoSize = true;
this.label24.Location = new System.Drawing.Point(81, 54);
this.label24.Location = new System.Drawing.Point(901, 73);
this.label24.Name = "label24";
this.label24.Size = new System.Drawing.Size(161, 12);
this.label24.TabIndex = 6;
......@@ -683,22 +681,81 @@
// label25
//
this.label25.AutoSize = true;
this.label25.Location = new System.Drawing.Point(18, 33);
this.label25.Location = new System.Drawing.Point(838, 52);
this.label25.Name = "label25";
this.label25.Size = new System.Drawing.Size(47, 12);
this.label25.TabIndex = 1;
this.label25.Text = "PDF路径";
//
// groupBox4
//
this.groupBox4.Controls.Add(this.btnSelectImagePath);
this.groupBox4.Controls.Add(this.btnExportImages);
this.groupBox4.Controls.Add(this.tbxExportImagesPath);
this.groupBox4.Controls.Add(this.label30);
this.groupBox4.Dock = System.Windows.Forms.DockStyle.Top;
this.groupBox4.Location = new System.Drawing.Point(3, 17);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(360, 107);
this.groupBox4.TabIndex = 8;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "获取图片";
//
// btnExportImages
//
this.btnExportImages.Location = new System.Drawing.Point(16, 63);
this.btnExportImages.Name = "btnExportImages";
this.btnExportImages.Size = new System.Drawing.Size(75, 23);
this.btnExportImages.TabIndex = 9;
this.btnExportImages.Text = "导出图片";
this.btnExportImages.UseVisualStyleBackColor = true;
this.btnExportImages.Click += new System.EventHandler(this.btnExportImages_Click);
//
// tbxExportImagesPath
//
this.tbxExportImagesPath.Location = new System.Drawing.Point(79, 26);
this.tbxExportImagesPath.Name = "tbxExportImagesPath";
this.tbxExportImagesPath.Size = new System.Drawing.Size(208, 21);
this.tbxExportImagesPath.TabIndex = 8;
//
// label30
//
this.label30.AutoSize = true;
this.label30.Location = new System.Drawing.Point(14, 29);
this.label30.Name = "label30";
this.label30.Size = new System.Drawing.Size(53, 12);
this.label30.TabIndex = 7;
this.label30.Text = "保存路径";
//
// btnSelectImagePath
//
this.btnSelectImagePath.Location = new System.Drawing.Point(293, 24);
this.btnSelectImagePath.Name = "btnSelectImagePath";
this.btnSelectImagePath.Size = new System.Drawing.Size(32, 23);
this.btnSelectImagePath.TabIndex = 10;
this.btnSelectImagePath.Text = "...";
this.btnSelectImagePath.UseVisualStyleBackColor = true;
this.btnSelectImagePath.Click += new System.EventHandler(this.btnSelectImagePath_Click);
//
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1185, 657);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.label27);
this.Controls.Add(this.panel1);
this.Controls.Add(this.btnStamp2);
this.Controls.Add(this.label2);
this.Controls.Add(this.tbxPdfFilePath2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.tbxSaveFolder2);
this.Controls.Add(this.button1);
this.Controls.Add(this.btnSelectSaveFolder2);
this.Controls.Add(this.label25);
this.Controls.Add(this.btnSelectFile2);
this.Controls.Add(this.label24);
this.Controls.Add(this.label26);
this.Name = "frmMain";
this.Text = "PDF ";
this.panel1.ResumeLayout(false);
......@@ -707,7 +764,8 @@
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
......@@ -776,6 +834,11 @@
private System.Windows.Forms.Button btnStampByService;
private System.Windows.Forms.TextBox tbxServiceUrl;
private System.Windows.Forms.Label label29;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Button btnExportImages;
private System.Windows.Forms.TextBox tbxExportImagesPath;
private System.Windows.Forms.Label label30;
private System.Windows.Forms.Button btnSelectImagePath;
}
}
......@@ -214,5 +214,38 @@ namespace Kivii.Pdf.Test
}
catch { }
}
private void btnSelectImagePath_Click(object sender, EventArgs e)
{
FolderBrowserDialog sfd = new FolderBrowserDialog();
if (sfd.ShowDialog() != DialogResult.OK) return;
tbxExportImagesPath.Text = sfd.SelectedPath;
}
private void btnExportImages_Click(object sender, EventArgs e)
{
var reader = new PdfReader(tbxPdfFilePath.Text);
for (var i = 0; i < reader.XrefSize; i++)
{
var pdfObj = reader.GetPdfObject(i);
if (pdfObj == null || !pdfObj.IsStream()) continue;
var pdfStream = (PdfStream)pdfObj;
var subType= pdfStream.Get(PdfName.SUBTYPE);
if (subType == null || subType.ToString() != PdfName.IMAGE.ToString()) continue;
var bytes = PdfReader.GetStreamBytesRaw((PRStream)pdfStream);
if (bytes == null) continue;
try
{
var ms = new MemoryStream(bytes);
ms.Position = 0;
var img = System.Drawing.Image.FromStream(ms);
img.Save(Path.Combine(tbxExportImagesPath.Text, $"{i}.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch
{ }
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Kivii.Common" version="5.5.2020.9280" targetFramework="net40" />
<package id="Kivii.Common" version="5.6.2021.5080" targetFramework="net40" />
<package id="Kivii.Pdf" version="5.5.2020.11000" targetFramework="net40" />
</packages>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment