Skip to content

Commit

Permalink
New features
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel-A-Sokolov committed Oct 12, 2023
1 parent f32683c commit 55b6198
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ productName: GroupDocs.Viewer for Java
hideChildren: False
toc: True
---
Due to the numerous resources and `.class` files in the JAR file, the `MANIFEST.MF` file has become huge. For instance, it iss approximately 19.7 Mb for GroupDocs.Viewer v21.2 and 22.5 Mb for GroupDocs.Viewer v23.7.
Due to the numerous resources and `.class` files in the JAR file, the `MANIFEST.MF` file has become huge. For instance, it is approximately 19.7 Mb for GroupDocs.Viewer v21.2 and 22.5 Mb for GroupDocs.Viewer v23.7.

That is why you may get errors similar to the one below:

Expand All @@ -21,7 +21,13 @@ The issue arises from Java's file size limit, which is set at 8,000,000 bytes by


{{< tabs "example1">}}
{{< tab "Settings" >}}
{{< tab "Windows" >}}
```sh
SET MAVEN_OPTS="-Djdk.jar.maxSignatureFileSize=25000000"
mvn clean compile spring-boot:run
```
{{< /tab >}}
{{< tab "Linux" >}}
```sh
export MAVEN_OPTS="-Djdk.jar.maxSignatureFileSize=25000000"
mvn clean compile spring-boot:run
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
id: loading-external-resources
url: viewer/net/loading-external-resources
title: Loading of external resources containing by a document
weight: 5
keywords: set timeout, Groupdocs.Viewer
description: "This article explains how to manage loading of external resources contained by a document with GroupDocs.Viewer within your .NET applications."
productName: GroupDocs.Viewer for .NET
hideChildren: False
---

If the document contains external resources, such as images, GroupDocs.Viewer loads them when rendering a document. This allows the document to display correctly, but is a potential security risk.

GroupDocs.Viewer allows you to manage loading of external resources contained by a document. These features are supported for the [Word Processing File Formats](https://docs.fileformat.com/word-processing/).

Use the [LoadOptions](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/loadoptions) object to manage loading of external resources.

## Skip loading of external resources

The following code snippet shows how to deny loading of external resources:

{{< tabs "example3">}}
{{< tab "C#" >}}
```csharp
LoadOptions loadOptions = new LoadOptions();
loadOptions.SkipExternalResources = true; // Skip loading of external resources
using (Viewer viewer = new Viewer("business-flyer.docx", loadOptions))
{
HtmlViewOptions viewOptions =
HtmlViewOptions.ForEmbeddedResources();

viewer.View(viewOptions);
}
```
{{< /tab >}}
{{< /tabs >}}

## Manage a safelist for loading external resources

The following code snippet shows how to allow loading of external resources from specific URLs:

{{< tabs "example2">}}
{{< tab "C#" >}}
```csharp
LoadOptions loadOptions = new LoadOptions();
loadOptions.SkipExternalResources = true; // Skip loading of all external resources
loadOptions.WhitelistedResources.Add("avatars.githubusercontent.com"); //Enable loading of external resources that has `avatars.githubusercontent.com` fragment in resource URL.
using (Viewer viewer = new Viewer("business-flyer.docx", loadOptions))
{
HtmlViewOptions viewOptions =
HtmlViewOptions.ForEmbeddedResources();

viewer.View(viewOptions);
}
```
{{< /tab >}}
{{< /tabs >}}

## Set timeout for loading of external resources

The default timeout is 30 seconds. GroupDocs.Viewer allows you to change this value.

The following code snippet shows how to set a timeout to load external resources:

{{< tabs "example1">}}
{{< tab "C#" >}}
```csharp
// Specify a timeout.
LoadOptions loadOptions = new LoadOptions();
loadOptions.ResourceLoadingTimeout = TimeSpan.FromSeconds(5);
// Render a file.
using (Viewer viewer = new Viewer("sample.docx", loadOptions))
{
HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();
viewer.View(viewOptions);
}
```
{{< /tab >}}
{{< /tabs >}}

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,41 @@ using (var viewer = new Viewer("Products.xlsx"))

The image below illustrates the result. The output PDF file contains one page that displays all worksheet data.

![Fit sheet on one page](/viewer/net/images/rendering-basics/render-spreadsheets/render-on-one-page.png)
![Fit sheet on one page](/viewer/net/images/rendering-basics/render-spreadsheets/render-on-one-page.png)

## Render worksheet by page breaks and print area

GroupDocs.Viewer uses page breaks to split a worksheet into separate pages. Microsoft Excel adds automatic page breaks based on paper size and page settings, but you can also insert manual horizontal and vertical page breaks. Switch to **Page Break Preview** in Microsoft Excel to see where page breaks appear on a worksheet.

Also, you can designate one or more cell ranges in a worksheet as the only region to print (a _print area_). A worksheet can contain multiple print areas. Each print area prints on its own page.

When printing, Microsoft Excel splits a worksheet into pages using both page breaks and print areas. In the following image the red line shows the print area, and the blue line shows page breaks:

![Specify page breaks and a print area in Microsoft Excel](/viewer/net/images/rendering-basics/render-spreadsheets/page-breake-vs-print-area.png)

GroupDocs.Viewer also supports this option. Call the [SpreadsheetOptions.ForRenderingPrintAreaAndPageBreaks](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/spreadsheetoptions/methods/forrenderingprintareaandpagebreaks) static method and assign the returned `SpreadsheetOptions` instance to the [ViewOptions.SpreadsheetOptions](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/baseviewoptions/properties/spreadsheetoptions) property to display only the worksheet's print area in the output HTML, PDF, or image file.

The following example renders the Microsoft Excel spreadsheet using page breaks and print areas displayed in the image above to PDF:

{{< tabs "example4">}}
{{< tab "C#" >}}
```csharp
using GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
// ...
//render spreadsheet to PDF
using (var viewer = new Viewer("products.xlsx"))
{
var viewOptions = new PdfViewOptions("output.pdf");
viewOptions.SpreadsheetOptions = SpreadsheetOptions.ForRenderingPrintAreaAndPageBreaks();
viewer.View(viewOptions);
}
```
{{< /tab >}}
{{< /tabs >}}

The image below illustrates the result:

![Render page breaks and a print area to PDF](/viewer/net/images/rendering-basics/render-spreadsheets/pdf-result.png)

0 comments on commit 55b6198

Please sign in to comment.