DynaPDF.SetColorSpace
---------------------

The function activates a device color space in the graphics state.

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

MBS( "DynaPDF.SetColorSpace"; PDF; Value ) 

**MBS**( **"DynaPDF.SetColorSpace";** /\* The function activates a device color space in the graphics state. \*/  
**$PDF**; /\* The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). \*/   
**$Value**) /\* The new colorspace. Can be DeviceRGB, DeviceCMYK or DeviceGray.e.g. "DeviceGray" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| PDF | The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). | $pdf |
| Value | The new colorspace. Can be DeviceRGB, DeviceCMYK or DeviceGray. | "DeviceGray" |

### Result

Returns OK on success or error message.

### Description

The function activates a device color space in the graphics state.   
All color values must be defined in the current color space. Images or EMF graphics are automatically converted to the current color space. The default color conversion rules can be modified with the function [DynaPDF.SetGStateFlags](DynaPDFSetGStateFlags.md).  
Extended color spaces can be set with [DynaPDF.SetExtColorSpace](DynaPDFSetExtColorSpace.md), [DynaPDF.SetExtFillColorSpace](DynaPDFSetExtFillColorSpace.md), and [DynaPDF.SetExtStrokeColorSpace](DynaPDFSetExtStrokeColorSpace.md).  
See also [DynaPDF.GetColorSpace](DynaPDFGetColorSpace.md).  
See also [SetColorSpace](https://www.monkeybreadsoftware.com/DynaPDF-Manual/SetColorSpace.shtml) function in DynaPDF manual.

### Examples

Set to RGB:

 MBS ( "DynaPDF.SetColorSpace"; $PDF ; "DeviceRGB" )  
Set to CMYK:

 MBS ( "DynaPDF.SetColorSpace"; $PDF ; "DeviceCMYK" )  
Write in CMYK:

 # switch to CMYK   
Set Variable \[$r ; Value:MBS ( "DynaPDF.SetColorSpace"; $pdf ; "DeviceCMYK" )\]  
\# set color to Cyan   
Set Variable \[$r ; Value:MBS ("[DynaPDF.SetFillColor](DynaPDFSetFillColor.md)"; $pdf ; 1; 0; 0; 0)\]  
\# Write some text   
Set Variable \[$r ; Value:MBS ("[DynaPDF.WriteText](DynaPDFWriteText.md)"; $pdf ; 100; $x ; "Some cyan text")\]  
\# now switch back to RGB   
Set Variable \[$r ; Value:MBS ( "DynaPDF.SetColorSpace"; $pdf ; "DeviceRGB" )\]  
### See also

- [DynaPDF.GetColorSpaceCount](DynaPDFGetColorSpaceCount.md)
- [DynaPDF.GetColorSpaceInfo](DynaPDFGetColorSpaceInfo.md)
- [DynaPDF.HighlightAnnot](DynaPDFHighlightAnnot.md)
- [DynaPDF.RGB](DynaPDFRGB.md)
- [DynaPDF.SetExtColorSpace](DynaPDFSetExtColorSpace.md)
- [DynaPDF.SetExtFillColorSpace](DynaPDFSetExtFillColorSpace.md)
- [DynaPDF.SetFillColor](DynaPDFSetFillColor.md)
- [DynaPDF.SetGStateFlags](DynaPDFSetGStateFlags.md)
- [DynaPDF.WriteFText](DynaPDFWriteFText.md)
- [DynaPDF.WriteFTextEx](DynaPDFWriteFTextEx.md)

### Example Databases

- [DynaPDF/Create PDF with Bezier Curves](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Create%20PDF%20with%20Bezier%20Curves.shtml#1ScriptAnchor_)
- [DynaPDF/Picture to PDF](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Picture%20to%20PDF.shtml#7ScriptAnchor_)
- [DynaPDF/Shrink PDF pages](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Shrink%20PDF%20pages.shtml#2ScriptAnchor_)
- [DynaPDF/Watermark pages](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Watermark%20pages.shtml#2ScriptAnchor_)

This function checks for a license.

Created 18th August 2014 , last changed 12nd November 2018

  
[DynaPDF.SetCheckBoxState](DynaPDFSetCheckBoxState.md) - [DynaPDF.SetCompressionFilter](DynaPDFSetCompressionFilter.md)

[HTML Version](DynaPDFSetColorSpace.shtml)