Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 33f9723ac6 | |||
| 13ba41f851 | |||
| 06de734658 | |||
| 901d7e62ca | |||
| 631f8c34b2 | |||
| 7ac6b19331 | |||
| 34e7424273 | |||
| 6b8bbc367f | |||
| 6dfc248b9a | |||
| f3aca2ffa5 | |||
| 7ba320a22c | |||
| 1edddf17b1 | |||
| 62120898d2 | |||
| dc1b9bc7ca | |||
| d1ea41474b | |||
| b11a2ac393 | |||
| 36fb20eb2e | |||
| 15fbec2470 | |||
| 52841de51b | |||
| d4c4615684 | |||
| ae76cab45d | |||
| 8dc54105fd | |||
| 3469593a2a | |||
| ebff0c2028 | |||
| 2fd074e041 | |||
| 4223619802 | |||
| 771305f5d0 | |||
| 90c7c5db92 |
@@ -1,29 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VAR.PdfTools.Net35", "VAR.PdfTools\VAR.PdfTools.Net35.csproj", "{EB7E003A-6A95-4002-809F-926C7C8A11E9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VAR.PdfTools.Workbench.Net35", "VAR.PdfTools.Workbench\VAR.PdfTools.Workbench.Net35.csproj", "{A5825D8E-9F81-49E0-B610-8AE5E46D02EA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A5825D8E-9F81-49E0-B610-8AE5E46D02EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A5825D8E-9F81-49E0-B610-8AE5E46D02EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A5825D8E-9F81-49E0-B610-8AE5E46D02EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A5825D8E-9F81-49E0-B610-8AE5E46D02EA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EB7E003A-6A95-4002-809F-926C7C8A11E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EB7E003A-6A95-4002-809F-926C7C8A11E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EB7E003A-6A95-4002-809F-926C7C8A11E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EB7E003A-6A95-4002-809F-926C7C8A11E9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = VAR.PdfTools.Workbench\VAR.PdfTools.Workbench.Net35.csproj
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
206
VAR.PdfTools.Workbench/FrmPdfInfo.Designer.cs
generated
206
VAR.PdfTools.Workbench/FrmPdfInfo.Designer.cs
generated
@@ -34,12 +34,19 @@
|
||||
this.txtPdfPath = new System.Windows.Forms.TextBox();
|
||||
this.txtOutput = new System.Windows.Forms.TextBox();
|
||||
this.btnProcess = new System.Windows.Forms.Button();
|
||||
this.btnGetColumn = new System.Windows.Forms.Button();
|
||||
this.txtColumnName = new System.Windows.Forms.TextBox();
|
||||
this.txtFieldName = new System.Windows.Forms.TextBox();
|
||||
this.btnGetField = new System.Windows.Forms.Button();
|
||||
this.txtText = new System.Windows.Forms.TextBox();
|
||||
this.btnHasText = new System.Windows.Forms.Button();
|
||||
this.btnGetColumn1 = new System.Windows.Forms.Button();
|
||||
this.txtField1 = new System.Windows.Forms.TextBox();
|
||||
this.btnGetField1 = new System.Windows.Forms.Button();
|
||||
this.btnHasText1 = new System.Windows.Forms.Button();
|
||||
this.btnRender = new System.Windows.Forms.Button();
|
||||
this.btnHasText2 = new System.Windows.Forms.Button();
|
||||
this.btnGetField2 = new System.Windows.Forms.Button();
|
||||
this.txtField2 = new System.Windows.Forms.TextBox();
|
||||
this.btnGetColumn2 = new System.Windows.Forms.Button();
|
||||
this.btnHasText3 = new System.Windows.Forms.Button();
|
||||
this.btnGetField3 = new System.Windows.Forms.Button();
|
||||
this.txtField3 = new System.Windows.Forms.TextBox();
|
||||
this.btnGetColumn3 = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// lblOutputs
|
||||
@@ -108,68 +115,146 @@
|
||||
this.btnProcess.UseVisualStyleBackColor = true;
|
||||
this.btnProcess.Click += new System.EventHandler(this.btnProcess_Click);
|
||||
//
|
||||
// btnGetColumn
|
||||
// btnGetColumn1
|
||||
//
|
||||
this.btnGetColumn.Location = new System.Drawing.Point(163, 51);
|
||||
this.btnGetColumn.Name = "btnGetColumn";
|
||||
this.btnGetColumn.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnGetColumn.TabIndex = 12;
|
||||
this.btnGetColumn.Text = "GetColumn";
|
||||
this.btnGetColumn.UseVisualStyleBackColor = true;
|
||||
this.btnGetColumn.Click += new System.EventHandler(this.btnGetColumn_Click);
|
||||
this.btnGetColumn1.Location = new System.Drawing.Point(292, 51);
|
||||
this.btnGetColumn1.Name = "btnGetColumn1";
|
||||
this.btnGetColumn1.Size = new System.Drawing.Size(60, 23);
|
||||
this.btnGetColumn1.TabIndex = 12;
|
||||
this.btnGetColumn1.Text = "GetColumn";
|
||||
this.btnGetColumn1.UseVisualStyleBackColor = true;
|
||||
this.btnGetColumn1.Click += new System.EventHandler(this.btnGetColumn1_Click);
|
||||
//
|
||||
// txtColumnName
|
||||
// txtField1
|
||||
//
|
||||
this.txtColumnName.Location = new System.Drawing.Point(15, 53);
|
||||
this.txtColumnName.Name = "txtColumnName";
|
||||
this.txtColumnName.Size = new System.Drawing.Size(142, 20);
|
||||
this.txtColumnName.TabIndex = 13;
|
||||
this.txtField1.Location = new System.Drawing.Point(15, 53);
|
||||
this.txtField1.Name = "txtField1";
|
||||
this.txtField1.Size = new System.Drawing.Size(142, 20);
|
||||
this.txtField1.TabIndex = 13;
|
||||
//
|
||||
// txtFieldName
|
||||
// btnGetField1
|
||||
//
|
||||
this.txtFieldName.Location = new System.Drawing.Point(15, 82);
|
||||
this.txtFieldName.Name = "txtFieldName";
|
||||
this.txtFieldName.Size = new System.Drawing.Size(142, 20);
|
||||
this.txtFieldName.TabIndex = 15;
|
||||
this.btnGetField1.Location = new System.Drawing.Point(226, 51);
|
||||
this.btnGetField1.Name = "btnGetField1";
|
||||
this.btnGetField1.Size = new System.Drawing.Size(60, 23);
|
||||
this.btnGetField1.TabIndex = 14;
|
||||
this.btnGetField1.Text = "GetField";
|
||||
this.btnGetField1.UseVisualStyleBackColor = true;
|
||||
this.btnGetField1.Click += new System.EventHandler(this.btnGetField1_Click);
|
||||
//
|
||||
// btnGetField
|
||||
// btnHasText1
|
||||
//
|
||||
this.btnGetField.Location = new System.Drawing.Point(163, 80);
|
||||
this.btnGetField.Name = "btnGetField";
|
||||
this.btnGetField.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnGetField.TabIndex = 14;
|
||||
this.btnGetField.Text = "GetField";
|
||||
this.btnGetField.UseVisualStyleBackColor = true;
|
||||
this.btnGetField.Click += new System.EventHandler(this.btnGetField_Click);
|
||||
this.btnHasText1.Location = new System.Drawing.Point(163, 51);
|
||||
this.btnHasText1.Name = "btnHasText1";
|
||||
this.btnHasText1.Size = new System.Drawing.Size(57, 23);
|
||||
this.btnHasText1.TabIndex = 16;
|
||||
this.btnHasText1.Text = "HasText";
|
||||
this.btnHasText1.UseVisualStyleBackColor = true;
|
||||
this.btnHasText1.Click += new System.EventHandler(this.btnHasText1_Click);
|
||||
//
|
||||
// txtText
|
||||
// btnRender
|
||||
//
|
||||
this.txtText.Location = new System.Drawing.Point(15, 111);
|
||||
this.txtText.Name = "txtText";
|
||||
this.txtText.Size = new System.Drawing.Size(142, 20);
|
||||
this.txtText.TabIndex = 17;
|
||||
this.btnRender.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnRender.Location = new System.Drawing.Point(397, 52);
|
||||
this.btnRender.Name = "btnRender";
|
||||
this.btnRender.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnRender.TabIndex = 18;
|
||||
this.btnRender.Text = "Render";
|
||||
this.btnRender.UseVisualStyleBackColor = true;
|
||||
this.btnRender.Click += new System.EventHandler(this.btnRender_Click);
|
||||
//
|
||||
// btnHasText
|
||||
// btnHasText2
|
||||
//
|
||||
this.btnHasText.Location = new System.Drawing.Point(163, 109);
|
||||
this.btnHasText.Name = "btnHasText";
|
||||
this.btnHasText.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnHasText.TabIndex = 16;
|
||||
this.btnHasText.Text = "HasText";
|
||||
this.btnHasText.UseVisualStyleBackColor = true;
|
||||
this.btnHasText.Click += new System.EventHandler(this.btnHasText_Click);
|
||||
this.btnHasText2.Location = new System.Drawing.Point(163, 80);
|
||||
this.btnHasText2.Name = "btnHasText2";
|
||||
this.btnHasText2.Size = new System.Drawing.Size(57, 23);
|
||||
this.btnHasText2.TabIndex = 22;
|
||||
this.btnHasText2.Text = "HasText";
|
||||
this.btnHasText2.UseVisualStyleBackColor = true;
|
||||
this.btnHasText2.Click += new System.EventHandler(this.btnHasText2_Click);
|
||||
//
|
||||
// btnGetField2
|
||||
//
|
||||
this.btnGetField2.Location = new System.Drawing.Point(226, 80);
|
||||
this.btnGetField2.Name = "btnGetField2";
|
||||
this.btnGetField2.Size = new System.Drawing.Size(60, 23);
|
||||
this.btnGetField2.TabIndex = 21;
|
||||
this.btnGetField2.Text = "GetField";
|
||||
this.btnGetField2.UseVisualStyleBackColor = true;
|
||||
this.btnGetField2.Click += new System.EventHandler(this.btnGetField2_Click);
|
||||
//
|
||||
// txtField2
|
||||
//
|
||||
this.txtField2.Location = new System.Drawing.Point(15, 82);
|
||||
this.txtField2.Name = "txtField2";
|
||||
this.txtField2.Size = new System.Drawing.Size(142, 20);
|
||||
this.txtField2.TabIndex = 20;
|
||||
//
|
||||
// btnGetColumn2
|
||||
//
|
||||
this.btnGetColumn2.Location = new System.Drawing.Point(292, 80);
|
||||
this.btnGetColumn2.Name = "btnGetColumn2";
|
||||
this.btnGetColumn2.Size = new System.Drawing.Size(60, 23);
|
||||
this.btnGetColumn2.TabIndex = 19;
|
||||
this.btnGetColumn2.Text = "GetColumn";
|
||||
this.btnGetColumn2.UseVisualStyleBackColor = true;
|
||||
this.btnGetColumn2.Click += new System.EventHandler(this.btnGetColumn2_Click);
|
||||
//
|
||||
// btnHasText3
|
||||
//
|
||||
this.btnHasText3.Location = new System.Drawing.Point(163, 109);
|
||||
this.btnHasText3.Name = "btnHasText3";
|
||||
this.btnHasText3.Size = new System.Drawing.Size(57, 23);
|
||||
this.btnHasText3.TabIndex = 26;
|
||||
this.btnHasText3.Text = "HasText";
|
||||
this.btnHasText3.UseVisualStyleBackColor = true;
|
||||
this.btnHasText3.Click += new System.EventHandler(this.btnHasText3_Click);
|
||||
//
|
||||
// btnGetField3
|
||||
//
|
||||
this.btnGetField3.Location = new System.Drawing.Point(226, 109);
|
||||
this.btnGetField3.Name = "btnGetField3";
|
||||
this.btnGetField3.Size = new System.Drawing.Size(60, 23);
|
||||
this.btnGetField3.TabIndex = 25;
|
||||
this.btnGetField3.Text = "GetField";
|
||||
this.btnGetField3.UseVisualStyleBackColor = true;
|
||||
this.btnGetField3.Click += new System.EventHandler(this.btnGetField3_Click);
|
||||
//
|
||||
// txtField3
|
||||
//
|
||||
this.txtField3.Location = new System.Drawing.Point(15, 111);
|
||||
this.txtField3.Name = "txtField3";
|
||||
this.txtField3.Size = new System.Drawing.Size(142, 20);
|
||||
this.txtField3.TabIndex = 24;
|
||||
//
|
||||
// btnGetColumn3
|
||||
//
|
||||
this.btnGetColumn3.Location = new System.Drawing.Point(292, 109);
|
||||
this.btnGetColumn3.Name = "btnGetColumn3";
|
||||
this.btnGetColumn3.Size = new System.Drawing.Size(60, 23);
|
||||
this.btnGetColumn3.TabIndex = 23;
|
||||
this.btnGetColumn3.Text = "GetColumn";
|
||||
this.btnGetColumn3.UseVisualStyleBackColor = true;
|
||||
this.btnGetColumn3.Click += new System.EventHandler(this.btnGetColumn3_Click);
|
||||
//
|
||||
// FrmPdfInfo
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(484, 461);
|
||||
this.Controls.Add(this.txtText);
|
||||
this.Controls.Add(this.btnHasText);
|
||||
this.Controls.Add(this.txtFieldName);
|
||||
this.Controls.Add(this.btnGetField);
|
||||
this.Controls.Add(this.txtColumnName);
|
||||
this.Controls.Add(this.btnGetColumn);
|
||||
this.Controls.Add(this.btnHasText3);
|
||||
this.Controls.Add(this.btnGetField3);
|
||||
this.Controls.Add(this.txtField3);
|
||||
this.Controls.Add(this.btnGetColumn3);
|
||||
this.Controls.Add(this.btnHasText2);
|
||||
this.Controls.Add(this.btnGetField2);
|
||||
this.Controls.Add(this.txtField2);
|
||||
this.Controls.Add(this.btnGetColumn2);
|
||||
this.Controls.Add(this.btnRender);
|
||||
this.Controls.Add(this.btnHasText1);
|
||||
this.Controls.Add(this.btnGetField1);
|
||||
this.Controls.Add(this.txtField1);
|
||||
this.Controls.Add(this.btnGetColumn1);
|
||||
this.Controls.Add(this.lblOutputs);
|
||||
this.Controls.Add(this.lblInputs);
|
||||
this.Controls.Add(this.btnBrowse);
|
||||
@@ -193,11 +278,18 @@
|
||||
private System.Windows.Forms.TextBox txtPdfPath;
|
||||
private System.Windows.Forms.TextBox txtOutput;
|
||||
private System.Windows.Forms.Button btnProcess;
|
||||
private System.Windows.Forms.Button btnGetColumn;
|
||||
private System.Windows.Forms.TextBox txtColumnName;
|
||||
private System.Windows.Forms.TextBox txtFieldName;
|
||||
private System.Windows.Forms.Button btnGetField;
|
||||
private System.Windows.Forms.TextBox txtText;
|
||||
private System.Windows.Forms.Button btnHasText;
|
||||
private System.Windows.Forms.Button btnGetColumn1;
|
||||
private System.Windows.Forms.TextBox txtField1;
|
||||
private System.Windows.Forms.Button btnGetField1;
|
||||
private System.Windows.Forms.Button btnHasText1;
|
||||
private System.Windows.Forms.Button btnRender;
|
||||
private System.Windows.Forms.Button btnHasText2;
|
||||
private System.Windows.Forms.Button btnGetField2;
|
||||
private System.Windows.Forms.TextBox txtField2;
|
||||
private System.Windows.Forms.Button btnGetColumn2;
|
||||
private System.Windows.Forms.Button btnHasText3;
|
||||
private System.Windows.Forms.Button btnGetField3;
|
||||
private System.Windows.Forms.TextBox txtField3;
|
||||
private System.Windows.Forms.Button btnGetColumn3;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using VAR.PdfTools.PdfElements;
|
||||
|
||||
namespace VAR.PdfTools.Workbench
|
||||
{
|
||||
@@ -15,17 +21,17 @@ namespace VAR.PdfTools.Workbench
|
||||
private void FrmPdfInfo_Load(object sender, EventArgs e)
|
||||
{
|
||||
txtPdfPath.Text = Properties.Settings.Default.LastPdfPath;
|
||||
txtColumnName.Text = Properties.Settings.Default.LastColumnName;
|
||||
txtFieldName.Text = Properties.Settings.Default.LastFieldName;
|
||||
txtText.Text = Properties.Settings.Default.LastText;
|
||||
txtField1.Text = Properties.Settings.Default.Field1;
|
||||
txtField2.Text = Properties.Settings.Default.Field2;
|
||||
txtField3.Text = Properties.Settings.Default.Field3;
|
||||
}
|
||||
|
||||
private void FrmPdfInfo_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
Properties.Settings.Default.LastPdfPath = txtPdfPath.Text;
|
||||
Properties.Settings.Default.LastColumnName = txtColumnName.Text;
|
||||
Properties.Settings.Default.LastFieldName = txtFieldName.Text;
|
||||
Properties.Settings.Default.LastText = txtText.Text;
|
||||
Properties.Settings.Default.Field1 = txtField1.Text;
|
||||
Properties.Settings.Default.Field2 = txtField2.Text;
|
||||
Properties.Settings.Default.Field3 = txtField3.Text;
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
|
||||
@@ -87,9 +93,25 @@ namespace VAR.PdfTools.Workbench
|
||||
PdfTextExtractor extractor = new PdfTextExtractor(page);
|
||||
foreach (PdfTextElement textElement in extractor.Elements)
|
||||
{
|
||||
string fontName = textElement.Font == null ? "#NULL#" : textElement.Font.Name;
|
||||
if (fontName == "#NULL#" && textElement.Childs.Count > 0)
|
||||
{
|
||||
var fontNames = textElement.Childs.Select(c => c.Font == null ? "#NULL#" : c.Font.Name);
|
||||
StringBuilder sbFontName = new StringBuilder();
|
||||
foreach(string fontNameAux in fontNames)
|
||||
{
|
||||
if (sbFontName.Length > 0) { sbFontName.Append(";"); }
|
||||
sbFontName.Append(fontNameAux);
|
||||
}
|
||||
fontName = sbFontName.ToString();
|
||||
}
|
||||
|
||||
lines.Add(string.Format("Text({0}, {1})({2}, {3})[{4}]: \"{5}\"",
|
||||
textElement.Matrix.Matrix[0, 2], textElement.Matrix.Matrix[1, 2], textElement.VisibleWidth, textElement.VisibleHeight,
|
||||
textElement.Font == null ? string.Empty : textElement.Font.Name,
|
||||
Math.Round(textElement.Matrix.Matrix[0, 2], 2),
|
||||
Math.Round(textElement.Matrix.Matrix[1, 2], 2),
|
||||
Math.Round(textElement.VisibleWidth, 2),
|
||||
Math.Round(textElement.VisibleHeight, 2),
|
||||
fontName,
|
||||
textElement.VisibleText));
|
||||
}
|
||||
}
|
||||
@@ -97,62 +119,287 @@ namespace VAR.PdfTools.Workbench
|
||||
txtOutput.Lines = lines.ToArray();
|
||||
}
|
||||
|
||||
private void btnGetColumn_Click(object sender, EventArgs e)
|
||||
private void btnHasText1_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (System.IO.File.Exists(txtPdfPath.Text) == false)
|
||||
string pdfPath = txtPdfPath.Text;
|
||||
string text = txtField1.Text;
|
||||
|
||||
Action_HasText(pdfPath, text);
|
||||
}
|
||||
|
||||
private void btnGetField1_Click(object sender, EventArgs e)
|
||||
{
|
||||
string pdfPath = txtPdfPath.Text;
|
||||
string field = txtField1.Text;
|
||||
|
||||
Action_GetField(pdfPath, field);
|
||||
}
|
||||
|
||||
private void btnGetColumn1_Click(object sender, EventArgs e)
|
||||
{
|
||||
string pdfPath = txtPdfPath.Text;
|
||||
string column = txtField1.Text;
|
||||
|
||||
Action_GetColumn(pdfPath, column);
|
||||
}
|
||||
|
||||
private void btnHasText2_Click(object sender, EventArgs e)
|
||||
{
|
||||
string pdfPath = txtPdfPath.Text;
|
||||
string text = txtField2.Text;
|
||||
|
||||
Action_HasText(pdfPath, text);
|
||||
}
|
||||
|
||||
private void btnGetField2_Click(object sender, EventArgs e)
|
||||
{
|
||||
string pdfPath = txtPdfPath.Text;
|
||||
string field = txtField2.Text;
|
||||
|
||||
Action_GetField(pdfPath, field);
|
||||
}
|
||||
|
||||
private void btnGetColumn2_Click(object sender, EventArgs e)
|
||||
{
|
||||
string pdfPath = txtPdfPath.Text;
|
||||
string column = txtField2.Text;
|
||||
|
||||
Action_GetColumn(pdfPath, column);
|
||||
}
|
||||
|
||||
private void btnHasText3_Click(object sender, EventArgs e)
|
||||
{
|
||||
string pdfPath = txtPdfPath.Text;
|
||||
string text = txtField3.Text;
|
||||
|
||||
Action_HasText(pdfPath, text);
|
||||
}
|
||||
|
||||
private void btnGetField3_Click(object sender, EventArgs e)
|
||||
{
|
||||
string pdfPath = txtPdfPath.Text;
|
||||
string field = txtField3.Text;
|
||||
|
||||
Action_GetField(pdfPath, field);
|
||||
}
|
||||
|
||||
private void btnGetColumn3_Click(object sender, EventArgs e)
|
||||
{
|
||||
string pdfPath = txtPdfPath.Text;
|
||||
string column = txtField3.Text;
|
||||
|
||||
Action_GetColumn(pdfPath, column);
|
||||
}
|
||||
|
||||
private void Action_HasText(string pdfPath, string text)
|
||||
{
|
||||
if (System.IO.File.Exists(pdfPath) == false)
|
||||
{
|
||||
MessageBox.Show("File does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
PdfDocument doc = PdfDocument.Load(txtPdfPath.Text);
|
||||
|
||||
var columnData = new List<string>();
|
||||
foreach (PdfDocumentPage page in doc.Pages)
|
||||
{
|
||||
PdfTextExtractor extractor = new PdfTextExtractor(page);
|
||||
columnData.AddRange(extractor.GetColumn(txtColumnName.Text));
|
||||
}
|
||||
txtOutput.Lines = columnData.ToArray();
|
||||
}
|
||||
|
||||
private void btnGetField_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (System.IO.File.Exists(txtPdfPath.Text) == false)
|
||||
{
|
||||
MessageBox.Show("File does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
PdfDocument doc = PdfDocument.Load(txtPdfPath.Text);
|
||||
|
||||
var fieldData = new List<string>();
|
||||
foreach (PdfDocumentPage page in doc.Pages)
|
||||
{
|
||||
PdfTextExtractor extractor = new PdfTextExtractor(page);
|
||||
fieldData.Add(extractor.GetField(txtFieldName.Text));
|
||||
}
|
||||
txtOutput.Lines = fieldData.ToArray();
|
||||
}
|
||||
|
||||
private void btnHasText_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (System.IO.File.Exists(txtPdfPath.Text) == false)
|
||||
{
|
||||
MessageBox.Show("File does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
PdfDocument doc = PdfDocument.Load(txtPdfPath.Text);
|
||||
PdfDocument doc = PdfDocument.Load(pdfPath);
|
||||
|
||||
List<string> lines = new List<string>();
|
||||
int pageNum = 1;
|
||||
foreach (PdfDocumentPage page in doc.Pages)
|
||||
{
|
||||
PdfTextExtractor extractor = new PdfTextExtractor(page);
|
||||
lines.Add(string.Format("Page({0}) : {1}", pageNum, Convert.ToString(extractor.HasText(txtText.Text))));
|
||||
lines.Add(string.Format("Page({0}) : {1}", pageNum, Convert.ToString(extractor.HasText(text))));
|
||||
}
|
||||
txtOutput.Lines = lines.ToArray();
|
||||
}
|
||||
|
||||
private void Action_GetField(string pdfPath, string field)
|
||||
{
|
||||
if (System.IO.File.Exists(pdfPath) == false)
|
||||
{
|
||||
MessageBox.Show("File does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
PdfDocument doc = PdfDocument.Load(pdfPath);
|
||||
|
||||
var fieldData = new List<string>();
|
||||
foreach (PdfDocumentPage page in doc.Pages)
|
||||
{
|
||||
PdfTextExtractor extractor = new PdfTextExtractor(page);
|
||||
fieldData.Add(extractor.GetField(field));
|
||||
}
|
||||
txtOutput.Lines = fieldData.ToArray();
|
||||
}
|
||||
|
||||
private void Action_GetColumn(string pdfPath, string column)
|
||||
{
|
||||
if (System.IO.File.Exists(pdfPath) == false)
|
||||
{
|
||||
MessageBox.Show("File does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
PdfDocument doc = PdfDocument.Load(pdfPath);
|
||||
|
||||
var columnData = new List<string>();
|
||||
foreach (PdfDocumentPage page in doc.Pages)
|
||||
{
|
||||
PdfTextExtractor extractor = new PdfTextExtractor(page);
|
||||
columnData.AddRange(extractor.GetColumn(column));
|
||||
}
|
||||
txtOutput.Lines = columnData.ToArray();
|
||||
}
|
||||
|
||||
private void btnRender_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (File.Exists(txtPdfPath.Text) == false)
|
||||
{
|
||||
MessageBox.Show("File does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
int MaxSize = 10000;
|
||||
|
||||
PdfDocument doc = PdfDocument.Load(txtPdfPath.Text);
|
||||
string baseDocumentPath = Path.GetDirectoryName(txtPdfPath.Text);
|
||||
string baseDocumentFilename = Path.GetFileNameWithoutExtension(txtPdfPath.Text);
|
||||
|
||||
List<string> lines = new List<string>();
|
||||
lines.Add(string.Format("Filename : {0}", baseDocumentFilename));
|
||||
lines.Add(string.Format("Number of Pages : {0}", doc.Pages.Count));
|
||||
|
||||
int pageNumber = 1;
|
||||
foreach (PdfDocumentPage page in doc.Pages)
|
||||
{
|
||||
double pageXMin = double.MaxValue;
|
||||
double pageYMin = double.MaxValue;
|
||||
double pageXMax = double.MinValue;
|
||||
double pageYMax = double.MinValue;
|
||||
|
||||
// Preprocess page to get max size
|
||||
PdfTextExtractor extractor = new PdfTextExtractor(page);
|
||||
foreach (PdfTextElement textElement in extractor.Elements)
|
||||
{
|
||||
double textElementXMin = textElement.GetX();
|
||||
double textElementYMax = textElement.GetY();
|
||||
double textElementXMax = textElementXMin + textElement.VisibleWidth;
|
||||
double textElementYMin = textElementYMax - textElement.VisibleHeight;
|
||||
|
||||
if (textElementXMax > pageXMax) { pageXMax = textElementXMax; }
|
||||
if (textElementYMax > pageYMax) { pageYMax = textElementYMax; }
|
||||
if (textElementXMin < pageXMin) { pageXMin = textElementXMin; }
|
||||
if (textElementYMin < pageYMin) { pageYMin = textElementYMin; }
|
||||
}
|
||||
lines.Add(string.Format("Page {0:0000} TextElements : {1}", pageNumber, extractor.Elements.Count));
|
||||
|
||||
// Prepare page image
|
||||
int pageWidth = (int)Math.Ceiling(pageXMax - pageXMin);
|
||||
int pageHeight = (int)Math.Ceiling(pageYMax - pageYMin);
|
||||
int Scale = 10;
|
||||
while ((pageWidth * Scale) > MaxSize) { Scale--; }
|
||||
while ((pageHeight * Scale) > MaxSize) { Scale--; }
|
||||
if (Scale <= 0) { Scale = 1; }
|
||||
using (Bitmap bmp = new Bitmap(pageWidth * Scale, pageHeight * Scale, PixelFormat.Format32bppArgb))
|
||||
using (Graphics gc = Graphics.FromImage(bmp))
|
||||
using (Pen penTextElem = new Pen(Color.Blue))
|
||||
{
|
||||
gc.Clear(Color.White);
|
||||
|
||||
// Draw text elements
|
||||
foreach (PdfTextElement textElement in extractor.Elements)
|
||||
{
|
||||
DrawTextElement(textElement, gc, penTextElem, Scale, pageHeight, pageXMin, pageYMin);
|
||||
}
|
||||
|
||||
// Save image to disk
|
||||
string fileName = Path.Combine(baseDocumentPath, string.Format("{0}_{1:0000}.png", baseDocumentFilename, pageNumber));
|
||||
bmp.Save(fileName, ImageFormat.Png);
|
||||
}
|
||||
pageNumber++;
|
||||
}
|
||||
|
||||
txtOutput.Lines = lines.ToArray();
|
||||
}
|
||||
|
||||
private static void DrawTextElement(PdfTextElement textElement, Graphics gc, Pen penTextElem, int Scale, int pageHeight, double pageXMin, double pageYMin)
|
||||
{
|
||||
double textElementX = textElement.GetX() - pageXMin;
|
||||
double textElementY = textElement.GetY() - pageYMin;
|
||||
double textElementWidth = textElement.VisibleWidth;
|
||||
double textElementHeight = textElement.VisibleHeight;
|
||||
string textElementText = textElement.VisibleText;
|
||||
string textElementFontName = (textElement.Font == null ? string.Empty : textElement.Font.Name);
|
||||
|
||||
if (textElementHeight < 0.0001) { return; }
|
||||
|
||||
double textElementPageX = textElementX;
|
||||
double textElementPageY = pageHeight - textElementY;
|
||||
|
||||
DrawRoundedRectangle(gc, penTextElem,
|
||||
(int)(textElementPageX * Scale),
|
||||
(int)(textElementPageY * Scale),
|
||||
(int)(textElementWidth * Scale),
|
||||
(int)(textElementHeight * Scale),
|
||||
5);
|
||||
|
||||
using (Font font = new Font("Arial", (int)(textElementHeight * Scale), GraphicsUnit.Pixel))
|
||||
{
|
||||
foreach (PdfCharElement c in textElement.Characters)
|
||||
{
|
||||
gc.DrawString(c.Char,
|
||||
font,
|
||||
Brushes.Black,
|
||||
(int)((textElementPageX + c.Displacement) * Scale),
|
||||
(int)(textElementPageY * Scale));
|
||||
gc.FillRectangle(Brushes.Red,
|
||||
(int)((textElementPageX + c.Displacement) * Scale),
|
||||
(int)(textElementPageY * Scale),
|
||||
2, 2);
|
||||
gc.FillRectangle(Brushes.Green,
|
||||
(int)((textElementPageX + c.Displacement + c.Width) * Scale),
|
||||
(int)(textElementPageY * Scale),
|
||||
2, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static GraphicsPath RoundedRect(int x, int y, int width, int height, int radius)
|
||||
{
|
||||
int diameter = radius * 2;
|
||||
Size size = new Size(diameter, diameter);
|
||||
Rectangle arc = new Rectangle(x, y, diameter, diameter);
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
|
||||
// top left arc
|
||||
path.AddArc(arc, 180, 90);
|
||||
|
||||
// top right arc
|
||||
arc.X = (x + width) - diameter;
|
||||
path.AddArc(arc, 270, 90);
|
||||
|
||||
// bottom right arc
|
||||
arc.Y = (y + height) - diameter;
|
||||
path.AddArc(arc, 0, 90);
|
||||
|
||||
// bottom left arc
|
||||
arc.X = x;
|
||||
path.AddArc(arc, 90, 90);
|
||||
|
||||
path.CloseFigure();
|
||||
return path;
|
||||
}
|
||||
|
||||
public static void DrawRoundedRectangle(Graphics graphics, Pen pen, int x, int y, int width, int height, int cornerRadius)
|
||||
{
|
||||
if (graphics == null)
|
||||
throw new ArgumentNullException("graphics");
|
||||
if (pen == null)
|
||||
throw new ArgumentNullException("pen");
|
||||
|
||||
using (GraphicsPath path = RoundedRect(x, y, width, height, cornerRadius))
|
||||
{
|
||||
graphics.DrawPath(pen, path);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,9 +112,9 @@
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -11,4 +11,4 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("a5825d8e-9f81-49e0-b610-8ae5e46d02ea")]
|
||||
[assembly: AssemblyVersion("1.2.*")]
|
||||
[assembly: AssemblyVersion("1.5.1.*")]
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace VAR.PdfTools.Workbench.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
@@ -38,36 +38,36 @@ namespace VAR.PdfTools.Workbench.Properties {
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
||||
public string LastColumnName {
|
||||
public string Field1 {
|
||||
get {
|
||||
return ((string)(this["LastColumnName"]));
|
||||
return ((string)(this["Field1"]));
|
||||
}
|
||||
set {
|
||||
this["LastColumnName"] = value;
|
||||
this["Field1"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
||||
public string LastFieldName {
|
||||
public string Field2 {
|
||||
get {
|
||||
return ((string)(this["LastFieldName"]));
|
||||
return ((string)(this["Field2"]));
|
||||
}
|
||||
set {
|
||||
this["LastFieldName"] = value;
|
||||
this["Field2"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
||||
public string LastText {
|
||||
public string Field3 {
|
||||
get {
|
||||
return ((string)(this["LastText"]));
|
||||
return ((string)(this["Field3"]));
|
||||
}
|
||||
set {
|
||||
this["LastText"] = value;
|
||||
this["Field3"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
<Setting Name="LastPdfPath" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="LastColumnName" Type="System.String" Scope="User">
|
||||
<Setting Name="Field1" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="LastFieldName" Type="System.String" Scope="User">
|
||||
<Setting Name="Field2" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="LastText" Type="System.String" Scope="User">
|
||||
<Setting Name="Field3" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
</Settings>
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<None Include="app.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
@@ -71,6 +72,11 @@
|
||||
<Name>VAR.PdfTools</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="FrmPdfInfo.resx">
|
||||
<DependentUpon>FrmPdfInfo.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
24
VAR.PdfTools.Workbench/app.config
Normal file
24
VAR.PdfTools.Workbench/app.config
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
|
||||
<section name="VAR.PdfTools.Workbench.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
<userSettings>
|
||||
<VAR.PdfTools.Workbench.Properties.Settings>
|
||||
<setting name="LastPdfPath" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="Field1" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="Field2" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="Field3" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
</VAR.PdfTools.Workbench.Properties.Settings>
|
||||
</userSettings>
|
||||
</configuration>
|
||||
@@ -1,8 +1,13 @@
|
||||
@echo off
|
||||
|
||||
:: MSBuild and tools path
|
||||
if exist "%ProgramFiles%\MSBuild\14.0\bin" set PATH=%ProgramFiles%\MSBuild\14.0\bin;%PATH%
|
||||
if exist "%ProgramFiles(x86)%\MSBuild\14.0\bin" set PATH=%ProgramFiles(x86)%\MSBuild\14.0\bin;%PATH%
|
||||
if exist "%windir%\Microsoft.Net\Framework\v4.0.30319" set MsBuildPath=%windir%\Microsoft.NET\Framework\v4.0.30319
|
||||
if exist "%windir%\Microsoft.Net\Framework64\v4.0.30319" set MsBuildPath=%windir%\Microsoft.NET\Framework64\v4.0.30319
|
||||
if exist "C:\Program Files (x86)\MSBuild\14.0\Bin" set MsBuildPath=C:\Program Files (x86)\MSBuild\14.0\Bin
|
||||
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin" set MsBuildPath=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin
|
||||
set PATH=%MsBuildPath%;%PATH%
|
||||
|
||||
echo %MsBuildPath%
|
||||
|
||||
:: NuGet
|
||||
set nuget="nuget"
|
||||
@@ -18,7 +23,7 @@ msbuild VAR.PdfTools.csproj /t:Build /p:Configuration="Release .Net 4.6.1" /p:Pl
|
||||
|
||||
:: Packing Nuget
|
||||
Title Packing Nuget
|
||||
%nuget% pack VAR.PdfTools.csproj -Verbosity detailed -OutputDir "NuGet" -MSBuildVersion "14.0" -Properties Configuration="Release .Net 4.6.1" -Prop Platform=AnyCPU
|
||||
%nuget% pack VAR.PdfTools.csproj -Verbosity detailed -OutputDir "NuGet" -Properties Configuration="Release .Net 4.6.1" -Prop Platform=AnyCPU
|
||||
|
||||
title Finished
|
||||
pause
|
||||
|
||||
121
VAR.PdfTools/Maths/Matrix3x3.cs
Normal file
121
VAR.PdfTools/Maths/Matrix3x3.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
|
||||
namespace VAR.PdfTools.Maths
|
||||
{
|
||||
public class Matrix3x3
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
public double[,] _matrix = new double[3, 3];
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public double[,] Matrix { get { return _matrix; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Creator
|
||||
|
||||
public Matrix3x3()
|
||||
{
|
||||
Idenity();
|
||||
}
|
||||
|
||||
public Matrix3x3(double a, double b, double c, double d, double e, double f)
|
||||
{
|
||||
Set(a, b, c, d, e, f);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
||||
public void Idenity()
|
||||
{
|
||||
_matrix[0, 0] = 1.0;
|
||||
_matrix[0, 1] = 0.0;
|
||||
_matrix[0, 2] = 0.0;
|
||||
_matrix[1, 0] = 0.0;
|
||||
_matrix[1, 1] = 1.0;
|
||||
_matrix[1, 2] = 0.0;
|
||||
_matrix[2, 0] = 0.0;
|
||||
_matrix[2, 1] = 0.0;
|
||||
_matrix[2, 2] = 1.0;
|
||||
}
|
||||
|
||||
public void Set(double a, double b, double c, double d, double e, double f)
|
||||
{
|
||||
_matrix[0, 0] = a;
|
||||
_matrix[1, 0] = b;
|
||||
_matrix[2, 0] = 0;
|
||||
_matrix[0, 1] = c;
|
||||
_matrix[1, 1] = d;
|
||||
_matrix[2, 1] = 0;
|
||||
_matrix[0, 2] = e;
|
||||
_matrix[1, 2] = f;
|
||||
_matrix[2, 2] = 1;
|
||||
}
|
||||
|
||||
public Vector3D Multiply(Vector3D vect)
|
||||
{
|
||||
Vector3D vectResult = new Vector3D();
|
||||
|
||||
vectResult.Vector[0] = (vect.Vector[0] * _matrix[0, 0]) + (vect.Vector[1] * _matrix[0, 1]) + (vect.Vector[2] * _matrix[0, 2]);
|
||||
vectResult.Vector[1] = (vect.Vector[0] * _matrix[1, 0]) + (vect.Vector[1] * _matrix[1, 1]) + (vect.Vector[2] * _matrix[1, 2]);
|
||||
vectResult.Vector[2] = (vect.Vector[0] * _matrix[2, 0]) + (vect.Vector[1] * _matrix[2, 1]) + (vect.Vector[2] * _matrix[2, 2]);
|
||||
|
||||
return vectResult;
|
||||
}
|
||||
|
||||
public Matrix3x3 Multiply(Matrix3x3 matrix)
|
||||
{
|
||||
Matrix3x3 newMatrix = new Matrix3x3();
|
||||
|
||||
newMatrix._matrix[0, 0] = (_matrix[0, 0] * matrix._matrix[0, 0]) + (_matrix[1, 0] * matrix._matrix[0, 1]) + (_matrix[2, 0] * matrix._matrix[0, 2]);
|
||||
newMatrix._matrix[0, 1] = (_matrix[0, 1] * matrix._matrix[0, 0]) + (_matrix[1, 1] * matrix._matrix[0, 1]) + (_matrix[2, 1] * matrix._matrix[0, 2]);
|
||||
newMatrix._matrix[0, 2] = (_matrix[0, 2] * matrix._matrix[0, 0]) + (_matrix[1, 2] * matrix._matrix[0, 1]) + (_matrix[2, 2] * matrix._matrix[0, 2]);
|
||||
newMatrix._matrix[1, 0] = (_matrix[0, 0] * matrix._matrix[1, 0]) + (_matrix[1, 0] * matrix._matrix[1, 1]) + (_matrix[2, 0] * matrix._matrix[1, 2]);
|
||||
newMatrix._matrix[1, 1] = (_matrix[0, 1] * matrix._matrix[1, 0]) + (_matrix[1, 1] * matrix._matrix[1, 1]) + (_matrix[2, 1] * matrix._matrix[1, 2]);
|
||||
newMatrix._matrix[1, 2] = (_matrix[0, 2] * matrix._matrix[1, 0]) + (_matrix[1, 2] * matrix._matrix[1, 1]) + (_matrix[2, 2] * matrix._matrix[1, 2]);
|
||||
newMatrix._matrix[2, 0] = (_matrix[0, 0] * matrix._matrix[2, 0]) + (_matrix[1, 0] * matrix._matrix[2, 1]) + (_matrix[2, 0] * matrix._matrix[2, 2]);
|
||||
newMatrix._matrix[2, 1] = (_matrix[0, 1] * matrix._matrix[2, 0]) + (_matrix[1, 1] * matrix._matrix[2, 1]) + (_matrix[2, 1] * matrix._matrix[2, 2]);
|
||||
newMatrix._matrix[2, 2] = (_matrix[0, 2] * matrix._matrix[2, 0]) + (_matrix[1, 2] * matrix._matrix[2, 1]) + (_matrix[2, 2] * matrix._matrix[2, 2]);
|
||||
|
||||
return newMatrix;
|
||||
}
|
||||
|
||||
public Matrix3x3 Copy()
|
||||
{
|
||||
Matrix3x3 newMatrix = new Matrix3x3();
|
||||
|
||||
newMatrix._matrix[0, 0] = _matrix[0, 0];
|
||||
newMatrix._matrix[0, 1] = _matrix[0, 1];
|
||||
newMatrix._matrix[0, 2] = _matrix[0, 2];
|
||||
newMatrix._matrix[1, 0] = _matrix[1, 0];
|
||||
newMatrix._matrix[1, 1] = _matrix[1, 1];
|
||||
newMatrix._matrix[1, 2] = _matrix[1, 2];
|
||||
newMatrix._matrix[2, 0] = _matrix[2, 0];
|
||||
newMatrix._matrix[2, 1] = _matrix[2, 1];
|
||||
newMatrix._matrix[2, 2] = _matrix[2, 2];
|
||||
|
||||
return newMatrix;
|
||||
}
|
||||
|
||||
public bool IsCollinear(Matrix3x3 otherMatrix, double horizontalDelta = 0.00001, double verticalDelta = 0.00001)
|
||||
{
|
||||
double epsilon = 0.00001;
|
||||
return (
|
||||
Math.Abs(_matrix[0, 0] - otherMatrix.Matrix[0, 0]) <= epsilon &&
|
||||
Math.Abs(_matrix[1, 0] - otherMatrix.Matrix[1, 0]) <= epsilon &&
|
||||
Math.Abs(_matrix[0, 1] - otherMatrix.Matrix[0, 1]) <= epsilon &&
|
||||
Math.Abs(_matrix[1, 1] - otherMatrix.Matrix[1, 1]) <= epsilon &&
|
||||
Math.Abs(_matrix[0, 2] - otherMatrix.Matrix[0, 2]) <= horizontalDelta &&
|
||||
Math.Abs(_matrix[1, 2] - otherMatrix.Matrix[1, 2]) <= verticalDelta &&
|
||||
true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
33
VAR.PdfTools/Maths/Vector3D.cs
Normal file
33
VAR.PdfTools/Maths/Vector3D.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
namespace VAR.PdfTools.Maths
|
||||
{
|
||||
public class Vector3D
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
public double[] _vector = new double[3];
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public double[] Vector { get { return _vector; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Creator
|
||||
|
||||
public Vector3D()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
_vector[0] = 0.0;
|
||||
_vector[1] = 0.0;
|
||||
_vector[2] = 1.0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using VAR.PdfTools.PdfElements;
|
||||
|
||||
namespace VAR.PdfTools
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using VAR.PdfTools.PdfElements;
|
||||
|
||||
namespace VAR.PdfTools
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using VAR.PdfTools.PdfElements;
|
||||
|
||||
namespace VAR.PdfTools
|
||||
{
|
||||
|
||||
@@ -1,202 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace VAR.PdfTools
|
||||
{
|
||||
public enum PdfElementTypes
|
||||
{
|
||||
Undefined,
|
||||
Boolean,
|
||||
Integer,
|
||||
Real,
|
||||
String,
|
||||
Name,
|
||||
Array,
|
||||
Dictionary,
|
||||
Null,
|
||||
ObjectReference,
|
||||
Object,
|
||||
Stream,
|
||||
};
|
||||
|
||||
public interface IPdfElement
|
||||
{
|
||||
PdfElementTypes Type { get; }
|
||||
}
|
||||
|
||||
public class PdfBoolean : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Boolean; } }
|
||||
public bool Value { get; set; }
|
||||
}
|
||||
|
||||
public class PdfInteger : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Integer; } }
|
||||
public long Value { get; set; }
|
||||
}
|
||||
|
||||
public class PdfReal : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Real; } }
|
||||
public double Value { get; set; }
|
||||
}
|
||||
|
||||
public class PdfString : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.String; } }
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
public class PdfName : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Name; } }
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
public class PdfArray : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Array; } }
|
||||
private List<IPdfElement> _values = new List<IPdfElement>();
|
||||
public List<IPdfElement> Values { get { return _values; } }
|
||||
}
|
||||
|
||||
public class PdfDictionary : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Dictionary; } }
|
||||
private Dictionary<string, IPdfElement> _values = new Dictionary<string, IPdfElement>();
|
||||
public Dictionary<string, IPdfElement> Values { get { return _values; } }
|
||||
|
||||
public string GetParamAsString(string name)
|
||||
{
|
||||
if (Values.ContainsKey(name) == false) { return null; }
|
||||
|
||||
IPdfElement value = Values[name];
|
||||
if (value is PdfArray)
|
||||
{
|
||||
value = ((PdfArray)value).Values[0];
|
||||
}
|
||||
if (value is PdfName)
|
||||
{
|
||||
return ((PdfName)value).Value;
|
||||
}
|
||||
if (value is PdfString)
|
||||
{
|
||||
return ((PdfString)value).Value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public long? GetParamAsInt(string name)
|
||||
{
|
||||
if (Values.ContainsKey(name) == false) { return null; }
|
||||
|
||||
IPdfElement value = Values[name];
|
||||
if (value is PdfArray)
|
||||
{
|
||||
value = ((PdfArray)value).Values[0];
|
||||
}
|
||||
if (value is PdfInteger)
|
||||
{
|
||||
return ((PdfInteger)value).Value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] GetParamAsStream(string name)
|
||||
{
|
||||
if (Values.ContainsKey(name) == false) { return null; }
|
||||
|
||||
IPdfElement value = Values[name];
|
||||
if (value is PdfArray)
|
||||
{
|
||||
PdfArray array = value as PdfArray;
|
||||
MemoryStream memStream = new MemoryStream();
|
||||
foreach (IPdfElement elem in array.Values)
|
||||
{
|
||||
PdfStream stream = elem as PdfStream;
|
||||
if (stream == null) { continue; }
|
||||
memStream.Write(stream.Data, 0, stream.Data.Length);
|
||||
}
|
||||
if (memStream.Length > 0)
|
||||
{
|
||||
return memStream.ToArray();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (value is PdfStream)
|
||||
{
|
||||
return ((PdfStream)value).Data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class PdfNull : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Null; } }
|
||||
}
|
||||
|
||||
public class PdfObjectReference : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.ObjectReference; } }
|
||||
public int ObjectID { get; set; }
|
||||
public int ObjectGeneration { get; set; }
|
||||
}
|
||||
|
||||
public class PdfStream : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Stream; } }
|
||||
public PdfDictionary Dictionary { get; set; }
|
||||
public byte[] Data { get; set; }
|
||||
|
||||
public byte[] OriginalData { get; set; }
|
||||
public IPdfElement OriginalFilter { get; set; }
|
||||
}
|
||||
|
||||
public class PdfObject : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Object; } }
|
||||
public int ObjectID { get; set; }
|
||||
public int ObjectGeneration { get; set; }
|
||||
public IPdfElement Data { get; set; }
|
||||
public int UsageCount { get; set; }
|
||||
}
|
||||
|
||||
public static class PdfElementUtils
|
||||
{
|
||||
public static double GetReal(IPdfElement elem, double defaultValue)
|
||||
{
|
||||
if (elem == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (elem is PdfInteger)
|
||||
{
|
||||
return ((PdfInteger)elem).Value;
|
||||
}
|
||||
if (elem is PdfReal)
|
||||
{
|
||||
return ((PdfReal)elem).Value;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
public static long GetInt(IPdfElement elem, long defaultValue)
|
||||
{
|
||||
if (elem == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (elem is PdfInteger)
|
||||
{
|
||||
return ((PdfInteger)elem).Value;
|
||||
}
|
||||
if (elem is PdfReal)
|
||||
{
|
||||
return (long)((PdfReal)elem).Value;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
7
VAR.PdfTools/PdfElements/IPdfElement.cs
Normal file
7
VAR.PdfTools/PdfElements/IPdfElement.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace VAR.PdfTools.PdfElements
|
||||
{
|
||||
public interface IPdfElement
|
||||
{
|
||||
PdfElementTypes Type { get; }
|
||||
}
|
||||
}
|
||||
11
VAR.PdfTools/PdfElements/PdfArray.cs
Normal file
11
VAR.PdfTools/PdfElements/PdfArray.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace VAR.PdfTools.PdfElements
|
||||
{
|
||||
public class PdfArray : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Array; } }
|
||||
private List<IPdfElement> _values = new List<IPdfElement>();
|
||||
public List<IPdfElement> Values { get { return _values; } }
|
||||
}
|
||||
}
|
||||
8
VAR.PdfTools/PdfElements/PdfBoolean.cs
Normal file
8
VAR.PdfTools/PdfElements/PdfBoolean.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace VAR.PdfTools.PdfElements
|
||||
{
|
||||
public class PdfBoolean : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Boolean; } }
|
||||
public bool Value { get; set; }
|
||||
}
|
||||
}
|
||||
77
VAR.PdfTools/PdfElements/PdfDictionary.cs
Normal file
77
VAR.PdfTools/PdfElements/PdfDictionary.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace VAR.PdfTools.PdfElements
|
||||
{
|
||||
public class PdfDictionary : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Dictionary; } }
|
||||
private Dictionary<string, IPdfElement> _values = new Dictionary<string, IPdfElement>();
|
||||
public Dictionary<string, IPdfElement> Values { get { return _values; } }
|
||||
|
||||
public string GetParamAsString(string name)
|
||||
{
|
||||
if (Values.ContainsKey(name) == false) { return null; }
|
||||
|
||||
IPdfElement value = Values[name];
|
||||
if (value is PdfArray)
|
||||
{
|
||||
value = ((PdfArray)value).Values[0];
|
||||
}
|
||||
if (value is PdfName)
|
||||
{
|
||||
return ((PdfName)value).Value;
|
||||
}
|
||||
if (value is PdfString)
|
||||
{
|
||||
return ((PdfString)value).Value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public long? GetParamAsInt(string name)
|
||||
{
|
||||
if (Values.ContainsKey(name) == false) { return null; }
|
||||
|
||||
IPdfElement value = Values[name];
|
||||
if (value is PdfArray)
|
||||
{
|
||||
value = ((PdfArray)value).Values[0];
|
||||
}
|
||||
if (value is PdfInteger)
|
||||
{
|
||||
return ((PdfInteger)value).Value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] GetParamAsStream(string name)
|
||||
{
|
||||
if (Values.ContainsKey(name) == false) { return null; }
|
||||
|
||||
IPdfElement value = Values[name];
|
||||
if (value is PdfArray)
|
||||
{
|
||||
PdfArray array = value as PdfArray;
|
||||
MemoryStream memStream = new MemoryStream();
|
||||
foreach (IPdfElement elem in array.Values)
|
||||
{
|
||||
PdfStream stream = elem as PdfStream;
|
||||
if (stream == null) { continue; }
|
||||
memStream.Write(stream.Data, 0, stream.Data.Length);
|
||||
}
|
||||
if (memStream.Length > 0)
|
||||
{
|
||||
return memStream.ToArray();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (value is PdfStream)
|
||||
{
|
||||
return ((PdfStream)value).Data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
18
VAR.PdfTools/PdfElements/PdfElementTypes.cs
Normal file
18
VAR.PdfTools/PdfElements/PdfElementTypes.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace VAR.PdfTools.PdfElements
|
||||
{
|
||||
public enum PdfElementTypes
|
||||
{
|
||||
Undefined,
|
||||
Boolean,
|
||||
Integer,
|
||||
Real,
|
||||
String,
|
||||
Name,
|
||||
Array,
|
||||
Dictionary,
|
||||
Null,
|
||||
ObjectReference,
|
||||
Object,
|
||||
Stream,
|
||||
};
|
||||
}
|
||||
56
VAR.PdfTools/PdfElements/PdfElementUtils.cs
Normal file
56
VAR.PdfTools/PdfElements/PdfElementUtils.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
namespace VAR.PdfTools.PdfElements
|
||||
{
|
||||
public static class PdfElementUtils
|
||||
{
|
||||
public static double GetReal(IPdfElement elem, double defaultValue)
|
||||
{
|
||||
if (elem == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (elem is PdfInteger)
|
||||
{
|
||||
return ((PdfInteger)elem).Value;
|
||||
}
|
||||
if (elem is PdfReal)
|
||||
{
|
||||
return ((PdfReal)elem).Value;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static long GetInt(IPdfElement elem, long defaultValue)
|
||||
{
|
||||
if (elem == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (elem is PdfInteger)
|
||||
{
|
||||
return ((PdfInteger)elem).Value;
|
||||
}
|
||||
if (elem is PdfReal)
|
||||
{
|
||||
return (long)((PdfReal)elem).Value;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static string GetString(IPdfElement elem, string defaultValue)
|
||||
{
|
||||
if (elem == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (elem is PdfString)
|
||||
{
|
||||
return ((PdfString)elem).Value;
|
||||
}
|
||||
if (elem is PdfName)
|
||||
{
|
||||
return ((PdfName)elem).Value;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
VAR.PdfTools/PdfElements/PdfInteger.cs
Normal file
8
VAR.PdfTools/PdfElements/PdfInteger.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace VAR.PdfTools.PdfElements
|
||||
{
|
||||
public class PdfInteger : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Integer; } }
|
||||
public long Value { get; set; }
|
||||
}
|
||||
}
|
||||
8
VAR.PdfTools/PdfElements/PdfName.cs
Normal file
8
VAR.PdfTools/PdfElements/PdfName.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace VAR.PdfTools.PdfElements
|
||||
{
|
||||
public class PdfName : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Name; } }
|
||||
public string Value { get; set; }
|
||||
}
|
||||
}
|
||||
7
VAR.PdfTools/PdfElements/PdfNull.cs
Normal file
7
VAR.PdfTools/PdfElements/PdfNull.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace VAR.PdfTools.PdfElements
|
||||
{
|
||||
public class PdfNull : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Null; } }
|
||||
}
|
||||
}
|
||||
11
VAR.PdfTools/PdfElements/PdfObject.cs
Normal file
11
VAR.PdfTools/PdfElements/PdfObject.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace VAR.PdfTools.PdfElements
|
||||
{
|
||||
public class PdfObject : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Object; } }
|
||||
public int ObjectID { get; set; }
|
||||
public int ObjectGeneration { get; set; }
|
||||
public IPdfElement Data { get; set; }
|
||||
public int UsageCount { get; set; }
|
||||
}
|
||||
}
|
||||
9
VAR.PdfTools/PdfElements/PdfObjectReference.cs
Normal file
9
VAR.PdfTools/PdfElements/PdfObjectReference.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace VAR.PdfTools.PdfElements
|
||||
{
|
||||
public class PdfObjectReference : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.ObjectReference; } }
|
||||
public int ObjectID { get; set; }
|
||||
public int ObjectGeneration { get; set; }
|
||||
}
|
||||
}
|
||||
8
VAR.PdfTools/PdfElements/PdfReal.cs
Normal file
8
VAR.PdfTools/PdfElements/PdfReal.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace VAR.PdfTools.PdfElements
|
||||
{
|
||||
public class PdfReal : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Real; } }
|
||||
public double Value { get; set; }
|
||||
}
|
||||
}
|
||||
12
VAR.PdfTools/PdfElements/PdfStream.cs
Normal file
12
VAR.PdfTools/PdfElements/PdfStream.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace VAR.PdfTools.PdfElements
|
||||
{
|
||||
public class PdfStream : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.Stream; } }
|
||||
public PdfDictionary Dictionary { get; set; }
|
||||
public byte[] Data { get; set; }
|
||||
|
||||
public byte[] OriginalData { get; set; }
|
||||
public IPdfElement OriginalFilter { get; set; }
|
||||
}
|
||||
}
|
||||
8
VAR.PdfTools/PdfElements/PdfString.cs
Normal file
8
VAR.PdfTools/PdfElements/PdfString.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace VAR.PdfTools.PdfElements
|
||||
{
|
||||
public class PdfString : IPdfElement
|
||||
{
|
||||
public PdfElementTypes Type { get { return PdfElementTypes.String; } }
|
||||
public string Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using VAR.PdfTools.PdfElements;
|
||||
|
||||
namespace VAR.PdfTools
|
||||
{
|
||||
@@ -45,6 +45,19 @@ namespace VAR.PdfTools
|
||||
_tainted = true;
|
||||
}
|
||||
|
||||
PrepareSizes(baseData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void PrepareSizes(PdfDictionary baseData)
|
||||
{
|
||||
// Set "Times-Roman" as default basefont sizes
|
||||
_widths = PdfStandar14FontMetrics.Times_Roman.Widths;
|
||||
_height = PdfStandar14FontMetrics.Times_Roman.ApproxHeight;
|
||||
|
||||
if (baseData.Values.ContainsKey("ToUnicode"))
|
||||
{
|
||||
byte[] toUnicodeStream = ((PdfStream)baseData.Values["ToUnicode"]).Data;
|
||||
@@ -52,7 +65,19 @@ namespace VAR.PdfTools
|
||||
_toUnicode = parser.ParseToUnicode();
|
||||
}
|
||||
|
||||
string baseFont = _baseData.GetParamAsString("BaseFont");
|
||||
if (string.IsNullOrEmpty(baseFont))
|
||||
{
|
||||
SetBaseFontSizes(baseFont);
|
||||
}
|
||||
|
||||
if (_baseData.Values.ContainsKey("FirstChar") && _baseData.Values.ContainsKey("LastChar") && _baseData.Values.ContainsKey("Widths"))
|
||||
{
|
||||
ParseSizes();
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseSizes()
|
||||
{
|
||||
double glyphSpaceToTextSpace = 1000.0; // FIXME: SubType:Type3 Uses a FontMatrix that may not correspond to 1/1000th
|
||||
_widths = new Dictionary<char, double>();
|
||||
@@ -62,26 +87,16 @@ namespace VAR.PdfTools
|
||||
char actualChar = firstChar;
|
||||
foreach (IPdfElement elem in widths.Values)
|
||||
{
|
||||
PdfReal widthReal = elem as PdfReal;
|
||||
if (widthReal != null)
|
||||
{
|
||||
_widths.Add(actualChar, widthReal.Value / glyphSpaceToTextSpace);
|
||||
double width = PdfElementUtils.GetReal(elem, 500);
|
||||
if (width < 0.0001f && width > -0.0001f) { width = 500; }
|
||||
_widths.Add(actualChar, width / glyphSpaceToTextSpace);
|
||||
actualChar++;
|
||||
continue;
|
||||
}
|
||||
PdfInteger widthInt = elem as PdfInteger;
|
||||
if (widthInt != null)
|
||||
{
|
||||
_widths.Add(actualChar, widthInt.Value / glyphSpaceToTextSpace);
|
||||
actualChar++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// FIMXE: Calculate real height
|
||||
}
|
||||
else
|
||||
|
||||
private void SetBaseFontSizes(string baseFont)
|
||||
{
|
||||
string baseFont = _baseData.GetParamAsString("BaseFont");
|
||||
if (baseFont == "Times-Roman")
|
||||
{
|
||||
_widths = PdfStandar14FontMetrics.Times_Roman.Widths;
|
||||
@@ -153,7 +168,6 @@ namespace VAR.PdfTools
|
||||
_height = PdfStandar14FontMetrics.ZapfDingbats.ApproxHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -177,15 +191,23 @@ namespace VAR.PdfTools
|
||||
|
||||
public double GetCharWidth(char character)
|
||||
{
|
||||
double charWidth = 0;
|
||||
if (_widths == null)
|
||||
{
|
||||
return 0;
|
||||
return charWidth;
|
||||
}
|
||||
if (_widths.ContainsKey(character))
|
||||
{
|
||||
return _widths[character];
|
||||
charWidth = _widths[character];
|
||||
}
|
||||
return 0;
|
||||
|
||||
// NOTE: Convert "Zero" to default width of 0.5
|
||||
if (charWidth <= 0.0001)
|
||||
{
|
||||
charWidth = 0.5;
|
||||
}
|
||||
|
||||
return charWidth;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using VAR.PdfTools.PdfElements;
|
||||
|
||||
namespace VAR.PdfTools
|
||||
{
|
||||
|
||||
@@ -2,155 +2,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using VAR.PdfTools.Maths;
|
||||
using VAR.PdfTools.PdfElements;
|
||||
|
||||
namespace VAR.PdfTools
|
||||
{
|
||||
public class Vector3D
|
||||
public struct PdfCharElement
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
public double[] _vector = new double[3];
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public double[] Vector { get { return _vector; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Creator
|
||||
|
||||
public Vector3D()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
_vector[0] = 0.0;
|
||||
_vector[1] = 0.0;
|
||||
_vector[2] = 1.0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class Matrix3x3
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
public double[,] _matrix = new double[3, 3];
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public double[,] Matrix { get { return _matrix; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Creator
|
||||
|
||||
public Matrix3x3()
|
||||
{
|
||||
Idenity();
|
||||
}
|
||||
|
||||
public Matrix3x3(double a, double b, double c, double d, double e, double f)
|
||||
{
|
||||
Set(a, b, c, d, e, f);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
||||
public void Idenity()
|
||||
{
|
||||
_matrix[0, 0] = 1.0;
|
||||
_matrix[0, 1] = 0.0;
|
||||
_matrix[0, 2] = 0.0;
|
||||
_matrix[1, 0] = 0.0;
|
||||
_matrix[1, 1] = 1.0;
|
||||
_matrix[1, 2] = 0.0;
|
||||
_matrix[2, 0] = 0.0;
|
||||
_matrix[2, 1] = 0.0;
|
||||
_matrix[2, 2] = 1.0;
|
||||
}
|
||||
|
||||
public void Set(double a, double b, double c, double d, double e, double f)
|
||||
{
|
||||
_matrix[0, 0] = a;
|
||||
_matrix[1, 0] = b;
|
||||
_matrix[2, 0] = 0;
|
||||
_matrix[0, 1] = c;
|
||||
_matrix[1, 1] = d;
|
||||
_matrix[2, 1] = 0;
|
||||
_matrix[0, 2] = e;
|
||||
_matrix[1, 2] = f;
|
||||
_matrix[2, 2] = 1;
|
||||
}
|
||||
|
||||
public Vector3D Multiply(Vector3D vect)
|
||||
{
|
||||
Vector3D vectResult = new Vector3D();
|
||||
|
||||
vectResult.Vector[0] = (vect.Vector[0] * _matrix[0, 0]) + (vect.Vector[1] * _matrix[0, 1]) + (vect.Vector[2] * _matrix[0, 2]);
|
||||
vectResult.Vector[1] = (vect.Vector[0] * _matrix[1, 0]) + (vect.Vector[1] * _matrix[1, 1]) + (vect.Vector[2] * _matrix[1, 2]);
|
||||
vectResult.Vector[2] = (vect.Vector[0] * _matrix[2, 0]) + (vect.Vector[1] * _matrix[2, 1]) + (vect.Vector[2] * _matrix[2, 2]);
|
||||
|
||||
return vectResult;
|
||||
}
|
||||
|
||||
public Matrix3x3 Multiply(Matrix3x3 matrix)
|
||||
{
|
||||
Matrix3x3 newMatrix = new Matrix3x3();
|
||||
|
||||
newMatrix._matrix[0, 0] = (_matrix[0, 0] * matrix._matrix[0, 0]) + (_matrix[1, 0] * matrix._matrix[0, 1]) + (_matrix[2, 0] * matrix._matrix[0, 2]);
|
||||
newMatrix._matrix[0, 1] = (_matrix[0, 1] * matrix._matrix[0, 0]) + (_matrix[1, 1] * matrix._matrix[0, 1]) + (_matrix[2, 1] * matrix._matrix[0, 2]);
|
||||
newMatrix._matrix[0, 2] = (_matrix[0, 2] * matrix._matrix[0, 0]) + (_matrix[1, 2] * matrix._matrix[0, 1]) + (_matrix[2, 2] * matrix._matrix[0, 2]);
|
||||
newMatrix._matrix[1, 0] = (_matrix[0, 0] * matrix._matrix[1, 0]) + (_matrix[1, 0] * matrix._matrix[1, 1]) + (_matrix[2, 0] * matrix._matrix[1, 2]);
|
||||
newMatrix._matrix[1, 1] = (_matrix[0, 1] * matrix._matrix[1, 0]) + (_matrix[1, 1] * matrix._matrix[1, 1]) + (_matrix[2, 1] * matrix._matrix[1, 2]);
|
||||
newMatrix._matrix[1, 2] = (_matrix[0, 2] * matrix._matrix[1, 0]) + (_matrix[1, 2] * matrix._matrix[1, 1]) + (_matrix[2, 2] * matrix._matrix[1, 2]);
|
||||
newMatrix._matrix[2, 0] = (_matrix[0, 0] * matrix._matrix[2, 0]) + (_matrix[1, 0] * matrix._matrix[2, 1]) + (_matrix[2, 0] * matrix._matrix[2, 2]);
|
||||
newMatrix._matrix[2, 1] = (_matrix[0, 1] * matrix._matrix[2, 0]) + (_matrix[1, 1] * matrix._matrix[2, 1]) + (_matrix[2, 1] * matrix._matrix[2, 2]);
|
||||
newMatrix._matrix[2, 2] = (_matrix[0, 2] * matrix._matrix[2, 0]) + (_matrix[1, 2] * matrix._matrix[2, 1]) + (_matrix[2, 2] * matrix._matrix[2, 2]);
|
||||
|
||||
return newMatrix;
|
||||
}
|
||||
|
||||
public Matrix3x3 Copy()
|
||||
{
|
||||
Matrix3x3 newMatrix = new Matrix3x3();
|
||||
|
||||
newMatrix._matrix[0, 0] = _matrix[0, 0];
|
||||
newMatrix._matrix[0, 1] = _matrix[0, 1];
|
||||
newMatrix._matrix[0, 2] = _matrix[0, 2];
|
||||
newMatrix._matrix[1, 0] = _matrix[1, 0];
|
||||
newMatrix._matrix[1, 1] = _matrix[1, 1];
|
||||
newMatrix._matrix[1, 2] = _matrix[1, 2];
|
||||
newMatrix._matrix[2, 0] = _matrix[2, 0];
|
||||
newMatrix._matrix[2, 1] = _matrix[2, 1];
|
||||
newMatrix._matrix[2, 2] = _matrix[2, 2];
|
||||
|
||||
return newMatrix;
|
||||
}
|
||||
|
||||
public bool IsCollinear(Matrix3x3 otherMatrix, double horizontalDelta = 0.00001, double verticalDelta = 0.00001)
|
||||
{
|
||||
double epsilon = 0.00001;
|
||||
return (
|
||||
Math.Abs(_matrix[0, 0] - otherMatrix.Matrix[0, 0]) <= epsilon &&
|
||||
Math.Abs(_matrix[1, 0] - otherMatrix.Matrix[1, 0]) <= epsilon &&
|
||||
Math.Abs(_matrix[0, 1] - otherMatrix.Matrix[0, 1]) <= epsilon &&
|
||||
Math.Abs(_matrix[1, 1] - otherMatrix.Matrix[1, 1]) <= epsilon &&
|
||||
Math.Abs(_matrix[0, 2] - otherMatrix.Matrix[0, 2]) <= horizontalDelta &&
|
||||
Math.Abs(_matrix[1, 2] - otherMatrix.Matrix[1, 2]) <= verticalDelta &&
|
||||
true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
public string Char;
|
||||
public double Displacement;
|
||||
public double Width;
|
||||
}
|
||||
|
||||
public class PdfTextElement
|
||||
@@ -171,8 +32,9 @@ namespace VAR.PdfTools
|
||||
|
||||
public double VisibleHeight { get; set; }
|
||||
|
||||
private List<PdfTextElement> _childs = new List<PdfTextElement>();
|
||||
public List<PdfTextElement> Childs { get { return _childs; } }
|
||||
public List<PdfCharElement> Characters { get; set; }
|
||||
|
||||
public List<PdfTextElement> Childs { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -188,6 +50,41 @@ namespace VAR.PdfTools
|
||||
return Matrix.Matrix[1, 2];
|
||||
}
|
||||
|
||||
public PdfTextElement SubPart(int startIndex, int endIndex)
|
||||
{
|
||||
PdfTextElement blockElem = new PdfTextElement
|
||||
{
|
||||
Font = null,
|
||||
FontSize = FontSize,
|
||||
Matrix = Matrix.Copy(),
|
||||
RawText = RawText.Substring(startIndex, endIndex - startIndex),
|
||||
VisibleText = VisibleText.Substring(startIndex, endIndex - startIndex),
|
||||
VisibleWidth = 0,
|
||||
VisibleHeight = VisibleHeight,
|
||||
Characters = new List<PdfCharElement>(),
|
||||
Childs = new List<PdfTextElement>(),
|
||||
};
|
||||
double displacement = Characters[startIndex].Displacement;
|
||||
blockElem.Matrix.Matrix[0, 2] += displacement;
|
||||
for (int j = startIndex; j < endIndex; j++)
|
||||
{
|
||||
blockElem.Characters.Add(new PdfCharElement
|
||||
{
|
||||
Char = Characters[j].Char,
|
||||
Displacement = Characters[j].Displacement - displacement,
|
||||
Width = Characters[j].Width,
|
||||
});
|
||||
}
|
||||
PdfCharElement lastChar = blockElem.Characters[blockElem.Characters.Count - 1];
|
||||
blockElem.VisibleWidth = lastChar.Displacement + lastChar.Width;
|
||||
foreach (PdfTextElement elem in Childs)
|
||||
{
|
||||
blockElem.Childs.Add(elem);
|
||||
}
|
||||
|
||||
return blockElem;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -206,15 +103,17 @@ namespace VAR.PdfTools
|
||||
// Text state
|
||||
private PdfFont _font = null;
|
||||
private double _fontSize = 1;
|
||||
private double _charSpacing = 0;
|
||||
private double _wordSpacing = 0;
|
||||
private double _textLeading = 0;
|
||||
|
||||
// Text object state
|
||||
private bool inText = false;
|
||||
private Matrix3x3 _textMatrix = new Matrix3x3();
|
||||
private Matrix3x3 _textMatrixCurrent = new Matrix3x3();
|
||||
private StringBuilder _sbText = new StringBuilder();
|
||||
private double _textWidth = 0;
|
||||
|
||||
PdfTextElement _currentTextElement = null;
|
||||
private List<PdfCharElement> _listCharacters = new List<PdfCharElement>();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -231,7 +130,9 @@ namespace VAR.PdfTools
|
||||
public PdfTextExtractor(PdfDocumentPage page)
|
||||
{
|
||||
_page = page;
|
||||
ProcessPage();
|
||||
ProcessPageContent();
|
||||
JoinTextElements();
|
||||
SplitTextElements();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -258,42 +159,26 @@ namespace VAR.PdfTools
|
||||
PdfTextElement textElem = new PdfTextElement();
|
||||
textElem.Font = _font;
|
||||
textElem.FontSize = _fontSize;
|
||||
textElem.Matrix = _textMatrix.Multiply(_graphicsMatrix);
|
||||
textElem.Matrix = _textMatrixCurrent.Multiply(_graphicsMatrix);
|
||||
textElem.RawText = _sbText.ToString();
|
||||
textElem.VisibleText = PdfString_ToUnicode(textElem.RawText, _font);
|
||||
textElem.VisibleWidth = _textWidth * textElem.Matrix.Matrix[0, 0];
|
||||
PdfCharElement lastChar = _listCharacters[_listCharacters.Count - 1];
|
||||
textElem.VisibleWidth = (lastChar.Displacement + lastChar.Width) * textElem.Matrix.Matrix[0, 0];
|
||||
textElem.VisibleHeight = (_font.Height * _fontSize) * textElem.Matrix.Matrix[1, 1];
|
||||
textElem.Characters = new List<PdfCharElement>();
|
||||
foreach (PdfCharElement c in _listCharacters)
|
||||
{
|
||||
textElem.Characters.Add(new PdfCharElement
|
||||
{
|
||||
Char = c.Char,
|
||||
Displacement = (c.Displacement * textElem.Matrix.Matrix[0, 0]),
|
||||
Width = (c.Width * textElem.Matrix.Matrix[0, 0]),
|
||||
});
|
||||
}
|
||||
textElem.Childs = new List<PdfTextElement>();
|
||||
return textElem;
|
||||
}
|
||||
|
||||
private void FlushTextElementSoft()
|
||||
{
|
||||
if (_sbText.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PdfTextElement textElem = BuildTextElement();
|
||||
if (_currentTextElement == null)
|
||||
{
|
||||
_currentTextElement = new PdfTextElement();
|
||||
_currentTextElement.Font = null;
|
||||
_currentTextElement.FontSize = -1;
|
||||
_currentTextElement.Matrix = textElem.Matrix.Copy();
|
||||
_currentTextElement.RawText = string.Empty;
|
||||
_currentTextElement.VisibleText = string.Empty;
|
||||
_currentTextElement.VisibleWidth = 0;
|
||||
_currentTextElement.VisibleHeight = 0;
|
||||
}
|
||||
_currentTextElement.VisibleText += textElem.VisibleText;
|
||||
_currentTextElement.VisibleWidth += textElem.VisibleWidth;
|
||||
_currentTextElement.VisibleHeight = System.Math.Max(_currentTextElement.VisibleHeight, textElem.VisibleHeight);
|
||||
_currentTextElement.Childs.Add(textElem);
|
||||
|
||||
_sbText = new StringBuilder();
|
||||
_textWidth = 0;
|
||||
}
|
||||
|
||||
private void AddTextElement(PdfTextElement textElement)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textElement.VisibleText.Trim()))
|
||||
@@ -307,27 +192,16 @@ namespace VAR.PdfTools
|
||||
{
|
||||
if (_sbText.Length == 0)
|
||||
{
|
||||
if (_currentTextElement != null)
|
||||
{
|
||||
AddTextElement(_currentTextElement);
|
||||
_currentTextElement = null;
|
||||
}
|
||||
_textWidth = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentTextElement != null)
|
||||
{
|
||||
FlushTextElementSoft();
|
||||
AddTextElement(_currentTextElement);
|
||||
_currentTextElement = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
PdfTextElement textElem = BuildTextElement();
|
||||
AddTextElement(textElem);
|
||||
}
|
||||
|
||||
_textMatrixCurrent.Matrix[0, 2] += _textWidth;
|
||||
|
||||
_sbText = new StringBuilder();
|
||||
_listCharacters.Clear();
|
||||
_textWidth = 0;
|
||||
}
|
||||
|
||||
@@ -362,6 +236,21 @@ namespace VAR.PdfTools
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<PdfTextElement> FindElementsContainingText(string text, bool fuzzy)
|
||||
{
|
||||
List<PdfTextElement> list = new List<PdfTextElement>();
|
||||
string matchingText = fuzzy ? SimplifyText(text) : text;
|
||||
foreach (PdfTextElement elem in _textElements)
|
||||
{
|
||||
string elemText = fuzzy ? SimplifyText(elem.VisibleText) : elem.VisibleText;
|
||||
if (elemText.Contains(matchingText))
|
||||
{
|
||||
list.Add(elem);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private bool TextElementVerticalIntersection(PdfTextElement elem1, PdfTextElement elem2)
|
||||
{
|
||||
double elem1X1 = elem1.GetX();
|
||||
@@ -391,36 +280,47 @@ namespace VAR.PdfTools
|
||||
_graphicsMatrixStack.Add(_graphicsMatrix.Copy());
|
||||
}
|
||||
|
||||
private void OpSetGraphMatrix(double a, double b, double c, double d, double e, double f)
|
||||
{
|
||||
_graphicsMatrix.Set(a, b, c, d, e, f);
|
||||
}
|
||||
|
||||
private void OpPopGraphState()
|
||||
{
|
||||
_graphicsMatrix = _graphicsMatrixStack[_graphicsMatrixStack.Count - 1];
|
||||
_graphicsMatrixStack.RemoveAt(_graphicsMatrixStack.Count - 1);
|
||||
}
|
||||
|
||||
private void OpSetGraphMatrix(double a, double b, double c, double d, double e, double f)
|
||||
{
|
||||
_graphicsMatrix.Set(a, b, c, d, e, f);
|
||||
}
|
||||
|
||||
private void OpBeginText()
|
||||
{
|
||||
_textMatrix.Idenity();
|
||||
_textMatrixCurrent.Idenity();
|
||||
inText = true;
|
||||
}
|
||||
|
||||
private void OpEndText()
|
||||
{
|
||||
FlushTextElementSoft();
|
||||
FlushTextElement();
|
||||
inText = false;
|
||||
}
|
||||
|
||||
private void OpTextFont(string fontName, double size)
|
||||
{
|
||||
FlushTextElementSoft();
|
||||
FlushTextElement();
|
||||
_font = _page.Fonts[fontName];
|
||||
_fontSize = size;
|
||||
}
|
||||
|
||||
private void OpTextCharSpacing(double charSpacing)
|
||||
{
|
||||
_charSpacing = charSpacing;
|
||||
}
|
||||
|
||||
private void OpTextWordSpacing(double wordSpacing)
|
||||
{
|
||||
_wordSpacing = wordSpacing;
|
||||
}
|
||||
|
||||
private void OpTextLeading(double textLeading)
|
||||
{
|
||||
_textLeading = textLeading;
|
||||
@@ -433,6 +333,7 @@ namespace VAR.PdfTools
|
||||
newMatrix.Matrix[0, 2] = x;
|
||||
newMatrix.Matrix[1, 2] = y;
|
||||
_textMatrix = newMatrix.Multiply(_textMatrix);
|
||||
_textMatrixCurrent = _textMatrix.Copy();
|
||||
}
|
||||
|
||||
private void OpTextLineFeed()
|
||||
@@ -442,35 +343,10 @@ namespace VAR.PdfTools
|
||||
|
||||
private void OpSetTextMatrix(double a, double b, double c, double d, double e, double f)
|
||||
{
|
||||
double halfSpaceWidth = 0;
|
||||
double horizontalDelta = 0;
|
||||
Matrix3x3 newMatrix = new Matrix3x3(a, b, c, d, e, f);
|
||||
|
||||
if (_font != null)
|
||||
{
|
||||
halfSpaceWidth = _font.GetCharWidth(' ') * _fontSize;
|
||||
}
|
||||
horizontalDelta = (_textWidth + halfSpaceWidth);
|
||||
if (_textMatrix.IsCollinear(newMatrix, horizontalDelta: horizontalDelta))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_currentTextElement != null)
|
||||
{
|
||||
if (_currentTextElement.Font != null)
|
||||
{
|
||||
halfSpaceWidth = _currentTextElement.Font.GetCharWidth(' ') * _currentTextElement.FontSize;
|
||||
}
|
||||
horizontalDelta = (_currentTextElement.VisibleWidth + halfSpaceWidth);
|
||||
if (_currentTextElement.Matrix.IsCollinear(newMatrix, horizontalDelta: horizontalDelta))
|
||||
{
|
||||
FlushTextElementSoft();
|
||||
_textMatrix = newMatrix;
|
||||
return;
|
||||
}
|
||||
}
|
||||
FlushTextElement();
|
||||
_textMatrix = newMatrix;
|
||||
_textMatrixCurrent = _textMatrix.Copy();
|
||||
}
|
||||
|
||||
private void OpTextPut(string text)
|
||||
@@ -481,7 +357,12 @@ namespace VAR.PdfTools
|
||||
{
|
||||
foreach (char c in text)
|
||||
{
|
||||
_textWidth += _font.GetCharWidth(c) * _fontSize;
|
||||
string realChar = _font.ToUnicode(c);
|
||||
if (realChar == "\0") { continue; }
|
||||
double charWidth = _font.GetCharWidth(c) * _fontSize;
|
||||
_listCharacters.Add(new PdfCharElement { Char = _font.ToUnicode(c), Displacement = _textWidth, Width = charWidth });
|
||||
_textWidth += charWidth;
|
||||
_textWidth += ((c == 0x20) ? _wordSpacing : _charSpacing);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -498,8 +379,7 @@ namespace VAR.PdfTools
|
||||
else if (elem is PdfInteger || elem is PdfReal)
|
||||
{
|
||||
double spacing = PdfElementUtils.GetReal(elem, 0);
|
||||
// FIXME: Apply correctly spacing
|
||||
//_textWidth += spacing;
|
||||
_textWidth -= (spacing / 1000) * _fontSize;
|
||||
}
|
||||
else if (elem is PdfArray)
|
||||
{
|
||||
@@ -512,13 +392,17 @@ namespace VAR.PdfTools
|
||||
|
||||
#region Private methods
|
||||
|
||||
private void ProcessPage()
|
||||
private void ProcessPageContent()
|
||||
{
|
||||
int unknowCount = 0;
|
||||
int lineCount = 0;
|
||||
int strokeCount = 0;
|
||||
int pathCount = 0;
|
||||
for (int i = 0; i < _page.ContentActions.Count; i++)
|
||||
{
|
||||
PdfContentAction action = _page.ContentActions[i];
|
||||
// Graphics Operations
|
||||
|
||||
// Special graphics state
|
||||
if (action.Token == "q")
|
||||
{
|
||||
OpPushGraphState();
|
||||
@@ -549,11 +433,13 @@ namespace VAR.PdfTools
|
||||
}
|
||||
else if (action.Token == "Tc")
|
||||
{
|
||||
// FIXME: Char spacing
|
||||
double charSpacing = PdfElementUtils.GetReal(action.Parameters[0], 0);
|
||||
OpTextCharSpacing(charSpacing);
|
||||
}
|
||||
else if (action.Token == "Tw")
|
||||
{
|
||||
// FIXME: Word spacing
|
||||
double wordSpacing = PdfElementUtils.GetReal(action.Parameters[0], 0);
|
||||
OpTextWordSpacing(wordSpacing);
|
||||
}
|
||||
else if (action.Token == "Tz")
|
||||
{
|
||||
@@ -561,7 +447,7 @@ namespace VAR.PdfTools
|
||||
}
|
||||
else if (action.Token == "Tf")
|
||||
{
|
||||
string fontName = ((PdfName)action.Parameters[0]).Value;
|
||||
string fontName = PdfElementUtils.GetString(action.Parameters[0], string.Empty);
|
||||
double fontSize = PdfElementUtils.GetReal(action.Parameters[1], 0);
|
||||
OpTextFont(fontName, fontSize);
|
||||
}
|
||||
@@ -607,18 +493,23 @@ namespace VAR.PdfTools
|
||||
}
|
||||
else if (action.Token == "Tj")
|
||||
{
|
||||
OpTextPut(((PdfString)action.Parameters[0]).Value);
|
||||
string text = PdfElementUtils.GetString(action.Parameters[0], string.Empty);
|
||||
OpTextPut(text);
|
||||
}
|
||||
else if (action.Token == "'")
|
||||
{
|
||||
string text = PdfElementUtils.GetString(action.Parameters[0], string.Empty);
|
||||
OpTextLineFeed();
|
||||
OpTextPut(((PdfString)action.Parameters[0]).Value);
|
||||
OpTextPut(text);
|
||||
}
|
||||
else if (action.Token == "\"")
|
||||
{
|
||||
double wordSpacing = PdfElementUtils.GetReal(action.Parameters[0], 0);
|
||||
double charSpacing = PdfElementUtils.GetReal(action.Parameters[1], 0);
|
||||
OpTextPut(((PdfString)action.Parameters[2]).Value);
|
||||
string text = PdfElementUtils.GetString(action.Parameters[0], string.Empty);
|
||||
OpTextCharSpacing(charSpacing);
|
||||
OpTextWordSpacing(wordSpacing);
|
||||
OpTextPut(text);
|
||||
}
|
||||
else if (action.Token == "TJ")
|
||||
{
|
||||
@@ -664,6 +555,45 @@ namespace VAR.PdfTools
|
||||
{
|
||||
// FIXME: Interpret this
|
||||
}
|
||||
else if (action.Token == "m")
|
||||
{
|
||||
// FIXME: Interpret this "moveto: Begin new subpath"
|
||||
}
|
||||
else if (action.Token == "l")
|
||||
{
|
||||
// FIXME: Interpret this "lineto: Append straight line segment to path"
|
||||
lineCount++;
|
||||
}
|
||||
else if (action.Token == "h")
|
||||
{
|
||||
// FIXME: Interpret this "closepath: Close subpath"
|
||||
pathCount++;
|
||||
}
|
||||
else if (action.Token == "W")
|
||||
{
|
||||
// FIXME: Interpret this "clip: Set clipping path using nonzero winding number rule"
|
||||
}
|
||||
else if (action.Token == "W*")
|
||||
{
|
||||
// FIXME: Interpret this "eoclip: Set clipping path using even-odd rule"
|
||||
}
|
||||
else if (action.Token == "w")
|
||||
{
|
||||
// FIXME: Interpret this "setlinewidth: Set line width"
|
||||
}
|
||||
else if (action.Token == "G")
|
||||
{
|
||||
// FIXME: Interpret this "setgray: Set gray level for stroking operations"
|
||||
}
|
||||
else if (action.Token == "S")
|
||||
{
|
||||
// FIXME: Interpret this "stroke: Stroke path"
|
||||
strokeCount++;
|
||||
}
|
||||
else if (action.Token == "M")
|
||||
{
|
||||
// FIXME: Interpret this "setmiterlimit: Set miter limit"
|
||||
}
|
||||
else
|
||||
{
|
||||
unknowCount++;
|
||||
@@ -672,6 +602,126 @@ namespace VAR.PdfTools
|
||||
FlushTextElement();
|
||||
}
|
||||
|
||||
private void JoinTextElements()
|
||||
{
|
||||
var textElementsCondensed = new List<PdfTextElement>();
|
||||
while (_textElements.Count > 0)
|
||||
{
|
||||
PdfTextElement elem = _textElements[0];
|
||||
_textElements.Remove(elem);
|
||||
double blockY = elem.GetY();
|
||||
double blockXMin = elem.GetX();
|
||||
double blockXMax = blockXMin + elem.VisibleWidth;
|
||||
|
||||
// Prepare first neighbour
|
||||
var textElementNeighbours = new List<PdfTextElement>();
|
||||
textElementNeighbours.Add(elem);
|
||||
|
||||
// Search Neighbours
|
||||
int i = 0;
|
||||
while (i < _textElements.Count)
|
||||
{
|
||||
PdfTextElement neighbour = _textElements[i];
|
||||
double neighbourY = neighbour.GetY();
|
||||
if (Math.Abs(neighbourY - blockY) > 0.001) { i++; continue; }
|
||||
|
||||
double maxWidth = neighbour.Characters.Max(c => c.Width);
|
||||
|
||||
double neighbourXMin = neighbour.GetX();
|
||||
double neighbourXMax = neighbourXMin + neighbour.VisibleWidth;
|
||||
double auxBlockXMin = blockXMin - maxWidth;
|
||||
double auxBlockXMax = blockXMax + maxWidth;
|
||||
if (auxBlockXMax >= neighbourXMin && neighbourXMax >= auxBlockXMin)
|
||||
{
|
||||
_textElements.Remove(neighbour);
|
||||
textElementNeighbours.Add(neighbour);
|
||||
if (blockXMax < neighbourXMax) { blockXMax = neighbourXMax; }
|
||||
if (blockXMin > neighbourXMin) { blockXMin = neighbourXMin; }
|
||||
i = 0;
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if(textElementNeighbours.Count == 0)
|
||||
{
|
||||
textElementsCondensed.Add(elem);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Join neighbours
|
||||
var chars = new List<PdfCharElement>();
|
||||
foreach (PdfTextElement neighbour in textElementNeighbours)
|
||||
{
|
||||
double neighbourXMin = neighbour.GetX();
|
||||
foreach(PdfCharElement c in neighbour.Characters)
|
||||
{
|
||||
chars.Add(new PdfCharElement
|
||||
{
|
||||
Char = c.Char,
|
||||
Displacement = (c.Displacement + neighbourXMin) - blockXMin,
|
||||
Width = c.Width,
|
||||
});
|
||||
}
|
||||
}
|
||||
chars = chars.OrderBy(c => c.Displacement).ToList();
|
||||
var sbText = new StringBuilder();
|
||||
foreach(PdfCharElement c in chars)
|
||||
{
|
||||
sbText.Append(c.Char);
|
||||
}
|
||||
PdfTextElement blockElem = new PdfTextElement
|
||||
{
|
||||
Font = null,
|
||||
FontSize = elem.FontSize,
|
||||
Matrix = elem.Matrix.Copy(),
|
||||
RawText = sbText.ToString(),
|
||||
VisibleText = sbText.ToString(),
|
||||
VisibleWidth = blockXMax - blockXMin,
|
||||
VisibleHeight = elem.VisibleHeight,
|
||||
Characters = chars,
|
||||
Childs = textElementNeighbours,
|
||||
};
|
||||
blockElem.Matrix.Matrix[0, 2] = blockXMin;
|
||||
textElementsCondensed.Add(blockElem);
|
||||
}
|
||||
_textElements = textElementsCondensed;
|
||||
}
|
||||
|
||||
private void SplitTextElements()
|
||||
{
|
||||
var textElementsSplitted = new List<PdfTextElement>();
|
||||
while (_textElements.Count > 0)
|
||||
{
|
||||
PdfTextElement elem = _textElements[0];
|
||||
_textElements.Remove(elem);
|
||||
|
||||
double maxWidth = elem.Characters.Max(c => c.Width);
|
||||
|
||||
int prevBreak = 0;
|
||||
for (int i = 1; i < elem.Characters.Count; i++)
|
||||
{
|
||||
double prevCharEnd = elem.Characters[i - 1].Displacement + elem.Characters[i - 1].Width;
|
||||
double charSeparation = elem.Characters[i].Displacement - prevCharEnd;
|
||||
if (charSeparation > maxWidth)
|
||||
{
|
||||
PdfTextElement partElem = elem.SubPart(prevBreak, i);
|
||||
textElementsSplitted.Add(partElem);
|
||||
prevBreak = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (prevBreak == 0)
|
||||
{
|
||||
textElementsSplitted.Add(elem);
|
||||
continue;
|
||||
}
|
||||
PdfTextElement lastElem = elem.SubPart(prevBreak, elem.Characters.Count);
|
||||
textElementsSplitted.Add(lastElem);
|
||||
}
|
||||
_textElements = textElementsSplitted;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
@@ -793,12 +843,8 @@ namespace VAR.PdfTools
|
||||
|
||||
public bool HasText(string text, bool fuzzy)
|
||||
{
|
||||
PdfTextElement fieldTitle = FindElementByText(text, fuzzy);
|
||||
if (fieldTitle == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
List<PdfTextElement> list = FindElementsContainingText(text, fuzzy);
|
||||
return (list.Count > 0);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -11,4 +11,4 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("eb7e003a-6a95-4002-809f-926c7c8a11e9")]
|
||||
[assembly: AssemblyVersion("1.2.*")]
|
||||
[assembly: AssemblyVersion("1.5.1.*")]
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{EB7E003A-6A95-4002-809F-926C7C8A11E9}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>VAR.PdfTools</RootNamespace>
|
||||
<AssemblyName>VAR.PdfTools</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<ProductVersion>10.0.0</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="PdfContentAction.cs" />
|
||||
<Compile Include="PdfDocument.cs" />
|
||||
<Compile Include="PdfDocumentPage.cs" />
|
||||
<Compile Include="PdfElements.cs" />
|
||||
<Compile Include="PdfFilters.cs" />
|
||||
<Compile Include="PdfFont.cs" />
|
||||
<Compile Include="PdfParser.cs" />
|
||||
<Compile Include="PdfStandar14FontMetrics.cs" />
|
||||
<Compile Include="PdfTextExtractor.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -60,16 +60,31 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Maths\Matrix3x3.cs" />
|
||||
<Compile Include="PdfContentAction.cs" />
|
||||
<Compile Include="PdfDocument.cs" />
|
||||
<Compile Include="PdfDocumentPage.cs" />
|
||||
<Compile Include="PdfElements.cs" />
|
||||
<Compile Include="PdfElements\IPdfElement.cs" />
|
||||
<Compile Include="PdfElements\PdfArray.cs" />
|
||||
<Compile Include="PdfElements\PdfBoolean.cs" />
|
||||
<Compile Include="PdfElements\PdfDictionary.cs" />
|
||||
<Compile Include="PdfElements\PdfElementTypes.cs" />
|
||||
<Compile Include="PdfElements\PdfElementUtils.cs" />
|
||||
<Compile Include="PdfFilters.cs" />
|
||||
<Compile Include="PdfFont.cs" />
|
||||
<Compile Include="PdfElements\PdfInteger.cs" />
|
||||
<Compile Include="PdfElements\PdfName.cs" />
|
||||
<Compile Include="PdfElements\PdfNull.cs" />
|
||||
<Compile Include="PdfElements\PdfObject.cs" />
|
||||
<Compile Include="PdfElements\PdfObjectReference.cs" />
|
||||
<Compile Include="PdfElements\PdfReal.cs" />
|
||||
<Compile Include="PdfElements\PdfStream.cs" />
|
||||
<Compile Include="PdfElements\PdfString.cs" />
|
||||
<Compile Include="PdfParser.cs" />
|
||||
<Compile Include="PdfStandar14FontMetrics.cs" />
|
||||
<Compile Include="PdfTextExtractor.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Maths\Vector3D.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="NuGet\keep.txt" />
|
||||
|
||||
Reference in New Issue
Block a user