You can export an original drawing to a monochrome or grayscale PDF file
by setting the color policy of the PDFExportParams class.
The color policy can be set with the method
setColorPolicy().
To retrieve the current color policy, use the
colorPolicy() method.
To represent the color policy, the
ColorPolicy
enumeration is used:
kNoPolicy — No color policy is used. A drawing is exported with its native
color palette (as-is). This is the default value.
kMono — Drawing is exported to a monochrome PDF file.
kGrayscale — Drawing is exported to a grayscale PDF file. Native colors
are converted into grayscale.
A monochrome PDF file can also be produced by setting a monochrome plot style
to the layout of the original drawing. This converts a colored drawing into
a monochrome PDF file.
A plot style is a file containing rules that determine how the colors of a
drawing should be converted, in this case into monochrome, i.e., which gray gradient
that each color must be replaced with. To export to monochrome, specify the path
to the plot style file(s) so the export process can access them.
The path to a monochrome plot style file can be set via the DDPLOTSTYLEPATHS
system variable, and then the plot style can be applied to one of the drawing layouts. Note that the findFile() method of your application services should be able to search the files in DDPLOTSTYLEPATHS folders too.
bool bMonochrome(false);
// Validator creates stylesheets equal to .ctb, .stb files. It's fully depends on DDPLOTSTYLEPATHS env var.
OdDbPlotSettingsValidatorPtr pValidator = svcs.plotSettingsValidator();
// Get database plot style mode: color-dependent or named
int i = pDb->getPSTYLEMODE();
OdString strMono((i == 1) ? "monochrome.ctb" : "monochrome.stb");
if(bMonoPalette)
{
OdArray <const OdChar*> PSSlist ;
pValidator->plotStyleSheetList(PSSlist);
unsigned int iSize = PSSlist.size();
if (iSize == 0)
{
STD(cout) << "Monochrome mode required files: monochrome.ctb, monochrome.stb to be found. Now exiting." << STD(endl);
return 2;
}
const OdChar* mono = strMono.c_str();
for(unsigned int i = 0; i < iSize; ++i)
{
if (*mono == *PSSlist[i])
{
bMonochrome = true;
break;
}
}
}
if (bMonochrome)
{
OdDbDictionaryPtr pLayoutDict = pDb->getLayoutDictionaryId().safeOpenObject();
for(unsigned f=0; f < params.layouts().size(); ++f)
{
OdDbLayoutPtr pLayout = pLayoutDict->getAt(params.layouts()[f]).safeOpenObject(OdDb::kForWrite);
pValidator->setCurrentStyleSheet((OdDbPlotSettings*)pLayout, strMono);
}
}
Also, the resolution of the monochrome images for the output PDF file can be specified;
the setBWImagesDPI()
method is used to set the resolution, and
bwImagesDPI()
is used to get the current resolution.
Exporting a drawing to a monochrome or grayscale PDF file using plot styles has several disadvantages:
When using plot styles, there is a dependency on color-dependent or named
plot style mode, which is applied to the original drawing; therefore, it is
not possible to guarantee a successful export.
A plot style file (.ctb) can be missing.
A plot style cannot be applied to some types of entities (pictures, underlays,
OLE objects, and some types of hatches). This can lead to confusing results (as
illustrated in the picture below):
Plot styles are supported for ODA Drawings (.dwg files) but can be unsupported for other ODA products and formats.
Export to monochrome mode is not supported on non-Windows platforms.