



Collapse AllThis method creates an optional content group in a PDF document.
These content groups are optional document layers that can be visible or invisible. Select View -> Navigation Tabs -> Layers in your Adobe Reader to find these groups and change their visibility.
Syntax| LONG CreateContentGroup ( BSTR groupName ) |
Remarks
Example{ PDF object is supposed to be created }
{ Draw main document layer }
fnt := PDF.AddBuiltInFont(bfHelvetica, false, false);
PDF.UseFont(fnt, 16);
W := PDF.PageWidth;
H := PDF.PageHeight;
PDF.SetColorFill(0.8, 0.8, 0.8, 0);
PDF.DrawRectangle(10, 10, W-20, H-20, 0);
PDF.Fill;
PDF.SetColorFill(0, 0, 0, 0);
PDF.ShowTextAt(30, 30, 'This is our document with text, graphics and so on...');
PDF.SetColorFill(0.9, 0.9, 0.9, 0);
PDF.MoveTo(30, 50);
PDF.DrawLineTo(W-30, 50);
PDF.DrawLineTo(30, H-50);
PDF.DrawLineTo(W-30, H-50);
PDF.DrawLineTo(30, 50);
PDF.FillAndStroke;
PDF.SetColorFill(0, 0, 0, 0);
{ Create 1st content group }
groupIndex1 := PDF.CreateContentGroup('grpText');
PDF.BeginMarkedContent(groupIndex1);
PDF.DrawRectangle(45, 95, 270, 65, 0);
PDF.Stroke;
PDF.ShowTextAt(50, 100, 'This is an optional content group #1.');
PDF.ShowTextAt(50, 120, 'It contains text.');
PDF.ShowTextAt(50, 140, 'It is initially visible.');
PDF.EndMarkedContent;
{ Create 2nd content group }
long groupIndex2 = PDF.CreateContentGroup('grpGraphics');
PDF.BeginMarkedContent(groupIndex2);
PDF.DrawRectangle(45, 240, 400, 300, 0);
PDF.Stroke;
PDF.ShowTextAt(50, 250, 'This is an optional content group #2.');
PDF.ShowTextAt(50, 270, 'It contains graphics.');
PDF.ShowTextAt(50, 290, 'It is initially invisible.');
PDF.SetLineWidth(4);
PDF.SetColorStroke(0, 0, 0.5, 0);
PDF.DrawCircle(150, 370, 50);
PDF.MoveTo(250, 350);
PDF.DrawCurveTo(300, 550, 350, 350, 400, 500);
PDF.Stroke;
PDF.EndMarkedContent;
{ Set 1st group visible and 2nd invisible }
PDF.SetContentGroupState(groupIndex1, true);
PDF.SetContentGroupState(groupIndex2, false);
PDF.SaveToFile('PdfWithContentGroups.pdf', true);
// PDF object is supposed to be created
// Draw main document layer
long fnt = PDF->AddBuiltInFont(bfHelvetica, FALSE, FALSE);
PDF->UseFont(fnt, 16);
long W = PDF->PageWidth;
long H = PDF->PageHeight;
PDF->SetColorFill(0.8, 0.8, 0.8, 0);
PDF->DrawRectangle(10, 10, W-20, H-20, 0);
PDF->Fill();
PDF->SetColorFill(0, 0, 0, 0);
PDF->ShowTextAt(30, 30, "This is our document with text, graphics and so on...");
PDF->SetColorFill(0.9, 0.9, 0.9, 0);
PDF->MoveTo(30, 50);
PDF->DrawLineTo(W-30, 50);
PDF->DrawLineTo(30, H-50);
PDF->DrawLineTo(W-30, H-50);
PDF->DrawLineTo(30, 50);
PDF->FillAndStroke();
PDF->SetColorFill(0, 0, 0, 0);
// Create 1st content group
long groupIndex1 = PDF->CreateContentGroup("grpText");
PDF->BeginMarkedContent(groupIndex1);
PDF->DrawRectangle(45, 95, 270, 65, 0);
PDF->Stroke();
PDF->ShowTextAt(50, 100, "This is an optional content group #1.");
PDF->ShowTextAt(50, 120, "It contains text.");
PDF->ShowTextAt(50, 140, "It is initially visible.");
PDF->EndMarkedContent();
// Create 2nd content group
long groupIndex2 = PDF->CreateContentGroup("grpGraphics");
PDF->BeginMarkedContent(groupIndex2);
PDF->DrawRectangle(45, 240, 400, 300, 0);
PDF->Stroke();
PDF->ShowTextAt(50, 250, "This is an optional content group #2.");
PDF->ShowTextAt(50, 270, "It contains graphics.");
PDF->ShowTextAt(50, 290, "It is initially invisible.");
PDF->SetLineWidth(4);
PDF->SetColorStroke(0, 0, 0.5, 0);
PDF->DrawCircle(150, 370, 50);
PDF->MoveTo(250, 350);
PDF->DrawCurveTo(300, 550, 350, 350, 400, 500);
PDF->Stroke();
PDF->EndMarkedContent();
// Set 1st group visible and 2nd invisible
PDF->SetContentGroupState(groupIndex1, TRUE);
PDF->SetContentGroupState(groupIndex2, FALSE);
PDF->SaveToFile("PdfWithContentGroups.pdf", true);
// PDF object is supposed to be created
// Draw main document layer
long fnt = PDF.AddBuiltInFont(BuiltInFont.bfHelvetica, false, false);
PDF.UseFont(fnt, 16);
long W = PDF.PageWidth;
long H = PDF.PageHeight;
PDF.SetColorFill(0.8, 0.8, 0.8, 0);
PDF.DrawRectangle(10, 10, W-20, H-20, 0);
PDF.Fill();
PDF.SetColorFill(0, 0, 0, 0);
PDF.ShowTextAt(30, 30, "This is our document with text, graphics and so on...");
PDF.SetColorFill(0.9, 0.9, 0.9, 0);
PDF.MoveTo(30, 50);
PDF.DrawLineTo(W-30, 50);
PDF.DrawLineTo(30, H-50);
PDF.DrawLineTo(W-30, H-50);
PDF.DrawLineTo(30, 50);
PDF.FillAndStroke();
PDF.SetColorFill(0, 0, 0, 0);
// Create 1st content group
long groupIndex1 = PDF.CreateContentGroup("grpText");
PDF.BeginMarkedContent(groupIndex1);
PDF.DrawRectangle(45, 95, 270, 65, 0);
PDF.Stroke();
PDF.ShowTextAt(50, 100, "This is an optional content group #1.");
PDF.ShowTextAt(50, 120, "It contains text.");
PDF.ShowTextAt(50, 140, "It is initially visible.");
PDF.EndMarkedContent();
// Create 2nd content group
long groupIndex2 = PDF.CreateContentGroup("grpGraphics");
PDF.BeginMarkedContent(groupIndex2);
PDF.DrawRectangle(45, 240, 400, 300, 0);
PDF.Stroke();
PDF.ShowTextAt(50, 250, "This is an optional content group #2.");
PDF.ShowTextAt(50, 270, "It contains graphics.");
PDF.ShowTextAt(50, 290, "It is initially invisible.");
PDF.SetLineWidth(4);
PDF.SetColorStroke(0, 0, 0.5, 0);
PDF.DrawCircle(150, 370, 50);
PDF.MoveTo(250, 350);
PDF.DrawCurveTo(300, 550, 350, 350, 400, 500);
PDF.Stroke();
PDF.EndMarkedContent();
// Set 1st group visible and 2nd invisible
PDF.SetContentGroupState(groupIndex1, true);
PDF.SetContentGroupState(groupIndex2, false);
PDF.SaveToFile("PdfWithContentGroups.pdf", true);
' PDF object is supposed to be created
' Draw main document layer
fnt = PDF.AddBuiltInFont(1, false, false) 'bfHelvetica=1
PDF.UseFont fnt, 16
W = PDF.PageWidth
H = PDF.PageHeight
PDF.SetColorFill 0.8, 0.8, 0.8, 0
PDF.DrawRectangle 10, 10, W-20, H-20, 0
PDF.Fill
PDF.SetColorFill 0, 0, 0, 0
PDF.ShowTextAt 30, 30, "This is our document with text, graphics and so on..."
PDF.SetColorFill 0.9, 0.9, 0.9, 0
PDF.MoveTo 30, 50
PDF.DrawLineTo W-30, 50
PDF.DrawLineTo 30, H-50
PDF.DrawLineTo W-30, H-50
PDF.DrawLineTo 30, 50
PDF.FillAndStroke
PDF.SetColorFill 0, 0, 0, 0
' Create 1st content group
groupIndex1 = PDF.CreateContentGroup("grpText")
PDF.BeginMarkedContent groupIndex1
PDF.DrawRectangle 45, 95, 270, 65, 0
PDF.Stroke
PDF.ShowTextAt 50, 100, "This is an optional content group #1."
PDF.ShowTextAt 50, 120, "It contains text."
PDF.ShowTextAt 50, 140, "It is initially visible."
PDF.EndMarkedContent
' Create 2nd content group
groupIndex2 = PDF.CreateContentGroup("grpGraphics")
PDF.BeginMarkedContent groupIndex2
PDF.DrawRectangle 45, 240, 400, 300, 0
PDF.Stroke
PDF.ShowTextAt 50, 250, "This is an optional content group #2."
PDF.ShowTextAt 50, 270, "It contains graphics."
PDF.ShowTextAt 50, 290, "It is initially invisible."
PDF.SetLineWidth 4
PDF.SetColorStroke 0, 0, 0.5, 0
PDF.DrawCircle 150, 370, 50
PDF.MoveTo 250, 350
PDF.DrawCurveTo 300, 550, 350, 350, 400, 500
PDF.Stroke
PDF.EndMarkedContent
' Set 1st group visible and 2nd invisible
PDF.SetContentGroupState groupIndex1, True
PDF.SetContentGroupState groupIndex2, False
PDF.SaveToFile "PdfWithContentGroups.pdf", true
Set PDF = Nothing
See Also