Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 62120898d2 | |||
| dc1b9bc7ca | |||
| d1ea41474b | |||
| b11a2ac393 | |||
| 36fb20eb2e | |||
| 15fbec2470 | |||
| 52841de51b | |||
| d4c4615684 | |||
| ae76cab45d | |||
| 8dc54105fd | |||
| 3469593a2a | |||
| ebff0c2028 | |||
| 2fd074e041 | |||
| 4223619802 | |||
| 771305f5d0 | |||
| 90c7c5db92 | |||
| b474fc1257 | |||
| a5879ec9c2 | |||
| 0938553510 | |||
| c1fd18f355 | |||
| c0a8de2617 | |||
| 4d92f144f8 | |||
| c388e9daae | |||
| 29e49546fa | |||
| d46f8d2abe | |||
| 7d9b7981a8 | |||
| 9b2310ea96 | |||
| 58c09c1110 | |||
| 241b68bd0a | |||
| 85d998a8d3 | |||
| da908d0f36 | |||
| ed03166f6f | |||
| 17001d6c8a | |||
| 35ec8b478f |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -25,3 +25,5 @@ Thumbs.db
|
|||||||
obj/
|
obj/
|
||||||
[Rr]elease*/
|
[Rr]elease*/
|
||||||
_ReSharper*/
|
_ReSharper*/
|
||||||
|
*.userprefs
|
||||||
|
*.nupkg
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2015 Valeriano Alfonso Rodriguez
|
Copyright (c) 2016-2017 Valeriano Alfonso Rodriguez
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
71
README.md
Normal file
71
README.md
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
# .Net library and tool to work with PDF files
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### VAR.PdfTools
|
||||||
|
Add the resulting assembly as reference in your projects, and this line on code:
|
||||||
|
|
||||||
|
using VAR.PdfTools;
|
||||||
|
|
||||||
|
Then extract the contents of a data column using:
|
||||||
|
|
||||||
|
var columnData = new List<string>();
|
||||||
|
PdfDocument doc = PdfDocument.Load("document.pdf");
|
||||||
|
foreach (PdfDocumentPage page in doc.Pages)
|
||||||
|
{
|
||||||
|
PdfTextExtractor extractor = new PdfTextExtractor(page);
|
||||||
|
columnData.AddRange(extractor.GetColumn("Column"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Or the content of a field (text on the right of the indicated text):
|
||||||
|
|
||||||
|
var fieldData = new List<string>();
|
||||||
|
PdfDocument doc = PdfDocument.Load("document.pdf");
|
||||||
|
foreach (PdfDocumentPage page in doc.Pages)
|
||||||
|
{
|
||||||
|
PdfTextExtractor extractor = new PdfTextExtractor(page);
|
||||||
|
fieldData.Add(extractor.GetField(txtFieldName.Text));
|
||||||
|
}
|
||||||
|
|
||||||
|
### VAR.PdfTools.Workbench
|
||||||
|
It is a simple Windows.Forms application, to test basic funcitionallity of the library.
|
||||||
|
|
||||||
|
## Building
|
||||||
|
A Visual Studio 2015 and 2010 solutions are provided. Simply, click build on the IDE.
|
||||||
|
|
||||||
|
A .nuget package can be build using:
|
||||||
|
VAR.PdfTools\Build.NuGet.cmd
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
1. Fork it!
|
||||||
|
2. Create your feature branch: `git checkout -b my-new-feature`
|
||||||
|
3. Commit your changes: `git commit -am 'Add some feature'`
|
||||||
|
4. Push to the branch: `git push origin my-new-feature`
|
||||||
|
5. Submit a pull request :D
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
* Valeriano Alfonso Rodriguez.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2016-2017 Valeriano Alfonso Rodriguez
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<?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>
|
|
||||||
<startup>
|
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
|
||||||
</startup>
|
|
||||||
<userSettings>
|
|
||||||
<VAR.PdfTools.Workbench.Properties.Settings>
|
|
||||||
<setting name="LastPdfPath" serializeAs="String">
|
|
||||||
<value />
|
|
||||||
</setting>
|
|
||||||
<setting name="LastColumnName" serializeAs="String">
|
|
||||||
<value />
|
|
||||||
</setting>
|
|
||||||
<setting name="LastFieldName" serializeAs="String">
|
|
||||||
<value />
|
|
||||||
</setting>
|
|
||||||
</VAR.PdfTools.Workbench.Properties.Settings>
|
|
||||||
</userSettings>
|
|
||||||
</configuration>
|
|
||||||
43
VAR.PdfTools.Workbench/FrmPdfInfo.Designer.cs
generated
43
VAR.PdfTools.Workbench/FrmPdfInfo.Designer.cs
generated
@@ -38,13 +38,16 @@
|
|||||||
this.txtColumnName = new System.Windows.Forms.TextBox();
|
this.txtColumnName = new System.Windows.Forms.TextBox();
|
||||||
this.txtFieldName = new System.Windows.Forms.TextBox();
|
this.txtFieldName = new System.Windows.Forms.TextBox();
|
||||||
this.btnGetField = new System.Windows.Forms.Button();
|
this.btnGetField = new System.Windows.Forms.Button();
|
||||||
|
this.txtText = new System.Windows.Forms.TextBox();
|
||||||
|
this.btnHasText = new System.Windows.Forms.Button();
|
||||||
|
this.btnRender = new System.Windows.Forms.Button();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// lblOutputs
|
// lblOutputs
|
||||||
//
|
//
|
||||||
this.lblOutputs.AutoSize = true;
|
this.lblOutputs.AutoSize = true;
|
||||||
this.lblOutputs.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
this.lblOutputs.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
this.lblOutputs.Location = new System.Drawing.Point(12, 130);
|
this.lblOutputs.Location = new System.Drawing.Point(12, 143);
|
||||||
this.lblOutputs.Name = "lblOutputs";
|
this.lblOutputs.Name = "lblOutputs";
|
||||||
this.lblOutputs.Size = new System.Drawing.Size(51, 13);
|
this.lblOutputs.Size = new System.Drawing.Size(51, 13);
|
||||||
this.lblOutputs.TabIndex = 11;
|
this.lblOutputs.TabIndex = 11;
|
||||||
@@ -88,11 +91,11 @@
|
|||||||
| System.Windows.Forms.AnchorStyles.Left)
|
| System.Windows.Forms.AnchorStyles.Left)
|
||||||
| System.Windows.Forms.AnchorStyles.Right)));
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.txtOutput.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
this.txtOutput.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
this.txtOutput.Location = new System.Drawing.Point(15, 146);
|
this.txtOutput.Location = new System.Drawing.Point(15, 159);
|
||||||
this.txtOutput.Multiline = true;
|
this.txtOutput.Multiline = true;
|
||||||
this.txtOutput.Name = "txtOutput";
|
this.txtOutput.Name = "txtOutput";
|
||||||
this.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
this.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||||
this.txtOutput.Size = new System.Drawing.Size(457, 303);
|
this.txtOutput.Size = new System.Drawing.Size(457, 290);
|
||||||
this.txtOutput.TabIndex = 7;
|
this.txtOutput.TabIndex = 7;
|
||||||
//
|
//
|
||||||
// btnProcess
|
// btnProcess
|
||||||
@@ -140,11 +143,42 @@
|
|||||||
this.btnGetField.UseVisualStyleBackColor = true;
|
this.btnGetField.UseVisualStyleBackColor = true;
|
||||||
this.btnGetField.Click += new System.EventHandler(this.btnGetField_Click);
|
this.btnGetField.Click += new System.EventHandler(this.btnGetField_Click);
|
||||||
//
|
//
|
||||||
|
// txtText
|
||||||
|
//
|
||||||
|
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;
|
||||||
|
//
|
||||||
|
// btnHasText
|
||||||
|
//
|
||||||
|
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);
|
||||||
|
//
|
||||||
|
// btnRender
|
||||||
|
//
|
||||||
|
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);
|
||||||
|
//
|
||||||
// FrmPdfInfo
|
// FrmPdfInfo
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(484, 461);
|
this.ClientSize = new System.Drawing.Size(484, 461);
|
||||||
|
this.Controls.Add(this.btnRender);
|
||||||
|
this.Controls.Add(this.txtText);
|
||||||
|
this.Controls.Add(this.btnHasText);
|
||||||
this.Controls.Add(this.txtFieldName);
|
this.Controls.Add(this.txtFieldName);
|
||||||
this.Controls.Add(this.btnGetField);
|
this.Controls.Add(this.btnGetField);
|
||||||
this.Controls.Add(this.txtColumnName);
|
this.Controls.Add(this.txtColumnName);
|
||||||
@@ -176,5 +210,8 @@
|
|||||||
private System.Windows.Forms.TextBox txtColumnName;
|
private System.Windows.Forms.TextBox txtColumnName;
|
||||||
private System.Windows.Forms.TextBox txtFieldName;
|
private System.Windows.Forms.TextBox txtFieldName;
|
||||||
private System.Windows.Forms.Button btnGetField;
|
private System.Windows.Forms.Button btnGetField;
|
||||||
|
private System.Windows.Forms.TextBox txtText;
|
||||||
|
private System.Windows.Forms.Button btnHasText;
|
||||||
|
private System.Windows.Forms.Button btnRender;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using VAR.PdfTools.PdfElements;
|
||||||
|
|
||||||
namespace VAR.PdfTools.Workbench
|
namespace VAR.PdfTools.Workbench
|
||||||
{
|
{
|
||||||
@@ -18,6 +22,7 @@ namespace VAR.PdfTools.Workbench
|
|||||||
txtPdfPath.Text = Properties.Settings.Default.LastPdfPath;
|
txtPdfPath.Text = Properties.Settings.Default.LastPdfPath;
|
||||||
txtColumnName.Text = Properties.Settings.Default.LastColumnName;
|
txtColumnName.Text = Properties.Settings.Default.LastColumnName;
|
||||||
txtFieldName.Text = Properties.Settings.Default.LastFieldName;
|
txtFieldName.Text = Properties.Settings.Default.LastFieldName;
|
||||||
|
txtText.Text = Properties.Settings.Default.LastText;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FrmPdfInfo_FormClosing(object sender, FormClosingEventArgs e)
|
private void FrmPdfInfo_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
@@ -25,6 +30,7 @@ namespace VAR.PdfTools.Workbench
|
|||||||
Properties.Settings.Default.LastPdfPath = txtPdfPath.Text;
|
Properties.Settings.Default.LastPdfPath = txtPdfPath.Text;
|
||||||
Properties.Settings.Default.LastColumnName = txtColumnName.Text;
|
Properties.Settings.Default.LastColumnName = txtColumnName.Text;
|
||||||
Properties.Settings.Default.LastFieldName = txtFieldName.Text;
|
Properties.Settings.Default.LastFieldName = txtFieldName.Text;
|
||||||
|
Properties.Settings.Default.LastText = txtText.Text;
|
||||||
Properties.Settings.Default.Save();
|
Properties.Settings.Default.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,8 +92,9 @@ namespace VAR.PdfTools.Workbench
|
|||||||
PdfTextExtractor extractor = new PdfTextExtractor(page);
|
PdfTextExtractor extractor = new PdfTextExtractor(page);
|
||||||
foreach (PdfTextElement textElement in extractor.Elements)
|
foreach (PdfTextElement textElement in extractor.Elements)
|
||||||
{
|
{
|
||||||
lines.Add(string.Format("Text({0}, {1})({2}, {3}): \"{4}\"",
|
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.Matrix.Matrix[0, 2], textElement.Matrix.Matrix[1, 2], textElement.VisibleWidth, textElement.VisibleHeight,
|
||||||
|
textElement.Font == null ? "#NULL#" : textElement.Font.Name,
|
||||||
textElement.VisibleText));
|
textElement.VisibleText));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,5 +139,171 @@ namespace VAR.PdfTools.Workbench
|
|||||||
}
|
}
|
||||||
txtOutput.Lines = fieldData.ToArray();
|
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);
|
||||||
|
|
||||||
|
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))));
|
||||||
|
}
|
||||||
|
txtOutput.Lines = lines.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnRender_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (File.Exists(txtPdfPath.Text) == false)
|
||||||
|
{
|
||||||
|
MessageBox.Show("File does not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int Scale = 5;
|
||||||
|
|
||||||
|
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);
|
||||||
|
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),
|
||||||
|
Scale);
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,120 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:choice maxOccurs="unbounded">
|
|
||||||
<xsd:element name="metadata">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="assembly">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:attribute name="alias" type="xsd:string" />
|
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="data">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="resheader">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:choice>
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:schema>
|
|
||||||
<resheader name="resmimetype">
|
|
||||||
<value>text/microsoft-resx</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="version">
|
|
||||||
<value>2.0</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="reader">
|
|
||||||
<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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
</root>
|
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace VAR.PdfTools.Workbench
|
namespace VAR.PdfTools.Workbench
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
[assembly: Guid("a5825d8e-9f81-49e0-b610-8ae5e46d02ea")]
|
[assembly: Guid("a5825d8e-9f81-49e0-b610-8ae5e46d02ea")]
|
||||||
[assembly: AssemblyVersion("1.0.*")]
|
[assembly: AssemblyVersion("1.3.*")]
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
// <auto-generated>
|
|
||||||
// This code was generated by a tool.
|
|
||||||
// Runtime Version:4.0.30319.42000
|
|
||||||
//
|
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
|
||||||
// the code is regenerated.
|
|
||||||
// </auto-generated>
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace VAR.PdfTools.Workbench.Properties
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
|
||||||
/// </summary>
|
|
||||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
|
||||||
// class via a tool like ResGen or Visual Studio.
|
|
||||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
|
||||||
// with the /str option, or rebuild your VS project.
|
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
|
||||||
internal class Resources
|
|
||||||
{
|
|
||||||
|
|
||||||
private static global::System.Resources.ResourceManager resourceMan;
|
|
||||||
|
|
||||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
|
||||||
|
|
||||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
||||||
internal Resources()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the cached ResourceManager instance used by this class.
|
|
||||||
/// </summary>
|
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
internal static global::System.Resources.ResourceManager ResourceManager
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if ((resourceMan == null))
|
|
||||||
{
|
|
||||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("VAR.PdfTools.Workbench.Properties.Resources", typeof(Resources).Assembly);
|
|
||||||
resourceMan = temp;
|
|
||||||
}
|
|
||||||
return resourceMan;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Overrides the current thread's CurrentUICulture property for all
|
|
||||||
/// resource lookups using this strongly typed resource class.
|
|
||||||
/// </summary>
|
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
internal static global::System.Globalization.CultureInfo Culture
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return resourceCulture;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
resourceCulture = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:choice maxOccurs="unbounded">
|
|
||||||
<xsd:element name="metadata">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="assembly">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:attribute name="alias" type="xsd:string" />
|
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="data">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="resheader">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:choice>
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:schema>
|
|
||||||
<resheader name="resmimetype">
|
|
||||||
<value>text/microsoft-resx</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="version">
|
|
||||||
<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>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="writer">
|
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
</root>
|
|
||||||
@@ -12,7 +12,7 @@ namespace VAR.PdfTools.Workbench.Properties {
|
|||||||
|
|
||||||
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
|
||||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||||
|
|
||||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||||
@@ -58,5 +58,17 @@ namespace VAR.PdfTools.Workbench.Properties {
|
|||||||
this["LastFieldName"] = value;
|
this["LastFieldName"] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
||||||
|
public string LastText {
|
||||||
|
get {
|
||||||
|
return ((string)(this["LastText"]));
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this["LastText"] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,8 @@
|
|||||||
<Setting Name="LastFieldName" Type="System.String" Scope="User">
|
<Setting Name="LastFieldName" Type="System.String" Scope="User">
|
||||||
<Value Profile="(Default)" />
|
<Value Profile="(Default)" />
|
||||||
</Setting>
|
</Setting>
|
||||||
|
<Setting Name="LastText" Type="System.String" Scope="User">
|
||||||
|
<Value Profile="(Default)" />
|
||||||
|
</Setting>
|
||||||
</Settings>
|
</Settings>
|
||||||
</SettingsFile>
|
</SettingsFile>
|
||||||
81
VAR.PdfTools.Workbench/VAR.PdfTools.Workbench.Net35.csproj
Normal file
81
VAR.PdfTools.Workbench/VAR.PdfTools.Workbench.Net35.csproj
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<?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>{A5825D8E-9F81-49E0-B610-8AE5E46D02EA}</ProjectGuid>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>VAR.PdfTools.Workbench</RootNamespace>
|
||||||
|
<AssemblyName>VAR.PdfTools.Workbench</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
<TargetFrameworkProfile />
|
||||||
|
<ProductVersion>10.0.0</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<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' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<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.Drawing" />
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="FrmPdfInfo.cs">
|
||||||
|
<SubType>Form</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="FrmPdfInfo.Designer.cs">
|
||||||
|
<DependentUpon>FrmPdfInfo.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<None Include="Properties\Settings.settings">
|
||||||
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
|
</None>
|
||||||
|
<Compile Include="Properties\Settings.Designer.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Settings.settings</DependentUpon>
|
||||||
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
|
</Compile>
|
||||||
|
</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>
|
||||||
|
-->
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\VAR.PdfTools\VAR.PdfTools.Net35.csproj">
|
||||||
|
<Project>{EB7E003A-6A95-4002-809F-926C7C8A11E9}</Project>
|
||||||
|
<Name>VAR.PdfTools.Net35</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
<TargetFrameworkProfile />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
@@ -40,11 +41,8 @@
|
|||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Deployment" />
|
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Net.Http" />
|
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -57,18 +55,6 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<EmbeddedResource Include="FrmPdfInfo.resx">
|
|
||||||
<DependentUpon>FrmPdfInfo.cs</DependentUpon>
|
|
||||||
</EmbeddedResource>
|
|
||||||
<EmbeddedResource Include="Properties\Resources.resx">
|
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
|
||||||
<SubType>Designer</SubType>
|
|
||||||
</EmbeddedResource>
|
|
||||||
<Compile Include="Properties\Resources.Designer.cs">
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
<None Include="Properties\Settings.settings">
|
<None Include="Properties\Settings.settings">
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
@@ -79,9 +65,6 @@
|
|||||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<None Include="App.config" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\VAR.PdfTools\VAR.PdfTools.csproj">
|
<ProjectReference Include="..\VAR.PdfTools\VAR.PdfTools.csproj">
|
||||||
<Project>{eb7e003a-6a95-4002-809f-926c7c8a11e9}</Project>
|
<Project>{eb7e003a-6a95-4002-809f-926c7c8a11e9}</Project>
|
||||||
|
|||||||
@@ -1,22 +1,28 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 14
|
# Visual Studio 14
|
||||||
VisualStudioVersion = 14.0.25123.0
|
VisualStudioVersion = 14.0.25420.1
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VAR.PdfTools", "VAR.PdfTools\VAR.PdfTools.csproj", "{EB7E003A-6A95-4002-809F-926C7C8A11E9}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VAR.PdfTools", "VAR.PdfTools\VAR.PdfTools.csproj", "{EB7E003A-6A95-4002-809F-926C7C8A11E9}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VAR.PdfTools.Workbench", "VAR.PdfTools.Workbench\VAR.PdfTools.Workbench.csproj", "{A5825D8E-9F81-49E0-B610-8AE5E46D02EA}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VAR.PdfTools.Workbench", "VAR.PdfTools.Workbench\VAR.PdfTools.Workbench.csproj", "{A5825D8E-9F81-49E0-B610-8AE5E46D02EA}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Notes", "Notes", "{CE2D7584-5D82-401E-9A88-A9961CBB6959}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
LICENSE.txt = LICENSE.txt
|
||||||
|
README.md = README.md
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{EB7E003A-6A95-4002-809F-926C7C8A11E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{EB7E003A-6A95-4002-809F-926C7C8A11E9}.Debug|Any CPU.ActiveCfg = Debug .Net 4.6.1|Any CPU
|
||||||
{EB7E003A-6A95-4002-809F-926C7C8A11E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{EB7E003A-6A95-4002-809F-926C7C8A11E9}.Debug|Any CPU.Build.0 = Debug .Net 4.6.1|Any CPU
|
||||||
{EB7E003A-6A95-4002-809F-926C7C8A11E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{EB7E003A-6A95-4002-809F-926C7C8A11E9}.Release|Any CPU.ActiveCfg = Release .Net 4.6.1|Any CPU
|
||||||
{EB7E003A-6A95-4002-809F-926C7C8A11E9}.Release|Any CPU.Build.0 = Release|Any CPU
|
{EB7E003A-6A95-4002-809F-926C7C8A11E9}.Release|Any CPU.Build.0 = Release .Net 4.6.1|Any CPU
|
||||||
{A5825D8E-9F81-49E0-B610-8AE5E46D02EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{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}.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.ActiveCfg = Release|Any CPU
|
||||||
|
|||||||
29
VAR.PdfTools/Build.NuGet.cmd
Normal file
29
VAR.PdfTools/Build.NuGet.cmd
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
@echo off
|
||||||
|
|
||||||
|
:: MSBuild and tools 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"
|
||||||
|
if exist "%~dp0..\packages\NuGet.CommandLine.3.4.3\tools\NuGet.exe" set nuget="%~dp0\..\packages\NuGet.CommandLine.3.4.3\tools\NuGet.exe"
|
||||||
|
|
||||||
|
:: Release .Net 3.5
|
||||||
|
Title Building Release .Net 3.5
|
||||||
|
msbuild VAR.PdfTools.csproj /t:Build /p:Configuration="Release .Net 3.5" /p:Platform="AnyCPU"
|
||||||
|
|
||||||
|
:: Release .Net 4.6.1
|
||||||
|
Title Building Release .Net 4.6.1
|
||||||
|
msbuild VAR.PdfTools.csproj /t:Build /p:Configuration="Release .Net 4.6.1" /p:Platform="AnyCPU"
|
||||||
|
|
||||||
|
:: Packing Nuget
|
||||||
|
Title Packing Nuget
|
||||||
|
%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
|
||||||
|
}
|
||||||
|
}
|
||||||
0
VAR.PdfTools/NuGet/keep.txt
Normal file
0
VAR.PdfTools/NuGet/keep.txt
Normal file
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using VAR.PdfTools.PdfElements;
|
||||||
|
|
||||||
namespace VAR.PdfTools
|
namespace VAR.PdfTools
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using VAR.PdfTools.PdfElements;
|
||||||
|
|
||||||
namespace VAR.PdfTools
|
namespace VAR.PdfTools
|
||||||
{
|
{
|
||||||
@@ -36,49 +36,12 @@ namespace VAR.PdfTools
|
|||||||
|
|
||||||
#region Private methods
|
#region Private methods
|
||||||
|
|
||||||
private static byte[] DecodeFlateStreamData(byte[] streamData)
|
private static void ApplyFilterToStream(PdfStream stream, string filter)
|
||||||
{
|
{
|
||||||
MemoryStream msInput = new MemoryStream(streamData);
|
|
||||||
MemoryStream msOutput = new MemoryStream();
|
|
||||||
|
|
||||||
// It seems to work when skipping the first two bytes.
|
|
||||||
byte header;
|
|
||||||
header = (byte)msInput.ReadByte();
|
|
||||||
header = (byte)msInput.ReadByte();
|
|
||||||
|
|
||||||
DeflateStream zip = new DeflateStream(msInput, CompressionMode.Decompress, true);
|
|
||||||
int cbRead;
|
|
||||||
byte[] abResult = new byte[1024];
|
|
||||||
do
|
|
||||||
{
|
|
||||||
cbRead = zip.Read(abResult, 0, abResult.Length);
|
|
||||||
if (cbRead > 0)
|
|
||||||
{
|
|
||||||
msOutput.Write(abResult, 0, cbRead);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (cbRead > 0);
|
|
||||||
zip.Close();
|
|
||||||
msOutput.Flush();
|
|
||||||
if (msOutput.Length >= 0)
|
|
||||||
{
|
|
||||||
msOutput.Capacity = (int)msOutput.Length;
|
|
||||||
return msOutput.GetBuffer();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ApplyFiltersToStreams(PdfStream stream)
|
|
||||||
{
|
|
||||||
string filter = stream.Dictionary.GetParamAsString("Filter");
|
|
||||||
if (filter == "FlateDecode")
|
if (filter == "FlateDecode")
|
||||||
{
|
{
|
||||||
stream.OriginalData = stream.Data;
|
byte[] decodedStreamData = PdfFilters.FlateDecode.Decode(stream.Data);
|
||||||
stream.OriginalFilter = stream.Dictionary.Values["Filter"];
|
|
||||||
byte[] decodedStreamData = DecodeFlateStreamData(stream.Data);
|
|
||||||
stream.Data = decodedStreamData;
|
stream.Data = decodedStreamData;
|
||||||
stream.Dictionary.Values["Length"] = new PdfInteger { Value = decodedStreamData.Length };
|
|
||||||
stream.Dictionary.Values.Remove("Filter");
|
|
||||||
}
|
}
|
||||||
else if (filter == "ASCII85Decode" || filter == "A85")
|
else if (filter == "ASCII85Decode" || filter == "A85")
|
||||||
{
|
{
|
||||||
@@ -92,11 +55,55 @@ namespace VAR.PdfTools
|
|||||||
{
|
{
|
||||||
// FIXME: Implement this filter
|
// FIXME: Implement this filter
|
||||||
}
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// FIXME: Implement the rest of filters
|
// FIXME: Implement the rest of filters
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ApplyFiltersToStreams(PdfStream stream)
|
||||||
|
{
|
||||||
|
if (stream.Dictionary.Values.ContainsKey("Filter") == false) { return; }
|
||||||
|
IPdfElement elemFilter = stream.Dictionary.Values["Filter"];
|
||||||
|
|
||||||
|
stream.OriginalData = stream.Data;
|
||||||
|
stream.OriginalFilter = stream.Dictionary.Values["Filter"];
|
||||||
|
|
||||||
|
if (elemFilter is PdfString)
|
||||||
|
{
|
||||||
|
ApplyFilterToStream(stream, ((PdfString)elemFilter).Value);
|
||||||
|
}
|
||||||
|
else if (elemFilter is PdfName)
|
||||||
|
{
|
||||||
|
ApplyFilterToStream(stream, ((PdfName)elemFilter).Value);
|
||||||
|
}
|
||||||
|
else if(elemFilter is PdfArray)
|
||||||
|
{
|
||||||
|
foreach(IPdfElement elemSubFilter in ((PdfArray)elemFilter).Values)
|
||||||
|
{
|
||||||
|
if (elemSubFilter is PdfString)
|
||||||
|
{
|
||||||
|
ApplyFilterToStream(stream, ((PdfString)elemSubFilter).Value);
|
||||||
|
}
|
||||||
|
else if (elemSubFilter is PdfName)
|
||||||
|
{
|
||||||
|
ApplyFilterToStream(stream, ((PdfName)elemSubFilter).Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("PdfFilter not correctly specified");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("PdfFilter not correctly specified");
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.Dictionary.Values["Length"] = new PdfInteger { Value = stream.Data.Length };
|
||||||
|
stream.Dictionary.Values.Remove("Filter");
|
||||||
|
}
|
||||||
|
|
||||||
private static IPdfElement ResolveIndirectReferences(IPdfElement elem, Dictionary<int, PdfObject> dictReferences)
|
private static IPdfElement ResolveIndirectReferences(IPdfElement elem, Dictionary<int, PdfObject> dictReferences)
|
||||||
{
|
{
|
||||||
if (elem is PdfObjectReference)
|
if (elem is PdfObjectReference)
|
||||||
@@ -211,7 +218,7 @@ namespace VAR.PdfTools
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
PdfObject obj = parser.ParseObject(doc.Objects);
|
PdfObject obj = parser.ParseObject(doc.Objects);
|
||||||
if (obj != null)
|
if (obj != null && obj.Data != null)
|
||||||
{
|
{
|
||||||
if (obj.Data is PdfStream)
|
if (obj.Data is PdfStream)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using VAR.PdfTools.PdfElements;
|
||||||
|
|
||||||
namespace VAR.PdfTools
|
namespace VAR.PdfTools
|
||||||
{
|
{
|
||||||
@@ -58,6 +59,7 @@ namespace VAR.PdfTools
|
|||||||
foreach (KeyValuePair<string, IPdfElement> pair in fonts.Values)
|
foreach (KeyValuePair<string, IPdfElement> pair in fonts.Values)
|
||||||
{
|
{
|
||||||
var font = new PdfFont(pair.Value as PdfDictionary);
|
var font = new PdfFont(pair.Value as PdfDictionary);
|
||||||
|
font.Name = pair.Key;
|
||||||
_fonts.Add(pair.Key, font);
|
_fonts.Add(pair.Key, font);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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; private set; } = PdfElementTypes.Boolean;
|
|
||||||
public bool Value { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PdfInteger : IPdfElement
|
|
||||||
{
|
|
||||||
public PdfElementTypes Type { get; private set; } = PdfElementTypes.Integer;
|
|
||||||
public long Value { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PdfReal : IPdfElement
|
|
||||||
{
|
|
||||||
public PdfElementTypes Type { get; private set; } = PdfElementTypes.Real;
|
|
||||||
public double Value { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PdfString : IPdfElement
|
|
||||||
{
|
|
||||||
public PdfElementTypes Type { get; private set; } = PdfElementTypes.String;
|
|
||||||
public string Value { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PdfName : IPdfElement
|
|
||||||
{
|
|
||||||
public PdfElementTypes Type { get; private set; } = PdfElementTypes.Name;
|
|
||||||
public string Value { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PdfArray : IPdfElement
|
|
||||||
{
|
|
||||||
public PdfElementTypes Type { get; private set; } = PdfElementTypes.Array;
|
|
||||||
private List<IPdfElement> _values = new List<IPdfElement>();
|
|
||||||
public List<IPdfElement> Values { get { return _values; } }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PdfDictionary : IPdfElement
|
|
||||||
{
|
|
||||||
public PdfElementTypes Type { get; private set; } = 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; private set; } = PdfElementTypes.Null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PdfObjectReference : IPdfElement
|
|
||||||
{
|
|
||||||
public PdfElementTypes Type { get; private set; } = PdfElementTypes.ObjectReference;
|
|
||||||
public int ObjectID { get; set; }
|
|
||||||
public int ObjectGeneration { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PdfStream : IPdfElement
|
|
||||||
{
|
|
||||||
public PdfElementTypes Type { get; private set; } = 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; private set; } = PdfElementTypes.Object;
|
|
||||||
public int ObjectID { get; set; }
|
|
||||||
public int ObjectGeneration { get; set; }
|
|
||||||
public IPdfElement Data { get; set; }
|
|
||||||
public int UsageCount { get; set; } = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
50
VAR.PdfTools/PdfFilters.cs
Normal file
50
VAR.PdfTools/PdfFilters.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
|
||||||
|
namespace VAR.PdfTools
|
||||||
|
{
|
||||||
|
public static class PdfFilters
|
||||||
|
{
|
||||||
|
public class FlateDecode
|
||||||
|
{
|
||||||
|
public byte[] Encode(byte[] streamData)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException("FlateFilter.Encode: Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] Decode(byte[] streamData)
|
||||||
|
{
|
||||||
|
MemoryStream msInput = new MemoryStream(streamData);
|
||||||
|
MemoryStream msOutput = new MemoryStream();
|
||||||
|
|
||||||
|
// It seems to work when skipping the first two bytes.
|
||||||
|
byte header;
|
||||||
|
header = (byte)msInput.ReadByte();
|
||||||
|
header = (byte)msInput.ReadByte();
|
||||||
|
|
||||||
|
DeflateStream zip = new DeflateStream(msInput, CompressionMode.Decompress, true);
|
||||||
|
int cbRead;
|
||||||
|
byte[] abResult = new byte[1024];
|
||||||
|
do
|
||||||
|
{
|
||||||
|
cbRead = zip.Read(abResult, 0, abResult.Length);
|
||||||
|
if (cbRead > 0)
|
||||||
|
{
|
||||||
|
msOutput.Write(abResult, 0, cbRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (cbRead > 0);
|
||||||
|
zip.Close();
|
||||||
|
msOutput.Flush();
|
||||||
|
if (msOutput.Length >= 0)
|
||||||
|
{
|
||||||
|
msOutput.Capacity = (int)msOutput.Length;
|
||||||
|
return msOutput.GetBuffer();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using VAR.PdfTools.PdfElements;
|
||||||
|
|
||||||
namespace VAR.PdfTools
|
namespace VAR.PdfTools
|
||||||
{
|
{
|
||||||
@@ -15,6 +15,8 @@ namespace VAR.PdfTools
|
|||||||
|
|
||||||
private double _height = 1.0;
|
private double _height = 1.0;
|
||||||
|
|
||||||
|
private string _name = string.Empty;
|
||||||
|
|
||||||
private bool _tainted = false;
|
private bool _tainted = false;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -25,6 +27,8 @@ namespace VAR.PdfTools
|
|||||||
|
|
||||||
public double Height { get { return _height; } }
|
public double Height { get { return _height; } }
|
||||||
|
|
||||||
|
public string Name { get { return _name; } set { _name = value; } }
|
||||||
|
|
||||||
public bool Tainted { get { return _tainted; } }
|
public bool Tainted { get { return _tainted; } }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -41,6 +45,19 @@ namespace VAR.PdfTools
|
|||||||
_tainted = true;
|
_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"))
|
if (baseData.Values.ContainsKey("ToUnicode"))
|
||||||
{
|
{
|
||||||
byte[] toUnicodeStream = ((PdfStream)baseData.Values["ToUnicode"]).Data;
|
byte[] toUnicodeStream = ((PdfStream)baseData.Values["ToUnicode"]).Data;
|
||||||
@@ -48,7 +65,19 @@ namespace VAR.PdfTools
|
|||||||
_toUnicode = parser.ParseToUnicode();
|
_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"))
|
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
|
double glyphSpaceToTextSpace = 1000.0; // FIXME: SubType:Type3 Uses a FontMatrix that may not correspond to 1/1000th
|
||||||
_widths = new Dictionary<char, double>();
|
_widths = new Dictionary<char, double>();
|
||||||
@@ -58,26 +87,14 @@ namespace VAR.PdfTools
|
|||||||
char actualChar = firstChar;
|
char actualChar = firstChar;
|
||||||
foreach (IPdfElement elem in widths.Values)
|
foreach (IPdfElement elem in widths.Values)
|
||||||
{
|
{
|
||||||
PdfReal widthReal = elem as PdfReal;
|
_widths.Add(actualChar, PdfElementUtils.GetReal(elem, 500) / glyphSpaceToTextSpace);
|
||||||
if (widthReal != null)
|
|
||||||
{
|
|
||||||
_widths.Add(actualChar, widthReal.Value / glyphSpaceToTextSpace);
|
|
||||||
actualChar++;
|
actualChar++;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
PdfInteger widthInt = elem as PdfInteger;
|
|
||||||
if (widthInt != null)
|
|
||||||
{
|
|
||||||
_widths.Add(actualChar, widthInt.Value / glyphSpaceToTextSpace);
|
|
||||||
actualChar++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// FIMXE: Calculate real height
|
// FIMXE: Calculate real height
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
private void SetBaseFontSizes(string baseFont)
|
||||||
{
|
{
|
||||||
string baseFont = _baseData.GetParamAsString("BaseFont");
|
|
||||||
if (baseFont == "Times-Roman")
|
if (baseFont == "Times-Roman")
|
||||||
{
|
{
|
||||||
_widths = PdfStandar14FontMetrics.Times_Roman.Widths;
|
_widths = PdfStandar14FontMetrics.Times_Roman.Widths;
|
||||||
@@ -149,7 +166,6 @@ namespace VAR.PdfTools
|
|||||||
_height = PdfStandar14FontMetrics.ZapfDingbats.ApproxHeight;
|
_height = PdfStandar14FontMetrics.ZapfDingbats.ApproxHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -173,15 +189,23 @@ namespace VAR.PdfTools
|
|||||||
|
|
||||||
public double GetCharWidth(char character)
|
public double GetCharWidth(char character)
|
||||||
{
|
{
|
||||||
|
double charWidth = 0;
|
||||||
if (_widths == null)
|
if (_widths == null)
|
||||||
{
|
{
|
||||||
return 0;
|
return charWidth;
|
||||||
}
|
}
|
||||||
if (_widths.ContainsKey(character))
|
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
|
#endregion
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Globalization;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using VAR.PdfTools.PdfElements;
|
||||||
|
|
||||||
namespace VAR.PdfTools
|
namespace VAR.PdfTools
|
||||||
{
|
{
|
||||||
@@ -23,13 +24,6 @@ namespace VAR.PdfTools
|
|||||||
public PdfParser(byte[] stream)
|
public PdfParser(byte[] stream)
|
||||||
{
|
{
|
||||||
_stream = stream;
|
_stream = stream;
|
||||||
|
|
||||||
// Intentar usar el separador decimal de la cultura
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_decimalSeparator = CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator;
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -436,7 +430,7 @@ namespace VAR.PdfTools
|
|||||||
if (dotCount == 1)
|
if (dotCount == 1)
|
||||||
{
|
{
|
||||||
PdfReal obj = new PdfReal();
|
PdfReal obj = new PdfReal();
|
||||||
obj.Value = Convert.ToDouble(sbNumber.ToString());
|
obj.Value = Convert.ToDouble(sbNumber.ToString(), CultureInfo.InvariantCulture);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1028,6 +1022,20 @@ namespace VAR.PdfTools
|
|||||||
PdfContentAction action = new PdfContentAction(token, elems);
|
PdfContentAction action = new PdfContentAction(token, elems);
|
||||||
elems = new List<IPdfElement>();
|
elems = new List<IPdfElement>();
|
||||||
actions.Add(action);
|
actions.Add(action);
|
||||||
|
if (action.Token == "ID")
|
||||||
|
{
|
||||||
|
// Embbed inline image
|
||||||
|
byte lineFeed = 0x0A;
|
||||||
|
byte carriageReturn = 0x0D;
|
||||||
|
long distToObject = MeasureToMarkers(new char[][] {
|
||||||
|
new char[] {(char)lineFeed, 'E', 'I'},
|
||||||
|
new char[] {(char)carriageReturn, (char)lineFeed, 'E', 'I'},
|
||||||
|
});
|
||||||
|
byte[] imageBody = GetRawData(distToObject);
|
||||||
|
SkipEndOfLine();
|
||||||
|
string endToken = ParseToken();
|
||||||
|
action.Parameters.Add(new PdfStream { OriginalData = imageBody, });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while (IsEndOfStream() == false);
|
} while (IsEndOfStream() == false);
|
||||||
return actions;
|
return actions;
|
||||||
|
|||||||
@@ -1,124 +1,16 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using VAR.PdfTools.Maths;
|
||||||
|
using VAR.PdfTools.PdfElements;
|
||||||
|
|
||||||
namespace VAR.PdfTools
|
namespace VAR.PdfTools
|
||||||
{
|
{
|
||||||
public class Vector3D
|
public struct PdfCharElement
|
||||||
{
|
{
|
||||||
#region Declarations
|
public string Char;
|
||||||
|
public double Displacement;
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
#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 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PdfTextElement
|
public class PdfTextElement
|
||||||
@@ -139,6 +31,10 @@ namespace VAR.PdfTools
|
|||||||
|
|
||||||
public double VisibleHeight { get; set; }
|
public double VisibleHeight { get; set; }
|
||||||
|
|
||||||
|
public List<PdfCharElement> Characters { get; set; }
|
||||||
|
|
||||||
|
public List<PdfTextElement> Childs { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public methods
|
#region Public methods
|
||||||
@@ -171,13 +67,17 @@ namespace VAR.PdfTools
|
|||||||
// Text state
|
// Text state
|
||||||
private PdfFont _font = null;
|
private PdfFont _font = null;
|
||||||
private double _fontSize = 1;
|
private double _fontSize = 1;
|
||||||
|
private double _charSpacing = 0;
|
||||||
|
private double _wordSpacing = 0;
|
||||||
private double _textLeading = 0;
|
private double _textLeading = 0;
|
||||||
|
|
||||||
// Text object state
|
// Text object state
|
||||||
private bool inText = false;
|
private bool inText = false;
|
||||||
private Matrix3x3 _textMatrix = new Matrix3x3();
|
private Matrix3x3 _textMatrix = new Matrix3x3();
|
||||||
|
private Matrix3x3 _textMatrixCurrent = new Matrix3x3();
|
||||||
private StringBuilder _sbText = new StringBuilder();
|
private StringBuilder _sbText = new StringBuilder();
|
||||||
private double _textWidth = 0;
|
private double _textWidth = 0;
|
||||||
|
private List<PdfCharElement> _listCharacters = new List<PdfCharElement>();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -194,7 +94,8 @@ namespace VAR.PdfTools
|
|||||||
public PdfTextExtractor(PdfDocumentPage page)
|
public PdfTextExtractor(PdfDocumentPage page)
|
||||||
{
|
{
|
||||||
_page = page;
|
_page = page;
|
||||||
ProcessPage();
|
ProcessPageContent();
|
||||||
|
JoinTextElements();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -216,32 +117,79 @@ namespace VAR.PdfTools
|
|||||||
return sbText.ToString();
|
return sbText.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FlushTextElement()
|
private PdfTextElement BuildTextElement()
|
||||||
{
|
{
|
||||||
if (_sbText.Length == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PdfTextElement textElem = new PdfTextElement();
|
PdfTextElement textElem = new PdfTextElement();
|
||||||
textElem.Font = _font;
|
textElem.Font = _font;
|
||||||
textElem.FontSize = _fontSize;
|
textElem.FontSize = _fontSize;
|
||||||
textElem.Matrix = _textMatrix.Multiply(_graphicsMatrix);
|
textElem.Matrix = _textMatrixCurrent.Multiply(_graphicsMatrix);
|
||||||
textElem.RawText = _sbText.ToString();
|
textElem.RawText = _sbText.ToString();
|
||||||
textElem.VisibleText = PdfString_ToUnicode(textElem.RawText, _font);
|
textElem.VisibleText = PdfString_ToUnicode(textElem.RawText, _font);
|
||||||
textElem.VisibleWidth = _textWidth * textElem.Matrix.Matrix[0, 0];
|
textElem.VisibleWidth = _textWidth * textElem.Matrix.Matrix[0, 0];
|
||||||
textElem.VisibleHeight = (_font.Height * _fontSize) * textElem.Matrix.Matrix[1, 1];
|
textElem.VisibleHeight = (_font.Height * _fontSize) * textElem.Matrix.Matrix[1, 1];
|
||||||
_textElements.Add(textElem);
|
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]),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
textElem.Childs = new List<PdfTextElement>();
|
||||||
|
return textElem;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddTextElement(PdfTextElement textElement)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textElement.VisibleText.Trim()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_textElements.Add(textElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FlushTextElement()
|
||||||
|
{
|
||||||
|
if (_sbText.Length == 0)
|
||||||
|
{
|
||||||
|
_textWidth = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PdfTextElement textElem = BuildTextElement();
|
||||||
|
AddTextElement(textElem);
|
||||||
|
|
||||||
|
_textMatrixCurrent.Matrix[0, 2] += _textWidth;
|
||||||
|
|
||||||
_sbText = new StringBuilder();
|
_sbText = new StringBuilder();
|
||||||
|
_listCharacters.Clear();
|
||||||
_textWidth = 0;
|
_textWidth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PdfTextElement FindElementByText(string text)
|
private string SimplifyText(string text)
|
||||||
{
|
{
|
||||||
|
StringBuilder sbResult = new StringBuilder();
|
||||||
|
foreach (char c in text)
|
||||||
|
{
|
||||||
|
if (c == '.' || c == ',' ||
|
||||||
|
c == ':' || c == ';' ||
|
||||||
|
c == '-' || c == '_' ||
|
||||||
|
c == ' ' || c == '\t')
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sbResult.Append(char.ToUpper(c));
|
||||||
|
}
|
||||||
|
return sbResult.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private PdfTextElement FindElementByText(string text, bool fuzzy)
|
||||||
|
{
|
||||||
|
string matchingText = fuzzy ? SimplifyText(text) : text;
|
||||||
foreach (PdfTextElement elem in _textElements)
|
foreach (PdfTextElement elem in _textElements)
|
||||||
{
|
{
|
||||||
if (elem.VisibleText == text)
|
string elemText = fuzzy ? SimplifyText(elem.VisibleText) : elem.VisibleText;
|
||||||
|
if (elemText == matchingText)
|
||||||
{
|
{
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
@@ -249,6 +197,21 @@ namespace VAR.PdfTools
|
|||||||
return null;
|
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)
|
private bool TextElementVerticalIntersection(PdfTextElement elem1, PdfTextElement elem2)
|
||||||
{
|
{
|
||||||
double elem1X1 = elem1.GetX();
|
double elem1X1 = elem1.GetX();
|
||||||
@@ -278,28 +241,21 @@ namespace VAR.PdfTools
|
|||||||
_graphicsMatrixStack.Add(_graphicsMatrix.Copy());
|
_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()
|
private void OpPopGraphState()
|
||||||
{
|
{
|
||||||
_graphicsMatrix = _graphicsMatrixStack[_graphicsMatrixStack.Count - 1];
|
_graphicsMatrix = _graphicsMatrixStack[_graphicsMatrixStack.Count - 1];
|
||||||
_graphicsMatrixStack.RemoveAt(_graphicsMatrixStack.Count - 1);
|
_graphicsMatrixStack.RemoveAt(_graphicsMatrixStack.Count - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpSetGraphMatrix(double a, double b, double c, double d, double e, double f)
|
|
||||||
{
|
|
||||||
_graphicsMatrix.Matrix[0, 0] = a;
|
|
||||||
_graphicsMatrix.Matrix[1, 0] = b;
|
|
||||||
_graphicsMatrix.Matrix[2, 0] = 0;
|
|
||||||
_graphicsMatrix.Matrix[0, 1] = c;
|
|
||||||
_graphicsMatrix.Matrix[1, 1] = d;
|
|
||||||
_graphicsMatrix.Matrix[2, 1] = 0;
|
|
||||||
_graphicsMatrix.Matrix[0, 2] = e;
|
|
||||||
_graphicsMatrix.Matrix[1, 2] = f;
|
|
||||||
_graphicsMatrix.Matrix[2, 2] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OpBeginText()
|
private void OpBeginText()
|
||||||
{
|
{
|
||||||
_textMatrix.Idenity();
|
_textMatrix.Idenity();
|
||||||
|
_textMatrixCurrent.Idenity();
|
||||||
inText = true;
|
inText = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,37 +272,42 @@ namespace VAR.PdfTools
|
|||||||
_fontSize = size;
|
_fontSize = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OpTextCharSpacing(double charSpacing)
|
||||||
|
{
|
||||||
|
_charSpacing = charSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OpTextWordSpacing(double wordSpacing)
|
||||||
|
{
|
||||||
|
_wordSpacing = wordSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
private void OpTextLeading(double textLeading)
|
private void OpTextLeading(double textLeading)
|
||||||
{
|
{
|
||||||
_textLeading = textLeading;
|
_textLeading = textLeading;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpTesDisplace(double x, double y)
|
private void OpTextDisplace(double x, double y)
|
||||||
{
|
{
|
||||||
FlushTextElement();
|
FlushTextElement();
|
||||||
var newMatrix = new Matrix3x3();
|
var newMatrix = new Matrix3x3();
|
||||||
newMatrix.Matrix[0, 2] = x;
|
newMatrix.Matrix[0, 2] = x;
|
||||||
newMatrix.Matrix[1, 2] = y;
|
newMatrix.Matrix[1, 2] = y;
|
||||||
_textMatrix = newMatrix.Multiply(_textMatrix);
|
_textMatrix = newMatrix.Multiply(_textMatrix);
|
||||||
|
_textMatrixCurrent = _textMatrix.Copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpTextLineFeed()
|
private void OpTextLineFeed()
|
||||||
{
|
{
|
||||||
OpTesDisplace(0, -_textLeading);
|
OpTextDisplace(0, -_textLeading);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpSetTextMatrix(double a, double b, double c, double d, double e, double f)
|
private void OpSetTextMatrix(double a, double b, double c, double d, double e, double f)
|
||||||
{
|
{
|
||||||
|
Matrix3x3 newMatrix = new Matrix3x3(a, b, c, d, e, f);
|
||||||
FlushTextElement();
|
FlushTextElement();
|
||||||
_textMatrix.Matrix[0, 0] = a;
|
_textMatrix = newMatrix;
|
||||||
_textMatrix.Matrix[1, 0] = b;
|
_textMatrixCurrent = _textMatrix.Copy();
|
||||||
_textMatrix.Matrix[2, 0] = 0;
|
|
||||||
_textMatrix.Matrix[0, 1] = c;
|
|
||||||
_textMatrix.Matrix[1, 1] = d;
|
|
||||||
_textMatrix.Matrix[2, 1] = 0;
|
|
||||||
_textMatrix.Matrix[0, 2] = e;
|
|
||||||
_textMatrix.Matrix[1, 2] = f;
|
|
||||||
_textMatrix.Matrix[2, 2] = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpTextPut(string text)
|
private void OpTextPut(string text)
|
||||||
@@ -357,7 +318,12 @@ namespace VAR.PdfTools
|
|||||||
{
|
{
|
||||||
foreach (char c in text)
|
foreach (char c in text)
|
||||||
{
|
{
|
||||||
_textWidth += _font.GetCharWidth(c) * _fontSize;
|
string realChar = _font.ToUnicode(c);
|
||||||
|
if (realChar == "\0") { continue; }
|
||||||
|
_listCharacters.Add(new PdfCharElement { Char = _font.ToUnicode(c), Displacement = _textWidth, });
|
||||||
|
double charWidth = _font.GetCharWidth(c) * _fontSize;
|
||||||
|
_textWidth += charWidth;
|
||||||
|
_textWidth += ((c == 0x20) ? _wordSpacing : _charSpacing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -374,7 +340,7 @@ namespace VAR.PdfTools
|
|||||||
else if (elem is PdfInteger || elem is PdfReal)
|
else if (elem is PdfInteger || elem is PdfReal)
|
||||||
{
|
{
|
||||||
double spacing = PdfElementUtils.GetReal(elem, 0);
|
double spacing = PdfElementUtils.GetReal(elem, 0);
|
||||||
_textWidth += spacing;
|
_textWidth -= (spacing / 1000) * _fontSize;
|
||||||
}
|
}
|
||||||
else if (elem is PdfArray)
|
else if (elem is PdfArray)
|
||||||
{
|
{
|
||||||
@@ -387,11 +353,14 @@ namespace VAR.PdfTools
|
|||||||
|
|
||||||
#region Private methods
|
#region Private methods
|
||||||
|
|
||||||
private void ProcessPage()
|
private void ProcessPageContent()
|
||||||
{
|
{
|
||||||
foreach (PdfContentAction action in _page.ContentActions)
|
int unknowCount = 0;
|
||||||
|
for (int i = 0; i < _page.ContentActions.Count; i++)
|
||||||
{
|
{
|
||||||
// Graphics Operations
|
PdfContentAction action = _page.ContentActions[i];
|
||||||
|
|
||||||
|
// Special graphics state
|
||||||
if (action.Token == "q")
|
if (action.Token == "q")
|
||||||
{
|
{
|
||||||
OpPushGraphState();
|
OpPushGraphState();
|
||||||
@@ -422,11 +391,13 @@ namespace VAR.PdfTools
|
|||||||
}
|
}
|
||||||
else if (action.Token == "Tc")
|
else if (action.Token == "Tc")
|
||||||
{
|
{
|
||||||
// FIXME: Char spacing
|
double charSpacing = PdfElementUtils.GetReal(action.Parameters[0], 0);
|
||||||
|
OpTextCharSpacing(charSpacing);
|
||||||
}
|
}
|
||||||
else if (action.Token == "Tw")
|
else if (action.Token == "Tw")
|
||||||
{
|
{
|
||||||
// FIXME: Word spacing
|
double wordSpacing = PdfElementUtils.GetReal(action.Parameters[0], 0);
|
||||||
|
OpTextWordSpacing(wordSpacing);
|
||||||
}
|
}
|
||||||
else if (action.Token == "Tz")
|
else if (action.Token == "Tz")
|
||||||
{
|
{
|
||||||
@@ -434,7 +405,7 @@ namespace VAR.PdfTools
|
|||||||
}
|
}
|
||||||
else if (action.Token == "Tf")
|
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);
|
double fontSize = PdfElementUtils.GetReal(action.Parameters[1], 0);
|
||||||
OpTextFont(fontName, fontSize);
|
OpTextFont(fontName, fontSize);
|
||||||
}
|
}
|
||||||
@@ -455,14 +426,14 @@ namespace VAR.PdfTools
|
|||||||
{
|
{
|
||||||
double x = PdfElementUtils.GetReal(action.Parameters[0], 0);
|
double x = PdfElementUtils.GetReal(action.Parameters[0], 0);
|
||||||
double y = PdfElementUtils.GetReal(action.Parameters[1], 0);
|
double y = PdfElementUtils.GetReal(action.Parameters[1], 0);
|
||||||
OpTesDisplace(x, y);
|
OpTextDisplace(x, y);
|
||||||
}
|
}
|
||||||
else if (action.Token == "TD")
|
else if (action.Token == "TD")
|
||||||
{
|
{
|
||||||
double x = PdfElementUtils.GetReal(action.Parameters[0], 0);
|
double x = PdfElementUtils.GetReal(action.Parameters[0], 0);
|
||||||
double y = PdfElementUtils.GetReal(action.Parameters[1], 0);
|
double y = PdfElementUtils.GetReal(action.Parameters[1], 0);
|
||||||
OpTextLeading(-y);
|
OpTextLeading(-y);
|
||||||
OpTesDisplace(x, y);
|
OpTextDisplace(x, y);
|
||||||
}
|
}
|
||||||
else if (action.Token == "Tm")
|
else if (action.Token == "Tm")
|
||||||
{
|
{
|
||||||
@@ -480,78 +451,248 @@ namespace VAR.PdfTools
|
|||||||
}
|
}
|
||||||
else if (action.Token == "Tj")
|
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 == "'")
|
else if (action.Token == "'")
|
||||||
{
|
{
|
||||||
|
string text = PdfElementUtils.GetString(action.Parameters[0], string.Empty);
|
||||||
OpTextLineFeed();
|
OpTextLineFeed();
|
||||||
OpTextPut(((PdfString)action.Parameters[0]).Value);
|
OpTextPut(text);
|
||||||
}
|
}
|
||||||
else if (action.Token == "\"")
|
else if (action.Token == "\"")
|
||||||
{
|
{
|
||||||
double wordSpacing = PdfElementUtils.GetReal(action.Parameters[0], 0);
|
double wordSpacing = PdfElementUtils.GetReal(action.Parameters[0], 0);
|
||||||
double charSpacing = PdfElementUtils.GetReal(action.Parameters[1], 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")
|
else if (action.Token == "TJ")
|
||||||
{
|
{
|
||||||
OpTextPutMultiple(((PdfArray)action.Parameters[0]));
|
OpTextPutMultiple(((PdfArray)action.Parameters[0]));
|
||||||
}
|
}
|
||||||
|
else if (action.Token == "re")
|
||||||
|
{
|
||||||
|
// FIXME: Interpret this
|
||||||
|
}
|
||||||
|
else if (action.Token == "f")
|
||||||
|
{
|
||||||
|
// FIXME: Interpret this
|
||||||
|
}
|
||||||
|
else if (action.Token == "g")
|
||||||
|
{
|
||||||
|
// FIXME: Interpret this
|
||||||
|
}
|
||||||
|
else if (action.Token == "rg")
|
||||||
|
{
|
||||||
|
// FIXME: Interpret this
|
||||||
|
}
|
||||||
|
else if (action.Token == "BI")
|
||||||
|
{
|
||||||
|
// FIXME: Interpret this
|
||||||
|
}
|
||||||
|
else if (action.Token == "ID")
|
||||||
|
{
|
||||||
|
// FIXME: Interpret this
|
||||||
|
}
|
||||||
|
else if (action.Token == "EI")
|
||||||
|
{
|
||||||
|
// FIXME: Interpret this
|
||||||
|
}
|
||||||
|
else if (action.Token == "W")
|
||||||
|
{
|
||||||
|
// FIXME: Interpret this
|
||||||
|
}
|
||||||
|
else if (action.Token == "n")
|
||||||
|
{
|
||||||
|
// FIXME: Interpret this
|
||||||
|
}
|
||||||
|
else if (action.Token == "Do")
|
||||||
|
{
|
||||||
|
// FIXME: Interpret this
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unknowCount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FlushTextElement();
|
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 neighbourXMin = neighbour.GetX();
|
||||||
|
double neighbourXMax = neighbourXMin + neighbour.VisibleWidth;
|
||||||
|
double auxBlockXMin = blockXMin - elem.FontSize;
|
||||||
|
double auxBlockXMax = blockXMax + elem.FontSize;
|
||||||
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public methods
|
#region Public methods
|
||||||
|
|
||||||
public List<string> GetColumn(string column)
|
public List<string> GetColumn(string column)
|
||||||
{
|
{
|
||||||
PdfTextElement columnHead = FindElementByText(column);
|
return GetColumn(column, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<string> GetColumn(string column, bool fuzzy)
|
||||||
|
{
|
||||||
|
PdfTextElement columnHead = FindElementByText(column, fuzzy);
|
||||||
if (columnHead == null)
|
if (columnHead == null)
|
||||||
{
|
{
|
||||||
return new List<string>();
|
return new List<string>();
|
||||||
}
|
}
|
||||||
double headY = columnHead.GetY();
|
double headY = columnHead.GetY();
|
||||||
|
double headX1 = columnHead.GetX();
|
||||||
|
double headX2 = headX1 + columnHead.VisibleWidth;
|
||||||
|
|
||||||
// Get all the elements that intersects vertically and sort
|
// Determine horizontal extent
|
||||||
var columnData = new List<PdfTextElement>();
|
double extentX1 = double.MinValue;
|
||||||
|
double extentX2 = double.MaxValue;
|
||||||
|
foreach (PdfTextElement elem in _textElements)
|
||||||
|
{
|
||||||
|
if (elem == columnHead) { continue; }
|
||||||
|
if (TextElementHorizontalIntersection(columnHead, elem) == false) { continue; }
|
||||||
|
double elemX1 = elem.GetX();
|
||||||
|
double elemX2 = elemX1 + elem.VisibleWidth;
|
||||||
|
|
||||||
|
if (elemX2 < headX1)
|
||||||
|
{
|
||||||
|
if (elemX2 > extentX1)
|
||||||
|
{
|
||||||
|
extentX1 = elemX2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (elemX1 > headX2)
|
||||||
|
{
|
||||||
|
if (elemX1 < extentX2)
|
||||||
|
{
|
||||||
|
extentX2 = elemX1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all the elements that intersects vertically, are down and sort results
|
||||||
|
var columnDataRaw = new List<PdfTextElement>();
|
||||||
foreach (PdfTextElement elem in _textElements)
|
foreach (PdfTextElement elem in _textElements)
|
||||||
{
|
{
|
||||||
if (TextElementVerticalIntersection(columnHead, elem) == false) { continue; }
|
if (TextElementVerticalIntersection(columnHead, elem) == false) { continue; }
|
||||||
|
|
||||||
|
// Only intems down the column
|
||||||
double elemY = elem.GetY();
|
double elemY = elem.GetY();
|
||||||
if (elemY >= headY) { continue; }
|
if (elemY >= headY) { continue; }
|
||||||
|
|
||||||
|
columnDataRaw.Add(elem);
|
||||||
|
}
|
||||||
|
columnDataRaw = columnDataRaw.OrderByDescending(elem => elem.GetY()).ToList();
|
||||||
|
|
||||||
|
// Only items completelly inside extents, amd break on the first element outside
|
||||||
|
var columnData = new List<PdfTextElement>();
|
||||||
|
foreach (PdfTextElement elem in columnDataRaw)
|
||||||
|
{
|
||||||
|
double elemX1 = elem.GetX();
|
||||||
|
double elemX2 = elemX1 + elem.VisibleWidth;
|
||||||
|
if (elemX1 < extentX1 || elemX2 > extentX2) { break; }
|
||||||
|
|
||||||
columnData.Add(elem);
|
columnData.Add(elem);
|
||||||
}
|
}
|
||||||
columnData = columnData.OrderByDescending(elem => elem.GetY()).ToList();
|
|
||||||
|
|
||||||
// Filter only nearest elements
|
// Emit result
|
||||||
var result = new List<string>();
|
var result = new List<string>();
|
||||||
double prevY = headY;
|
|
||||||
double medDiff = 0;
|
|
||||||
bool first = true;
|
|
||||||
foreach (PdfTextElement elem in columnData)
|
foreach (PdfTextElement elem in columnData)
|
||||||
{
|
{
|
||||||
double elemY = elem.GetY();
|
|
||||||
double diff = prevY - elemY;
|
|
||||||
prevY = elemY;
|
|
||||||
if (first)
|
|
||||||
{
|
|
||||||
first = false;
|
|
||||||
medDiff = diff;
|
|
||||||
}
|
|
||||||
if (diff > medDiff) { break; }
|
|
||||||
medDiff = (medDiff + diff) / 2;
|
|
||||||
|
|
||||||
result.Add(elem.VisibleText);
|
result.Add(elem.VisibleText);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetField(string column)
|
public string GetField(string field)
|
||||||
{
|
{
|
||||||
PdfTextElement fieldTitle = FindElementByText(column);
|
return GetField(field, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetField(string field, bool fuzzy)
|
||||||
|
{
|
||||||
|
PdfTextElement fieldTitle = FindElementByText(field, fuzzy);
|
||||||
if (fieldTitle == null)
|
if (fieldTitle == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -577,6 +718,17 @@ namespace VAR.PdfTools
|
|||||||
return fieldData.OrderBy(elem => elem.GetX()).FirstOrDefault().VisibleText;
|
return fieldData.OrderBy(elem => elem.GetX()).FirstOrDefault().VisibleText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool HasText(string text)
|
||||||
|
{
|
||||||
|
return HasText(text, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasText(string text, bool fuzzy)
|
||||||
|
{
|
||||||
|
List<PdfTextElement> list = FindElementsContainingText(text, fuzzy);
|
||||||
|
return (list.Count > 0);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("VAR")]
|
[assembly: AssemblyCompany("VAR")]
|
||||||
[assembly: AssemblyProduct("VAR.PdfTools")]
|
[assembly: AssemblyProduct("VAR.PdfTools")]
|
||||||
[assembly: AssemblyCopyright("Copyright © VAR 2016")]
|
[assembly: AssemblyCopyright("Copyright © VAR 2016-2017")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
[assembly: Guid("eb7e003a-6a95-4002-809f-926c7c8a11e9")]
|
[assembly: Guid("eb7e003a-6a95-4002-809f-926c7c8a11e9")]
|
||||||
[assembly: AssemblyVersion("1.0.*")]
|
[assembly: AssemblyVersion("1.3.*")]
|
||||||
|
|||||||
@@ -11,44 +11,88 @@
|
|||||||
<AssemblyName>VAR.PdfTools</AssemblyName>
|
<AssemblyName>VAR.PdfTools</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<TargetFrameworkProfile />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug .Net 4.6.1|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
<OutputPath>bin\Debug\net461</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release .Net 4.6.1|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
<OutputPath>bin\Release\net461</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug .Net 3.5|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\net35</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release .Net 3.5|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\net35</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Net.Http" />
|
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Maths\Matrix3x3.cs" />
|
||||||
<Compile Include="PdfContentAction.cs" />
|
<Compile Include="PdfContentAction.cs" />
|
||||||
<Compile Include="PdfDocument.cs" />
|
<Compile Include="PdfDocument.cs" />
|
||||||
<Compile Include="PdfDocumentPage.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="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="PdfParser.cs" />
|
||||||
<Compile Include="PdfStandar14FontMetrics.cs" />
|
<Compile Include="PdfStandar14FontMetrics.cs" />
|
||||||
<Compile Include="PdfTextExtractor.cs" />
|
<Compile Include="PdfTextExtractor.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Maths\Vector3D.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="NuGet\keep.txt" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="Build.NuGet.cmd" />
|
||||||
|
<None Include="packages.config" />
|
||||||
|
<None Include="VAR.PdfTools.nuspec" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|||||||
22
VAR.PdfTools/VAR.PdfTools.nuspec
Normal file
22
VAR.PdfTools/VAR.PdfTools.nuspec
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<package >
|
||||||
|
<metadata>
|
||||||
|
<id>$id$</id>
|
||||||
|
<version>$version$</version>
|
||||||
|
<title>$title$</title>
|
||||||
|
<authors>$author$</authors>
|
||||||
|
<owners>$author$</owners>
|
||||||
|
<licenseUrl>https://github.com/Kableado/VAR.PdfTools/blob/master/LICENSE.txt</licenseUrl>
|
||||||
|
<projectUrl>https://github.com/Kableado/VAR.PdfTools</projectUrl>
|
||||||
|
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||||
|
<description>$description$</description>
|
||||||
|
<copyright>Copyright VAR 2016-2017</copyright>
|
||||||
|
<tags>PDF Library</tags>
|
||||||
|
</metadata>
|
||||||
|
<files>
|
||||||
|
<file src="bin\Release\net461\VAR.PdfTools.dll" target="lib\net461\VAR.PdfTools.dll" />
|
||||||
|
<file src="bin\Release\net461\VAR.PdfTools.pdb" target="lib\net461\VAR.PdfTools.pdb" />
|
||||||
|
<file src="bin\Release\net35\VAR.PdfTools.dll" target="lib\net35\VAR.PdfTools.dll" />
|
||||||
|
<file src="bin\Release\net35\VAR.PdfTools.pdb" target="lib\net35\VAR.PdfTools.pdb" />
|
||||||
|
</files>
|
||||||
|
</package>
|
||||||
4
VAR.PdfTools/packages.config
Normal file
4
VAR.PdfTools/packages.config
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="NuGet.CommandLine" version="3.4.3" targetFramework="net461" developmentDependency="true" />
|
||||||
|
</packages>
|
||||||
Reference in New Issue
Block a user