Chapter 16
Optional Content Groups

cpdf -ocg-list in.pdf

cpdf -ocg-rename -ocg-rename-from <a> -ocg-rename-to <b> in.pdf -o out.pdf

cpdf -ocg-order-all in.pdf -o out.pdf

cpdf -ocg-coalesce-on-name in.pdf -o out.pdf

In a PDF file, optional content groups are used to group graphical elements together, so they may appear or not, depending on the preference of the user. They are similar in some ways to layers in graphics illustration programs.

cpdf -ocg-list in.pdf

List the optional content groups in the PDF, one per line, to standard output. UTF8.

cpdf -ocg-rename -ocg-rename-from <a> -ocg-rename-to <b> in.pdf -o out.pdf

Rename an optional content group.

cpdf -ocg-coalesce-on-name in.pdf -o out.pdf

Coalesce optional content groups. For example, if we merge or stamp two files both with an OCG called ”Layer 1”, we will have two different optional content groups. Running -ocg-coalesce-on-name will merge the two into a single optional content group.

cpdf -ocg-order-all in.pdf -o out.pdf

Ensure that every optional content group appears in the order list.

C Interface

 
/* CHAPTER 16. Optional Content Groups */ 
 
/* Begin retrieving optional content group names. The serial number 0..<n - 1> 
 * is returned. */ 
int cpdf_startGetOCGList(int pdf); 
 
/* Retrieve an OCG name, given its serial number 0..<n - 1>. */ 
char *cpdf_OCGListEntry(int i); 
 
/* End retrieval of optional content group names. */ 
void cpdf_endGetOCGList(void); 
 
/* cpdf_OCGRename(pdf, from, to) will rename an optional content group. */ 
void cpdf_OCGRename(int, const char[], const char[]); 
 
/* Ensure that every optional content group appears in the OCG order list. */ 
void cpdf_OCGOrderAll(int); 
 
/* Coalesce optional content groups. For example, if we merge or stamp two 
 * files both with an OCG called "Layer 1", we will have two different optional 
 * content groups. This function will merge the two into a single optional 
 * content group. */ 
void cpdf_OCGCoalesce(int);