Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<PropertyGroup Label="Package Versions">
<GroupDocsViewer>25.3.0</GroupDocsViewer>
<GroupDocsViewer>25.4.0</GroupDocsViewer>

<MicrosoftExtensionsHttp>8.0.1</MicrosoftExtensionsHttp>
<MicrosoftExtensionsDependencyInjectionAbstractions>8.0.2</MicrosoftExtensionsDependencyInjectionAbstractions>
Expand All @@ -29,24 +29,24 @@
<SystemTextJson>8.0.5</SystemTextJson>

<AzureBlobs>12.24.0</AzureBlobs>
<AwsSdkS3>3.7.416.3</AwsSdkS3>
<AwsSdkS3>4.0.0.1</AwsSdkS3>

<MicrosoftSourceLinkGithub>8.0.0</MicrosoftSourceLinkGithub>
</PropertyGroup>

<PropertyGroup Label="GroupDocs.Viewer UI Package Versions">
<GroupDocsViewerUI>8.0.5</GroupDocsViewerUI>
<GroupDocsViewerUIApi>8.0.5</GroupDocsViewerUIApi>
<GroupDocsViewerUIApiLocalCache>8.0.5</GroupDocsViewerUIApiLocalCache>
<GroupDocsViewerUIApiInMemoryCache>8.0.5</GroupDocsViewerUIApiInMemoryCache>
<GroupDocsViewerUIApiLocalStorage>8.0.5</GroupDocsViewerUIApiLocalStorage>
<GroupDocsViewerUIApiCloudStorage>8.0.5</GroupDocsViewerUIApiCloudStorage>
<GroupDocsViewerUIApiAzureStorage>8.0.5</GroupDocsViewerUIApiAzureStorage>
<GroupDocsViewerUIApiAwsS3Storage>8.0.5</GroupDocsViewerUIApiAwsS3Storage>
<GroupDocsViewerUICore>8.0.5</GroupDocsViewerUICore>
<GroupDocsViewerUISelfHostApi>8.0.5</GroupDocsViewerUISelfHostApi>
<GroupDocsViewerUISelfHostApiCrossPlatform>8.0.5</GroupDocsViewerUISelfHostApiCrossPlatform>
<GroupDocsViewerUICloudApi>8.0.5</GroupDocsViewerUICloudApi>
<GroupDocsViewerUI>8.0.6</GroupDocsViewerUI>
<GroupDocsViewerUIApi>8.0.6</GroupDocsViewerUIApi>
<GroupDocsViewerUIApiLocalCache>8.0.6</GroupDocsViewerUIApiLocalCache>
<GroupDocsViewerUIApiInMemoryCache>8.0.6</GroupDocsViewerUIApiInMemoryCache>
<GroupDocsViewerUIApiLocalStorage>8.0.6</GroupDocsViewerUIApiLocalStorage>
<GroupDocsViewerUIApiCloudStorage>8.0.6</GroupDocsViewerUIApiCloudStorage>
<GroupDocsViewerUIApiAzureStorage>8.0.6</GroupDocsViewerUIApiAzureStorage>
<GroupDocsViewerUIApiAwsS3Storage>8.0.6</GroupDocsViewerUIApiAwsS3Storage>
<GroupDocsViewerUICore>8.0.6</GroupDocsViewerUICore>
<GroupDocsViewerUISelfHostApi>8.0.6</GroupDocsViewerUISelfHostApi>
<GroupDocsViewerUISelfHostApiCrossPlatform>8.0.6</GroupDocsViewerUISelfHostApiCrossPlatform>
<GroupDocsViewerUICloudApi>8.0.6</GroupDocsViewerUICloudApi>
</PropertyGroup>

<PropertyGroup Label="NuGet Common Settings">
Expand Down
2 changes: 1 addition & 1 deletion samples/GroupDocs.Viewer.UI.Cloud.Api.Sample/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<header>
<div class="header-content">
<a href="https://products.groupdocs.com/">
<img src="https://products.groupdocs.app/viewer/img-redesign/groupdocs.svg" alt="GroupDocs Logo" class="logo">
<img src="https://groupdocs-viewer.github.io/resources/image/groupdocs-logo.svg" alt="GroupDocs Logo" class="logo">
</a>
<a href="https://dashboard.groupdocs.cloud" target="_blank" class="trial-button">Start Free Trial</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<header>
<div class="header-content">
<a href="https://products.groupdocs.com/">
<img src="https://products.groupdocs.app/viewer/img-redesign/groupdocs.svg" alt="GroupDocs Logo" class="logo">
<img src="https://groupdocs-viewer.github.io/resources/image/groupdocs-logo.svg" alt="GroupDocs Logo" class="logo">
</a>
<a href="https://purchase.groupdocs.com/buy/cart?ppId=99940" target="_blank" class="trial-button">Start Free Trial</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<header>
<div class="header-content">
<a href="https://products.groupdocs.com/">
<img src="https://products.groupdocs.app/viewer/img-redesign/groupdocs.svg" alt="GroupDocs Logo" class="logo">
<img src="https://groupdocs-viewer.github.io/resources/image/groupdocs-logo.svg" alt="GroupDocs Logo" class="logo">
</a>
<a href="https://purchase.groupdocs.com/buy/cart?ppId=99940" target="_blank" class="trial-button">Start Free Trial</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
private const string API_ENDPOINT = "/";
private const string CONTENT_FOLDER = "Content";

//NOTE: Thumbnails are only used when rendering to HTML
private static bool CreateThumbnails => VIEWER_TYPE == ViewerType.HtmlWithEmbeddedResources
|| VIEWER_TYPE == ViewerType.HtmlWithExternalResources;

static async Task Main(string[] args)
{
Config apiConfig = new Config();
apiConfig.SetViewerType(VIEWER_TYPE);
//apiConfig.SetLicensePath("GroupDocs.Viewer.lic");
//apiConfig.SetLicensePath("c://Licenses//GroupDocs.Viewer.lic");

IFileStorage fileStorage = new LocalFileStorage(STORAGE_PATH);
IApiUrlBuilder urlBuilder = new StaticUrlBuilder(API_ENDPOINT);
Expand All @@ -43,8 +47,14 @@
FileCredentials fileCredentials = new FileCredentials(file.FilePath, extension, password);

int[] pageNumbers = await CreateViewData(viewer, fileCredentials, urlBuilder);

await CreatePagesAsync(viewer, fileCredentials, pageNumbers);
await CreateThumbsAsync(viewer, fileCredentials, pageNumbers);

if(CreateThumbnails)
{
await CreateThumbsAsync(viewer, fileCredentials, pageNumbers);
}

await CreatePdfAsync(viewer, fileCredentials);

Console.WriteLine(" Done.");
Expand Down Expand Up @@ -76,7 +86,7 @@
);
break;
case ViewerType.HtmlWithExternalResources:
viewer = new HtmlWithExternalResourcesViewer(

Check warning on line 89 in samples/GroupDocs.Viewer.UI.Sample.StaticContentMode.Generator/Program.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected

Check warning on line 89 in samples/GroupDocs.Viewer.UI.Sample.StaticContentMode.Generator/Program.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected
configOptions,
asyncLock,
licenseManager,
Expand All @@ -88,7 +98,7 @@
);
break;
case ViewerType.Jpg:
viewer = new JpgViewer(

Check warning on line 101 in samples/GroupDocs.Viewer.UI.Sample.StaticContentMode.Generator/Program.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected

Check warning on line 101 in samples/GroupDocs.Viewer.UI.Sample.StaticContentMode.Generator/Program.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected
configOptions,
asyncLock,
licenseManager,
Expand All @@ -99,7 +109,7 @@
);
break;
case ViewerType.Png:
viewer = new PngViewer(

Check warning on line 112 in samples/GroupDocs.Viewer.UI.Sample.StaticContentMode.Generator/Program.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected

Check warning on line 112 in samples/GroupDocs.Viewer.UI.Sample.StaticContentMode.Generator/Program.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected
configOptions,
asyncLock,
licenseManager,
Expand Down Expand Up @@ -157,7 +167,11 @@
foreach (PageInfo page in documentInfo.Pages)
{
var pageUrl = urlBuilder.BuildPageUrl(fileCredentials.FilePath, page.Number, viewer.PageExtension);
var thumbUrl = urlBuilder.BuildThumbUrl(fileCredentials.FilePath, page.Number, viewer.ThumbExtension);

var thumbUrl = CreateThumbnails
? urlBuilder.BuildThumbUrl(fileCredentials.FilePath, page.Number, viewer.ThumbExtension)
: null;

var pageData = new PageData(page.Number, page.Width, page.Height, pageUrl, thumbUrl);

pages.Add(pageData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<header>
<div class="header-content">
<a href="https://products.groupdocs.com/">
<img src="https://products.groupdocs.app/viewer/img-redesign/groupdocs.svg" alt="GroupDocs Logo" class="logo">
<img src="https://groupdocs-viewer.github.io/resources/image/groupdocs-logo.svg" alt="GroupDocs Logo" class="logo">
</a>
<a href="https://purchase.groupdocs.com/buy/cart?ppId=99940" target="_blank" class="trial-button">Start Free Trial</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion samples/GroupDocs.Viewer.UI.Sample.ViewAsPng/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<header>
<div class="header-content">
<a href="https://products.groupdocs.com/">
<img src="https://products.groupdocs.app/viewer/img-redesign/groupdocs.svg" alt="GroupDocs Logo" class="logo">
<img src="https://groupdocs-viewer.github.io/resources/image/groupdocs-logo.svg" alt="GroupDocs Logo" class="logo">
</a>
<a href="https://purchase.groupdocs.com/buy/cart?ppId=99940" target="_blank" class="trial-button">Start Free Trial</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion samples/GroupDocs.Viewer.UI.Sample/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<header>
<div class="header-content">
<a href="https://products.groupdocs.com/">
<img src="https://products.groupdocs.app/viewer/img-redesign/groupdocs.svg" alt="GroupDocs Logo" class="logo">
<img src="https://groupdocs-viewer.github.io/resources/image/groupdocs-logo.svg" alt="GroupDocs Logo" class="logo">
</a>
<a href="https://purchase.groupdocs.com/buy/cart?ppId=99940" target="_blank" class="trial-button">Start Free Trial</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<header>
<div class="header-content">
<a href="https://products.groupdocs.com/">
<img src="https://products.groupdocs.app/viewer/img-redesign/groupdocs.svg" alt="GroupDocs Logo" class="logo">
<img src="https://groupdocs-viewer.github.io/resources/image/groupdocs-logo.svg" alt="GroupDocs Logo" class="logo">
</a>
<a href="https://purchase.groupdocs.com/buy/cart?ppId=99940" target="_blank" class="trial-button">Start Free Trial</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Viewer API can be accessed at '/viewer-api' endpoint.");
await context.Response.WriteAsync("Viewer API can be accessed at '/document-viewer-api' endpoint.");
});

endpoints.MapGroupDocsViewerApi(options =>
Expand Down
56 changes: 52 additions & 4 deletions src/GroupDocs.Viewer.UI.API/Controllers/ViewerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ public async Task<IActionResult> ViewData([FromBody] ViewDataRequest request)

var docInfo = await _viewer.GetDocumentInfoAsync(file);
var pagesToCreate = GetPagesToCreate(docInfo.TotalPagesCount, _config.PreloadPages);

var pages = await CreateViewDataPages(file, docInfo, pagesToCreate);

var pages = _config.RenderingMode == RenderingMode.Html
? await CreateViewDataPagesAndThumbs(file, docInfo, pagesToCreate)
: await CreateViewDataPages(file, docInfo, pagesToCreate);

var searchTerm = await _searchTermResolver.ResolveSearchTermAsync(request.File);
var fileName = await _fileNameResolver.ResolveFileNameAsync(request.File);
Expand Down Expand Up @@ -161,7 +163,9 @@ public async Task<IActionResult> CreatePages([FromBody] CreatePagesRequest reque
var file = new FileCredentials(request.File, request.FileType, request.Password);
var docInfo = await _viewer.GetDocumentInfoAsync(file);

var pages = await CreatePagesAndThumbs(file, docInfo, request.Pages);
var pages = _config.RenderingMode == RenderingMode.Html
? await CreatePagesAndThumbs(file, docInfo, request.Pages)
: await CreatePages(file, docInfo, request.Pages);

return Ok(pages);
}
Expand Down Expand Up @@ -324,7 +328,7 @@ public async Task<IActionResult> GetResource([FromQuery] GetResourceRequest requ
}

// NOTE: This method returns all of the pages including created and not
private async Task<List<PageData>> CreateViewDataPages(FileCredentials file, DocumentInfo docInfo, int[] pagesToCreate)
private async Task<List<PageData>> CreateViewDataPagesAndThumbs(FileCredentials file, DocumentInfo docInfo, int[] pagesToCreate)
{
await _viewer.GetPagesAsync(file, pagesToCreate);

Expand Down Expand Up @@ -357,6 +361,32 @@ private async Task<List<PageData>> CreateViewDataPages(FileCredentials file, Doc
return pages;
}

// NOTE: This method returns all of the pages including created and not
private async Task<List<PageData>> CreateViewDataPages(FileCredentials file, DocumentInfo docInfo, int[] pagesToCreate)
{
await _viewer.GetPagesAsync(file, pagesToCreate);


var pages = new List<PageData>();
foreach (PageInfo page in docInfo.Pages)
{
var isPageCreated = pagesToCreate.Contains(page.Number);
if (isPageCreated)
{
var pageUrl = _apiUrlBuilder.BuildPageUrl(file.FilePath, page.Number, _viewer.PageExtension);
var pageData = new PageData(page.Number, page.Width, page.Height, pageUrl);

pages.Add(pageData);
}
else
{
pages.Add(new PageData(page.Number, page.Width, page.Height));
}
}

return pages;
}

// NOTE: This method returns only created pages
private async Task<List<PageData>> CreatePagesAndThumbs(FileCredentials file, DocumentInfo docInfo, int[] pagesToCreate)
{
Expand Down Expand Up @@ -384,6 +414,24 @@ private async Task<List<PageData>> CreatePagesAndThumbs(FileCredentials file, Do
return pages;
}

// NOTE: This method returns only created pages
private async Task<List<PageData>> CreatePages(FileCredentials file, DocumentInfo docInfo, int[] pagesToCreate)
{
await _viewer.GetPagesAsync(file, pagesToCreate);

var pages = new List<PageData>();
foreach (int pageNumber in pagesToCreate)
{
var page = docInfo.Pages.First(p => p.Number == pageNumber);
var pageUrl = _apiUrlBuilder.BuildPageUrl(file.FilePath, page.Number, _viewer.PageExtension);
var pageData = new PageData(page.Number, page.Width, page.Height, pageUrl);

pages.Add(pageData);
}

return pages;
}

private int[] GetPagesToCreate(int totalPageCount, int preloadPageCount)
{
if (preloadPageCount == 0)
Expand Down
4 changes: 2 additions & 2 deletions src/GroupDocs.Viewer.UI.Api.AwsS3.Storage/AwsS3FileStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ private static async Task<IEnumerable<FileSystemEntry>> ListingObjectsAsync(
.ForEach(obj =>
{
fileSystemEntries.Add(
FileSystemEntry.File(GetObjectName(obj.Key), obj.Key, obj.Size));
FileSystemEntry.File(GetObjectName(obj.Key), obj.Key, obj.Size.GetValueOrDefault()));
});

// If the response is truncated, set the request ContinuationToken
// from the NextContinuationToken property of the response.
request.ContinuationToken = response.NextContinuationToken;
} while (response.IsTruncated);
} while (response.IsTruncated.GetValueOrDefault());

return fileSystemEntries;
}
Expand Down
91 changes: 91 additions & 0 deletions src/GroupDocs.Viewer.UI.Api.AwsS3.Storage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# GroupDocs.Viewer.UI.Api.AwsS3.Storage

`GroupDocs.Viewer.UI.Api.AwsS3.Storage` is an Amazon S3 file storage implementation that can be used with `GroupDocs.Viewer.UI.Api`. It provides seamless integration with AWS S3 for storing and retrieving documents in your `GroupDocs.Viewer.UI` application.

## Installation

To use AWS S3 storage in your ASP.NET Core project:

1. Add the required package to your project:

```bash
dotnet add package GroupDocs.Viewer.UI.Api.AwsS3.Storage
```

2. Configure AWS S3 storage in your `Startup` class:

```cs
using Amazon.S3;

var builder = WebApplication.CreateBuilder(args);

builder.Services
.AddGroupDocsViewerUI();

builder.Services
.AddControllers()
.AddGroupDocsViewerSelfHostApi()
.AddAwsS3Storage(options =>
{
options.Region = "us-east-1"; // AWS region
options.BucketName = "your-bucket-name";
options.AccessKey = "your-access-key"; // Optional if using AWS credentials
options.SecretKey = "your-secret-key"; // Optional if using AWS credentials
options.S3Config = new AmazonS3Config
{
// Configure additional S3 client settings if needed
};
});

var app = builder.Build();

app
.UseRouting()
.UseEndpoints(endpoints =>
{
endpoints.MapGroupDocsViewerUI(options =>
{
options.UIPath = "/viewer";
options.ApiEndpoint = "/viewer-api";
});
endpoints.MapGroupDocsViewerApi(options =>
{
options.ApiPath = "/viewer-api";
});
});

await app.RunAsync();
```

## Configuration Options

The AWS S3 storage implementation supports the following configuration options:

- `Region` (Required): The AWS region where your S3 bucket is located (e.g., "us-east-1", "eu-west-1").
- `BucketName` (Required): The name of your S3 bucket.
- `AccessKey` (Optional): AWS access key. If not provided, the AWS SDK will use the default credential provider chain.
- `SecretKey` (Optional): AWS secret key. If not provided, the AWS SDK will use the default credential provider chain.
- `S3Config` (Optional): Additional configuration for the Amazon S3 client.

## AWS Credentials

You can provide AWS credentials in several ways:

1. **Explicit Configuration**:
```cs
options.AccessKey = "your-access-key";
options.SecretKey = "your-secret-key";
```

2. **Environment Variables**:
- `AWS_ACCESS_KEY_ID`
- `AWS_SECRET_ACCESS_KEY`

3. **AWS Credentials File**:
- Located at `~/.aws/credentials` (Linux/Mac) or `%UserProfile%\.aws\credentials` (Windows)

4. **Instance Profile** (when running on AWS EC2)

## License

This project is licensed under the MIT License - see the [LICENSE.txt](../../LICENSE.txt) file for details.
Loading