Skip to content

Commit

Permalink
Merge pull request #90 from groupdocs-viewer/python-net-cad-section
Browse files Browse the repository at this point in the history
Viewer for Python - Implemented CAD File processing, PDF Optimization Options and more.
  • Loading branch information
RakhimAimaganbetov authored Sep 26, 2024
2 parents 39009ca + 18df9df commit 81a8957
Show file tree
Hide file tree
Showing 52 changed files with 1,677 additions and 275 deletions.
4 changes: 2 additions & 2 deletions python-net/developer-guide/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ id: developer-guide
url: viewer/python-net/developer-guide
title: Developer Guide
weight: 4
description: "Explains GroupDocs.Viewer for Python file viewer features and shows how to view PDF, Word, Excel, PowerPoint documents inside your JavaScript applications"
keywords: GroupDocs.Viewer Developer Guide, GroupDocs.Viewer Java Developer Guide, GroupDocs.Viewer Developer Guide Java, Using GroupDocs.Viewer for Python, GroupDocs.Viewer for Python use cases
description: "Explains GroupDocs.Viewer for Python file viewer features and shows how to view PDF, Word, Excel, PowerPoint documents inside your Python applications"
keywords: GroupDocs.Viewer Developer Guide, GroupDocs.Viewer Python Developer Guide, GroupDocs.Viewer Developer Guide Python, Using GroupDocs.Viewer for Python, GroupDocs.Viewer for Python use cases
productName: GroupDocs.Viewer for Python via .NET
hideChildren: False
isMenuItemWithNoContent: True
Expand Down
46 changes: 28 additions & 18 deletions python-net/developer-guide/caching-results/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,34 @@ To enable caching, follow these steps:
The following code snippet shows how to enable caching and displays the difference between rendering a file and getting the cached results:

{{< tabs "example1">}}
{{< tab "JavaScript" >}}
```js
const cachePath = "cache";
const cache = new FileCache(cachePath);
const settings = new ViewerSettings(cache);

const viewer = new groupdocs.viewer.Viewer("sample.docx", settings)
const options = HtmlViewOptions.forEmbeddedResources();
const currentTimeMillis = Date.now()

viewer.view(options);
currentTimeMillis = Date.now() - currentTimeMillis
console.log("Time taken on first call to View method " + currentTimeMillis + " (ms).")
currentTimeMillis = Date.now()

viewer.view(options)
currentTimeMillis = Date.now() - currentTimeMillis
console.log("Time taken on second call to View method " + currentTimeMillis + " (ms).")
{{< tab "Python" >}}
```python
import time
import groupdocs.viewer as gv
import groupdocs.viewer.options as gvo

# Define a path to cache
cache_path = "cache"
cache = gv.FileCache(cache_path)
settings = gv.ViewerSettings(cache)

# Define a Viewer for a "sample.docx" file
with gv.Viewer("sample.docx", settings) as viewer:
options = gvo.HtmlViewOptions.for_embedded_resources()

# Define the execution time of the first call
start_time = time.time()
viewer.view(options)

elapsed_time = time.time() - start_time
print(f"Time taken on first call to View method {elapsed_time * 1000:.0f} (ms).")

# Define the execution time of the second call
start_time = time.time()
viewer.view(options)

elapsed_time = time.time() - start_time
print(f"Time taken on second call to View method {elapsed_time * 1000:.0f} (ms).")
```
{{< /tab >}}
{{< /tabs >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ hideChildren: False
---
To get and save attachments, follow these steps:

1. Instantiate the [Viewer](#) object. Specify a file that contains attachments.
2. Call the [getAttachments](#) method. It returns the attachment collection.
3. Iterate through the collection. To save an attachment, call the [saveAttachment](#) method.
1. Instantiate the [Viewer](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/) object. Specify a file that contains attachments.
2. Call the [get_attachments](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method. It returns the attachment collection.
3. Iterate through the collection. To save an attachment, call the [save_attachment](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method.

The following code snippet shows how to get and save all attachments from the MSG file:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@ hideChildren: False
---
To add a watermark to the HTML/JPG/PNG/PDF output, follow these steps:

1. Create an instance of the [HtmlViewOptions](#) class (or [PngViewOptions](#), or [JpgViewOptions](#), or [PdfViewOptions](#));
2. Create a [Watermark](#) object and populate its properties;
3. Call the [setWatermark](#) method of the [HtmlViewOptions](#) (or [PngViewOptions](#), or [JpgViewOptions](#), or [PdfViewOptions](#)) class and specify the object created on step 2;
4. Call the [Viewer.view()](#) method.
1. Create an instance of the [HtmlViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/) class (or [PngViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions/), or [JpgViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/jpgviewoptions/), or [PdfViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfviewoptions/));
2. Create a [Watermark](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/watermark/) object and populate its properties;
3. Call the [watermark](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/viewoptions/#properties) method of the [HtmlViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/) (or [PngViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions/), or [JpgViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/jpgviewoptions/), or [PdfViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfviewoptions/)) class and specify the object created on step 2;
4. Call the [Viewer.view()](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method.

The following code snippet shows how to apply the watermark to the output pages.

{{< tabs "example1">}}
{{< tab "JavaScript" >}}
```js
const viewer = new groupdocs.viewer.Viewer("sample.docx")
// Create an HTML file.
const viewOptions = groupdocs.viewer.HtmlViewOptions.forEmbeddedResources(output-watermark.html)
// Add watermark.
const watermark = new groupdocs.viewer.Watermark('This is a watermark')
viewOptions.setWatermark(watermark);
viewer.view(viewOptions)
{{< tab "Python" >}}
```python
with gv.Viewer("sample.docx") as viewer:
# Create an HTML file.
viewOptions = gvo.HtmlViewOptions.for_embedded_resources("output-watermark.html")
# Add watermark.
viewOptions.watermark = gvo.Watermark("This is a watermark")
viewer.view(viewOptions)
```
{{< /tab >}}
{{< /tabs >}}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ GroupDocs.Viewer for Python provides two options to manage CSS, fonts, images, a

To render files to HTML, follow these steps:

1. Create an instance of the [Viewer](#) class. Specify the source document path as a constructor parameter.
2. Instantiate the [HtmlViewOptions](#) object. Specify a path to save the rendered pages.
3. Call the [View.view()](#) method of the [Viewer](#) object. Specify the [HtmlViewOptions](#) object as the parameter.
1. Create an instance of the [Viewer](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/) class. Specify the source document path as a constructor parameter.
2. Instantiate the [HtmlViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/) object. Specify a path to save the rendered pages.
3. Call the [View.view()](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method of the [Viewer](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/) object. Specify the [HtmlViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/) object as the parameter.

## Rendering to HTML with external resources

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ When rendering to PDF, GroupDocs.Viewer renders all pages of the source document

To render files to PDF, follow these steps:

1. Create an instance of the [Viewer](#) class. Specify the source document path as a constructor parameter.
2. Instantiate the [PdfViewOptions](#) object. Specify a path to save the rendered file.
3. Call the [View.view()](#) method of the [Viewer](#) object. Specify the [PdfViewOptions](#) object as the parameter.
1. Create an instance of the [Viewer](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/) class. Specify the source document path as a constructor parameter.
2. Instantiate the [PdfViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfviewoptions/) object. Specify a path to save the rendered file.
3. Call the [View.view()](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method of the [Viewer](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/) object. Specify the [PdfViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfviewoptions/) object as the parameter.

The following code snippet shows how to render a .docx document to PDF:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
id: adjust-jpeg-images-quality
url: viewer/python-net/adjust-jpeg-images-quality
title: Specify the JPEG image quality
weight: 3
description: "Adjust JPEG images quality when rendering documents to PDF with GroupDocs.Viewer for Python via .NET"
productName: GroupDocs.Viewer for Python via .NET
hideChildren: False
---
Decreasing the JPG images quality reduces the size of the output file.

To adjust images quality, set the [image_quality](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfoptimizationoptions/#properties) property of the [PdfViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfoptimizationoptions/) class. The value must be between 1 (minimum quality) and 100. The default value is 90.

To set the image quality, follow these steps:

1. Instantiate the [Viewer](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer) class. Specify the source document path as a constructor parameter.
1. Instantiate the [PdfViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfviewoptions) object.
2. Set the [PdfViewOptions.pdf_optimization_options](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfviewoptions/#properties) value as instantiated [PdfOptimizationOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfoptimizationoptions/) object.
3. Set the [PdfViewOptions.pdf_optimization_options.image_quality](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfoptimizationoptions/#properties) value.
4. Call the [view](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method of the [Viewer](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer) object. Specify the [PdfViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfviewoptions) object as the parameter.

The following code snippet shows how to adjust JPG image quality in the output PDF document:

{{< tabs "example1">}}
{{< tab "Python" >}}
```python
with gv.Viewer("sample.docx") as viewer:
# Create view options.
viewOptions = gvo.PdfViewOptions()

# Specify the JPG image quality.
pdf_optimization_options = gvo.PdfOptimizationOptions()
pdf_optimization_options.image_quality = 50
# Specify pdf_optimization_options object
viewOptions.pdf_optimization_options = pdf_optimization_options

viewer.view(viewOptions)
```
{{< /tab >}}
{{< /tabs >}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
id: optimization-pdf-options
url: viewer/python-net/optimization-pdf-options
title: Optimize the output PDF file
linkTitle: Optimize the output PDF file
weight: 6
description: "This topic describes how to optimize PDF file in the GroupDocs.Viewer Python API for web browser or to reduce size."
keywords: convert to pdf, optimize size, optimize browser, optimize web, pdf reduce size
productName: GroupDocs.Viewer for Python via .NET
hideChildren: False
toc: True
---
GroupDocs.Viewer allows you to optimize the output PDF file for a web browser or to reduce the file size by optimizing resources.

Optimization for a web allows a browser to display the first pages of a PDF file when you open the document, instead of waiting for the entire file to download.

Resource optimization allows you to reduce the size of the output PDF file. While optimizing, GroupDocs.Viewer may reduce the image size or quality, remove notes or form fields, remove objects, fonts, or personal information from a document, and so on.

You can also optimize an existing PDF file. To do this, open it, specify the optimization parameters, and save the output file.


Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
id: optimization-pdf-for-web
url: viewer/python-net/optimization-pdf-for-web
title: Optimize a PDF file for a browser
linkTitle: Optimize a PDF file for a browser
weight: 1
description: "This topic describes how to optimize PDF file using the GroupDocs.Viewer Python API for web browser or to reduce size."
keywords: convert to pdf, optimize browser, optimize web
productName: GroupDocs.Viewer for Python via .NET
hideChildren: False
toc: True
---
This optimization allows a browser to display the first pages of a PDF file when you open the document, instead of waiting for the entire file to download.

The following code snippet shows how to optimize a PDF file for browser:
{{< tabs "Example1">}}
{{< tab "Python" >}}
```python
with gv.Viewer("sample.docx") as viewer:

viewOptions = gvo.PdfViewOptions()
viewOptions.pdf_optimization_options = gvo.PdfOptimizationOptions()
viewOptions.pdf_optimization_options.lineriaze = True

viewer.view(viewOptions)
```
{{< /tab >}}
{{< /tabs >}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
id: optimization-pdf-resources
url: viewer/python-net/optimization-pdf-resources
title: Optimize the PDF file resources
linkTitle: Optimize the PDF file resources
weight: 2
description: "This topic describes how to optimize PDF file using the GroupDocs.Viewer Python API to reduce size."
keywords: convert to pdf, optimize size, pdf reduce size
productName: GroupDocs.Viewer for Python via .NET
hideChildren: False
toc: True
---
Resource optimization allows you to reduce the size of the output PDF file. While optimizing, GroupDocs.Viewer may reduce the image size or quality, remove notes or form fields, remove objects, fonts, or personal information from a document, and so on.

The following code snippet shows how to optimize the PDF file by default:

{{< tabs "Example1">}}
{{< tab "Python" >}}
```python
with gv.Viewer("sample.docx") as viewer:

viewOptions = gvo.PdfViewOptions()
viewOptions.pdf_optimization_options = gvo.PdfOptimizationOptions()

viewer.view(viewOptions)
```
{{< /tab >}}
{{< /tabs >}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
id: optimization-pdf-spreadsheets
url: viewer/python-net/optimization-pdf-spreadsheets
title: Optimize spreadsheets in a PDF file
linkTitle: Optimize spreadsheets in a PDF file
weight: 3
description: "This topic describes how to optimize spreadsheets in a PDF file using the GroupDocs.Viewer Python API."
keywords: convert to pdf, optimize browser, optimize web
productName: GroupDocs.Viewer for Python via .NET
hideChildren: False
toc: True
---
This optimization allows to reduce the output file size by setting up border lines. Besides that, it removes the Arial and Times New Roman characters of 32-127 codes.

The default value is `False`.


The following code snippet shows how to optimize spreadsheets in a PDF file:

{{< tabs "Example1">}}
{{< tab "Python" >}}
```python
with gv.Viewer("invoice.xlsx") as viewer:

viewOptions = gvo.PdfViewOptions()
viewOptions.pdf_optimization_options = gvo.PdfOptimizationOptions()
viewOptions.pdf_optimization_options.optimize_spreadsheets = True

viewer.view(viewOptions)
```
{{< /tab >}}
{{< /tabs >}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
id: optimize-content
url: viewer/python-net/optimize-content
title: Optimize content
weight: 5
description: "Optimize content of a PDF file using GroupDocs.Viewer for Python via .NET "
productName: GroupDocs.Viewer for Python via .NET
hideChildren: False
isMenuItemWithNoContent: True
---

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
id: optimization-pdf-remove-annotations
url: viewer/python-net/optimization-pdf-remove-annotations
title: Remove annotations
linkTitle: Remove annotations
weight: 1
description: "This topic describes how to remove annotations from PDF file using the GroupDocs.Viewer Python API."
keywords: convert to pdf, optimize size, pdf reduce size, remove annotations
productName: GroupDocs.Viewer for Python via .NET
hideChildren: False
toc: True
---
If the output PDF file contains annotations, you can remove them to reduce the file size.

To remove annotations, set the [remove_annotations](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfoptimizationoptions/#properties) property to `True`.

The following code snippet shows how to remove annotations from the file:

{{< tabs "Example1">}}
{{< tab "Python" >}}
```python
with gv.Viewer("sample.docx") as viewer:

viewOptions = gvo.PdfViewOptions()
viewOptions.pdf_optimization_options = gvo.PdfOptimizationOptions()
viewOptions.pdf_optimization_options.remove_annotations = True

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

The following image demonstrates the result:

![Remove annotations](/viewer/net/images/developer-guide/pdf-rendering/optimization/optimization-pdf-remove-annotations.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
id: optimization-pdf-remove-fields
url: viewer/python-net/optimization-pdf-remove-fields
title: Remove form fields
linkTitle: Remove form fields
weight: 2
description: "This topic describes how to remove form fields from PDF file using the GroupDocs.Viewer Python API."
keywords: convert to pdf, optimize size, pdf reduce size, remove fields
productName: GroupDocs.Viewer for Python via .NET
hideChildren: False
toc: True
---
If the output PDF file contains form fields, you can flatten them to reduce the file size.

To remove form fields, set the [remove_form_fields](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfoptimizationoptions/#properties) property to `True`.

The following code snippet shows how to flatten form fields in the file:

{{< tabs "Example1">}}
{{< tab "Python" >}}
```python
with gv.Viewer("sample.docx") as viewer:

viewOptions = gvo.PdfViewOptions()
viewOptions.pdf_optimization_options = gvo.PdfOptimizationOptions()
viewOptions.pdf_optimization_options.remove_form_fields = True

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

The following image demonstrates the result:

![Remove fields](/viewer/net/images/developer-guide/pdf-rendering/optimization/optimization-pdf-remove-fields.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
id: optimize-fonts
url: viewer/python-net/optimize-fonts
title: Optimize fonts
weight: 6
description: "Optimize fonts in a PDF file using GroupDocs.Viewer for Python via .NET"
productName: GroupDocs.Viewer for Python via .NET
hideChildren: False
isMenuItemWithNoContent: True
---

Loading

0 comments on commit 81a8957

Please sign in to comment.