Skip to content

Commit

Permalink
Merge pull request #11 from groupdocs-viewer/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
Ali Ahmed Sahi committed Jun 29, 2017
2 parents 018b4b8 + a17c39c commit 0ce5b15
Show file tree
Hide file tree
Showing 29 changed files with 193 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="GroupDocs.Viewer, Version=17.5.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56, processorArchitecture=MSIL">
<HintPath>..\..\packages\groupdocs-viewer-dotnet.17.5.0\lib\GroupDocs.Viewer.dll</HintPath>
<Reference Include="GroupDocs.Viewer, Version=17.6.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56, processorArchitecture=MSIL">
<HintPath>..\..\packages\groupdocs-viewer-dotnet.17.6.0\lib\GroupDocs.Viewer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.KeyVault.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ static void Main(string[] args)
//Render hidden pages in Visio file in image form
//ViewGenerator.RenderHiddenPagesOfVisioAsImage("sample.vdx");

//Get text coordinates in image based rendering
//ViewGenerator.GetTextCorrdinates("sample.docx");

#endregion

#region GeneralRepresentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,9 @@ public static void RenderLargeDocumentAsHtml(String DocumentName, String Documen
#endregion

#region ImageRepresentation

/// <summary>
/// Render simple document in image representation
/// Renders simple document in image representation
/// </summary>
/// <param name="DocumentName">File name</param>
/// <param name="DocumentPassword">Optional</param>
Expand Down Expand Up @@ -739,8 +740,9 @@ public static void RenderDocumentAsImages(String DocumentName, String DocumentPa
//ExEnd:RenderAsImage

}

/// <summary>
/// Render document in image representation with watermark
/// Renders document in image representation with watermark
/// </summary>
/// <param name="DocumentName">file/document name</param>
/// <param name="WatermarkText">watermark text</param>
Expand Down Expand Up @@ -780,8 +782,9 @@ public static void RenderDocumentAsImages(String DocumentName, String WatermarkT
}
//ExEnd:RenderAsImageWithWaterMark
}

/// <summary>
/// Render the document in image form and set the rotation angle to rotate the page while display.
/// Renders the document in image form and set the rotation angle to rotate the page while display.
/// </summary>
/// <param name="DocumentName"></param>
/// <param name="RotationAngle">rotation angle in digits</param>
Expand Down Expand Up @@ -821,8 +824,9 @@ public static void RenderDocumentAsImages(String DocumentName, int RotationAngle
}
//ExEnd:RenderAsImageWithRotationTransformation
}

/// <summary>
/// document in image representation and reorder a page
/// Renders document in image representation and reorder a page
/// </summary>
/// <param name="DocumentName">file/document name</param>
/// <param name="CurrentPageNumber">Page existing order number</param>
Expand Down Expand Up @@ -863,8 +867,9 @@ public static void RenderDocumentAsImages(String DocumentName, int CurrentPageNu
}
//ExEnd:RenderAsImageAndReorderPage
}

/// <summary>
/// Render a document in image representation whom located at web/remote location.
/// Renders a document in image representation whom located at web/remote location.
/// </summary>
/// <param name="DocumentURL">URL of the document</param>
/// <param name="DocumentPassword">Password Parameter is optional</param>
Expand Down Expand Up @@ -896,7 +901,7 @@ public static void RenderDocumentAsImages(Uri DocumentURL, String DocumentPasswo
}

/// <summary>
/// Render hidden pages of Visio file as image.
/// Renders hidden pages of Visio file as image.
/// </summary>
/// <param name="DocumentName">file/document name</param>
public static void RenderHiddenPagesOfVisioAsImage(string DocumentName)
Expand Down Expand Up @@ -931,7 +936,7 @@ public static void RenderHiddenPagesOfVisioAsImage(string DocumentName)
}

/// <summary>
/// Render CAD document in image representation
/// Renders CAD document in image representation
/// </summary>
/// <param name="DocumentName">File name</param>
public static void RenderCADAsImages(String DocumentName)
Expand Down Expand Up @@ -962,6 +967,74 @@ public static void RenderCADAsImages(String DocumentName)
}
//ExEnd:RenderCADAsImages

}

/// <summary>
/// Gets text coordinates in image mode. It is used when adding text search functionality in images.
/// </summary>
/// <param name="DocumentName">File name</param>
public static void GetTextCorrdinates(String DocumentName)
{
//ExStart:GetTextCorrdinates
//Get Configurations
ViewerConfig config = Utilities.GetConfigurations();

// Create image handler
ViewerImageHandler imageHandler = new ViewerImageHandler(config);

// Guid implies that unique document name
string guid = DocumentName;

// Init viewer image handler
ViewerImageHandler viewerImageHandler = new ViewerImageHandler(config);

//Get document rendered as an image with text extraction enabled
ImageOptions imageOptions = new ImageOptions();
imageOptions.ExtractText = true;
List<PageImage> pages = viewerImageHandler.GetPages(guid, imageOptions);

//Get document info
DocumentInfoOptions documentInfoOptions = new DocumentInfoOptions();
documentInfoOptions.ExtractText = true;
DocumentInfoContainer documentInfoContainer = viewerImageHandler.GetDocumentInfo(guid, documentInfoOptions);

// Go through all pages
foreach (PageData pageData in documentInfoContainer.Pages)
{
Console.WriteLine("Page number: " + pageData.Number);

//Go through all page rows
for (int i = 0; i < pageData.Rows.Count; i++)
{
RowData rowData = pageData.Rows[i];

// Write data to console
Console.WriteLine("Row: " + (i + 1));
Console.WriteLine("Text: " + rowData.Text);
Console.WriteLine("Text width: " + rowData.LineWidth);
Console.WriteLine("Text height: " + rowData.LineHeight);
Console.WriteLine("Distance from left: " + rowData.LineLeft);
Console.WriteLine("Distance from top: " + rowData.LineTop);

// Get words
string[] words = rowData.Text.Split(' ');

// Go through all word coordinates
for (int j = 0; j < words.Length; j++)
{
int coordinateIndex = j == 0 ? 0 : j + 1;

// Write data to console
Console.WriteLine(string.Empty);
Console.WriteLine("Word: '" + words[j] + "'");
Console.WriteLine("Word distance from left: " + rowData.TextCoordinates[coordinateIndex]);
Console.WriteLine("Word width: " + rowData.TextCoordinates[coordinateIndex + 1]);
Console.WriteLine(string.Empty);
}
}
}
//ExEnd:GetTextCorrdinates

}
#endregion

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="groupdocs-viewer-dotnet" version="17.5.0" targetFramework="net40-Client" />
<package id="groupdocs-viewer-dotnet" version="17.6.0" targetFramework="net40-Client" />
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net40" />
<package id="Microsoft.Data.Edm" version="5.6.4" targetFramework="net40" />
<package id="Microsoft.Data.OData" version="5.6.4" targetFramework="net40" />
<package id="Microsoft.Data.Services.Client" version="5.6.4" targetFramework="net40" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net40" />
<package id="System.Spatial" version="5.6.4" targetFramework="net40" />
<package id="WindowsAzure.Storage" version="6.2.0" targetFramework="net40" />
<package id="WindowsAzure.Storage" version="6.2.0" targetFramework="net40" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Namespace GroupDocs.Viewer.Examples
Dim emptyDate As New DateTime(1, 1, 1)
Return If(dateTimeOffset.HasValue, dateTimeOffset.Value.DateTime, emptyDate)
End Function
<Obsolete>
Public Sub AddFile(guid As String, content As Stream) Implements IInputDataHandler.AddFile
'TODO
End Sub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Namespace GroupDocs.Viewer.Examples
target = value
Return value
End Function

<Obsolete>
Public Sub AddFile(guid As String, content As Stream) Implements IInputDataHandler.AddFile
'TODO
End Sub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<ItemGroup>
<Reference Include="GroupDocs.Viewer, Version=17.5.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56, processorArchitecture=MSIL">
<HintPath>..\packages\groupdocs-viewer-dotnet.17.5.0\lib\GroupDocs.Viewer.dll</HintPath>
<Reference Include="GroupDocs.Viewer, Version=17.6.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56, processorArchitecture=MSIL">
<HintPath>..\packages\groupdocs-viewer-dotnet.17.6.0\lib\GroupDocs.Viewer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.KeyVault.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down
2 changes: 2 additions & 0 deletions Examples/GroupDocs.Viewer.Examples.VisualBasic/Module1.vb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ Namespace GroupDocs.Viewer.Examples
'Render hidden pages in Visio file in image form
'ViewGenerator.RenderHiddenPagesOfVisioAsImage("sample.vdx")

'Get text coordinates in image based rendering
'ViewGenerator.GetTextCorrdinates("sample.docx")
'#End Region

'#Region "GeneralRepresentation"
Expand Down
79 changes: 68 additions & 11 deletions Examples/GroupDocs.Viewer.Examples.VisualBasic/ViewGenerator.vb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ Namespace GroupDocs.Viewer.Examples
Utilities.SaveAsHtml(page.PageNumber & "_" & DocumentName, page.HtmlContent)
Next
'ExEnd:RenderAsHtml
End Sub
End Sub

''' <summary>
''' Renders document in html representation with watermark
''' </summary>
Expand Down Expand Up @@ -458,7 +458,7 @@ Namespace GroupDocs.Viewer.Examples
'ExEnd:RenderExcelAsHtmlWithCountRowsPerPage

End Sub

''' <summary>
''' Renders PDF document into html with EnablePreciseRendering settings
''' </summary>
Expand Down Expand Up @@ -879,6 +879,71 @@ Namespace GroupDocs.Viewer.Examples
'ExEnd:RenderCADAsImages

End Sub

''' <summary>
''' Gets text coordinates in image mode. It is used when adding text search functionality in images.
''' </summary>
''' <param name="DocumentName">File name</param>
Public Shared Sub GetTextCorrdinates(DocumentName As [String])
'ExStart:GetTextCorrdinates
'Get Configurations
Dim config As ViewerConfig = Utilities.GetConfigurations()

' Create image handler
Dim imageHandler As New ViewerImageHandler(config)

' Guid implies that unique document name
Dim guid As String = DocumentName

' Init viewer image handler
Dim viewerImageHandler As New ViewerImageHandler(config)

'Get document rendered as an image with text extraction enabled
Dim imageOptions As New ImageOptions()
imageOptions.ExtractText = True
Dim pages As List(Of PageImage) = viewerImageHandler.GetPages(guid, imageOptions)

'Get document info
Dim documentInfoOptions As New DocumentInfoOptions()
documentInfoOptions.ExtractText = True
Dim documentInfoContainer As DocumentInfoContainer = viewerImageHandler.GetDocumentInfo(guid, documentInfoOptions)

' Go through all pages
For Each pageData As PageData In documentInfoContainer.Pages
Console.WriteLine("Page number: " + pageData.Number)

'Go through all page rows
For i As Integer = 0 To pageData.Rows.Count - 1
Dim rowData As RowData = pageData.Rows(i)

' Write data to console
Console.WriteLine("Row: " + (i + 1))
Console.WriteLine("Text: " + rowData.Text)
Console.WriteLine("Text width: " + rowData.LineWidth)
Console.WriteLine("Text height: " + rowData.LineHeight)
Console.WriteLine("Distance from left: " + rowData.LineLeft)
Console.WriteLine("Distance from top: " + rowData.LineTop)

' Get words
Dim words As String() = rowData.Text.Split(" "c)

' Go through all word coordinates
For j As Integer = 0 To words.Length - 1
Dim coordinateIndex As Integer = If(j = 0, 0, j + 1)

' Write data to console
Console.WriteLine(String.Empty)
Console.WriteLine("Word: '" + words(j) + "'")
Console.WriteLine("Word distance from left: " + rowData.TextCoordinates(coordinateIndex))
Console.WriteLine("Word width: " + rowData.TextCoordinates(coordinateIndex + 1))
Console.WriteLine(String.Empty)
Next
Next
Next

'ExEnd:GetTextCorrdinates

End Sub
#End Region

#Region "GeneralRepresentation"
Expand Down Expand Up @@ -1134,7 +1199,6 @@ Namespace GroupDocs.Viewer.Examples

#End Region


#Region "InputDataHandlers"

''' <summary>
Expand Down Expand Up @@ -1608,13 +1672,6 @@ Namespace GroupDocs.Viewer.Examples

#End Region





End Class



End Namespace

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="groupdocs-viewer-dotnet" version="17.5.0" targetFramework="net40" />
<package id="groupdocs-viewer-dotnet" version="17.6.0" targetFramework="net40" />
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net40" />
<package id="Microsoft.Data.Edm" version="5.6.4" targetFramework="net40" />
<package id="Microsoft.Data.OData" version="5.6.4" targetFramework="net40" />
<package id="Microsoft.Data.Services.Client" version="5.6.4" targetFramework="net40" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net40" />
<package id="System.Spatial" version="5.6.4" targetFramework="net40" />
<package id="WindowsAzure.Storage" version="6.2.0" targetFramework="net40" />
<package id="WindowsAzure.Storage" version="6.2.0" targetFramework="net40" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,10 @@ public ActionResult GetResourceForHtml(GetResourceForHtmlParameters parameters)
parameters.ResourceName.IndexOf("/", StringComparison.Ordinal) >= 0)
parameters.ResourceName = parameters.ResourceName.Replace("/", "");

var resource = new HtmlResource
var resource = new HtmlResource(parameters.ResourceName)
{
ResourceName = parameters.ResourceName,
ResourceType = Utils.GetResourceType(parameters.ResourceName),
//ResourceName = parameters.ResourceName,
//ResourceType = Utils.GetResourceType(parameters.ResourceName),
DocumentPageNumber = parameters.PageNumber
};
var stream = _htmlHandler.GetResource(parameters.DocumentPath, resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ protected void Application_Start()
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);


GroupDocs.Viewer.License lic = new GroupDocs.Viewer.License();
lic.SetLicense(_licensePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="GroupDocs.Viewer, Version=17.5.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56, processorArchitecture=MSIL">
<HintPath>..\packages\groupdocs-viewer-dotnet.17.5.0\lib\GroupDocs.Viewer.dll</HintPath>
<Reference Include="GroupDocs.Viewer, Version=17.6.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56, processorArchitecture=MSIL">
<HintPath>..\packages\groupdocs-viewer-dotnet.17.6.0\lib\GroupDocs.Viewer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<packages>
<package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
<package id="bootstrap" version="3.0.0" targetFramework="net45" />
<package id="groupdocs-viewer-dotnet" version="17.5.0" targetFramework="net45" />
<package id="groupdocs-viewer-dotnet" version="17.6.0" targetFramework="net45" />
<package id="jQuery" version="1.10.2" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
Expand Down
Loading

0 comments on commit 0ce5b15

Please sign in to comment.