-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Loading Documents examples and update the shields label
- Loading branch information
1 parent
75d673a
commit 490d33a
Showing
4 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ments/loading-documents-from-different-sources/load-document-from-local-disk.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
id: load-document-from-local-disk | ||
url: viewer/python-net/load-document-from-local-disk | ||
title: Load document using the local path string | ||
weight: 1 | ||
description: "This article explains how to load a document using the local path string with GroupDocs.Viewer within your Python applications." | ||
productName: GroupDocs.Viewer for Python via .NET | ||
hideChildren: False | ||
--- | ||
You can load a document from a local disk using a path to a file. GroupDocs.Viewer opens the file in the read-only mode. | ||
|
||
The following code snippet shows how to load a document using the local path string: | ||
|
||
{{< tabs "example1">}} | ||
{{< tab "Python" >}} | ||
```python | ||
with gv.Viewer("sample.docx") as viewer: | ||
html_options = gvo.HtmlViewOptions.for_embedded_resources("page_{0}.html") | ||
viewer.view(html_options) | ||
``` | ||
{{< /tab >}} | ||
{{< /tabs >}} |
32 changes: 32 additions & 0 deletions
32
...oading-documents-from-different-sources/loading-documents-from-stream/_index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
id: load-document-from-stream | ||
url: viewer/python-net/load-document-from-stream | ||
title: Load from stream | ||
weight: 2 | ||
description: "This article explains how to load a document from a Stream with GroupDocs.Viewer within your Python applications." | ||
productName: GroupDocs.Viewer for Python via .NET | ||
hideChildren: False | ||
--- | ||
You can load a document from a stream without saving it as a file on a disk. You can use this feature to load a document from different sources like a URL, FTP, and so on. | ||
|
||
To load a document from a stream, follow these steps: | ||
|
||
1. Implement a method to get the document stream. | ||
2. Call the [Viewer](https://reference.groupdocs.com/python-net/viewer/groupdocs.viewer/viewer) class constructor. Specify the method implemented in the previous step. | ||
|
||
The following code snippet shows how to load a document from a stream: | ||
|
||
{{< tabs "example1">}} | ||
{{< tab "Python" >}} | ||
```python | ||
stream = open("sample.docx", "rb") | ||
|
||
# Render a document from the stream. | ||
with gv.Viewer(stream) as viewer: | ||
options = gvo.HtmlViewOptions.for_embedded_resources("page_{0}.html") | ||
viewer.view(options) | ||
``` | ||
{{< /tab >}} | ||
{{< /tabs >}} | ||
|
||
Please refer to the following pages for examples: |
38 changes: 38 additions & 0 deletions
38
...-from-different-sources/loading-documents-from-stream/load-document-from-url.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
id: load-document-from-url | ||
url: viewer/python-net/load-document-from-url | ||
title: Load from URL | ||
weight: 3 | ||
description: "This article explains how to load a document from a URL with GroupDocs.Viewer within your Python applications." | ||
productName: GroupDocs.Viewer for Python via .NET | ||
hideChildren: False | ||
--- | ||
The following code snippet shows how to load a document from a URL: | ||
|
||
{{< tabs "example1">}} | ||
{{< tab "Python" >}} | ||
```python | ||
import requests | ||
import io | ||
|
||
def download_file(url): | ||
response = requests.get(url, stream=True, headers={"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0"}, timeout=10) | ||
# Check if the request was successful (status code 200) | ||
response.raise_for_status() | ||
# Create a BytesIO stream from the content | ||
stream = io.BytesIO(response.content) | ||
return stream | ||
|
||
|
||
url = "https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-.NET/blob/master/Examples/GroupDocs.Viewer.Examples.CSharp/Resources/SampleFiles/sample.docx?raw=true"; | ||
|
||
stream = download_file(url) | ||
|
||
with gv.Viewer(stream) as viewer: | ||
options = gvo.HtmlViewOptions.for_embedded_resources("page_{0}.html") | ||
viewer.view(options) | ||
|
||
|
||
``` | ||
{{< /tab >}} | ||
{{< /tabs >}} |