DynaPDF.SetOCGState
-------------------

Changes the visibility state of an OCG or layer.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [DynaPDF](component_DynaPDF.md) | [9.1](newinversion91.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "DynaPDF.SetOCGState"; PDF; Handle; On { ; SaveState } ) 

**MBS**( **"DynaPDF.SetOCGState";** /\* Changes the visibility state of an OCG or layer. \*/  
**$PDF**; /\* The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). \*/   
**$Handle**; /\* The OCG handle.  
Index from 0 to [DynaPDF.GetOCGCount](DynaPDFGetOCGCount.md)-1.e.g. $OCG \*/   
**$On**; /\* Wished state: 1 = visible, 0 = invisiblee.g. 1 \*/   
**$SaveState**) /\* Optional; Whether to save the state in the PDF file?  
Pass 1 to save or 0 to only switch temporarly.  
Default 0.e.g. 1 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| PDF | The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). | $pdf |  |
| Handle | The OCG handle.   Index from 0 to [DynaPDF.GetOCGCount](DynaPDFGetOCGCount.md)-1. | $OCG |  |
| On | Wished state: 1 = visible, 0 = invisible | 1 |  |
| SaveState | Whether to save the state in the PDF file?   Pass 1 to save or 0 to only switch temporarly.   Default 0. | 1 | Optional |

### Result

Returns OK or error.

### Description

Changes the visibility state of an OCG or layer.   
If the parameter SaveState is 1, the new state is also saved in the PDF file. Otherwise, the state is only changed temporarily so that the wished state can be rendered with [DynaPDF.RenderPage](DynaPDFRenderPage.md) or [DynaPDF.RenderPDFFile](DynaPDFRenderPDFFile.md) for example.   
Note that only the new state of the current OCG will be be saved. If the state of other OCGs were changed beforehand, while SaveState was set to 0, then these changes will not be considered.   
See also [SetOCGState](https://www.monkeybreadsoftware.com/DynaPDF-Manual/SetOCGState.shtml) function in DynaPDF manual.

### See also

- [DynaPDF.CreateOCG](DynaPDFCreateOCG.md)
- [DynaPDF.GetOCG](DynaPDFGetOCG.md)
- [DynaPDF.GetOCGCount](DynaPDFGetOCGCount.md)
- [DynaPDF.LockLayer](DynaPDFLockLayer.md)
- [DynaPDF.New](DynaPDFNew.md)
- [DynaPDF.RenderPage](DynaPDFRenderPage.md)
- [DynaPDF.RenderPDFFile](DynaPDFRenderPDFFile.md)
- [DynaPDF.SetAnnotDate](DynaPDFSetAnnotDate.md)
- [DynaPDF.SetExtGState](DynaPDFSetExtGState.md)

### Release notes

- **Version 9.1**
    - Added [DynaPDF.GetOCG](http://www.mbsplugins.eu/DynaPDFGetOCG.shtml), [DynaPDF.GetOCGContUsage](http://www.mbsplugins.eu/DynaPDFGetOCGContUsage.shtml), [DynaPDF.GetOCGCount](http://www.mbsplugins.eu/DynaPDFGetOCGCount.shtml), [DynaPDF.GetOCGUsageUserName](http://www.mbsplugins.eu/DynaPDFGetOCGUsageUserName.shtml) and [DynaPDF.SetOCGState](http://www.mbsplugins.eu/DynaPDFSetOCGState.shtml) functions for PDF layers.

### Blog Entries

- [Unlocking the Power of PDFs in FileMaker with DynaPDF and the MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2024-09-16/Unlocking_the_Power_of_PDFs_in/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 9.1pr4](https://www.mbsplugins.de/archive/2019-02-25/MBS_FileMaker_Plugin_version_9/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 18th February 2019 , last changed 18th February 2019

  
[DynaPDF.SetNumberFormat](DynaPDFSetNumberFormat.md) - [DynaPDF.SetOpacity](DynaPDFSetOpacity.md)

[HTML Version](DynaPDFSetOCGState.shtml)