diff --git a/python-net/_index.md b/python-net/_index.md index 952ef8a..771815e 100644 --- a/python-net/_index.md +++ b/python-net/_index.md @@ -14,8 +14,9 @@ AddLibInfoScript: True groupdocs-viewer-python-home -Nuget package -Nuget downloads +PyPI package +PyPI downloads {{< button style="primary" link="https://releases.groupdocs.com/viewer/python-net/release-notes/" >}} Release notes {{< /button >}} {{< button style="primary" link="https://pypi.org/project/groupdocs.viewer" >}} {{< icon "gdoc_download" >}} Package repository {{< /button >}} diff --git a/python-net/developer-guide/loading-documents/loading-documents-from-different-sources/load-document-from-local-disk.md b/python-net/developer-guide/loading-documents/loading-documents-from-different-sources/load-document-from-local-disk.md new file mode 100644 index 0000000..b91a3d8 --- /dev/null +++ b/python-net/developer-guide/loading-documents/loading-documents-from-different-sources/load-document-from-local-disk.md @@ -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 >}} diff --git a/python-net/developer-guide/loading-documents/loading-documents-from-different-sources/loading-documents-from-stream/_index.md b/python-net/developer-guide/loading-documents/loading-documents-from-different-sources/loading-documents-from-stream/_index.md new file mode 100644 index 0000000..180233a --- /dev/null +++ b/python-net/developer-guide/loading-documents/loading-documents-from-different-sources/loading-documents-from-stream/_index.md @@ -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: \ No newline at end of file diff --git a/python-net/developer-guide/loading-documents/loading-documents-from-different-sources/loading-documents-from-stream/load-document-from-url.md b/python-net/developer-guide/loading-documents/loading-documents-from-different-sources/loading-documents-from-stream/load-document-from-url.md new file mode 100644 index 0000000..a475d9f --- /dev/null +++ b/python-net/developer-guide/loading-documents/loading-documents-from-different-sources/loading-documents-from-stream/load-document-from-url.md @@ -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 >}}