我的意思是使用 ac 或 c++ lib。操纵。以前我使用cairo lib,成功创建pdf文件,但没有图层。现在我想创建具有多个图层的 pdf 文件。
谢谢
您可以创建(也阅读和编辑)PDF 图层(也知道可选内容组),如PDFLayers示例中所示,该示例也包含在PDFNet SDK中。
以下是相关代码:
PDFNet.Initialize();
PDFDoc doc;
// Create three layers...
OCG::Group image_layer = CreateLayer(doc, "Image Layer");
OCG::Group text_layer = CreateLayer(doc, "Text Layer");
OCG::Group vector_layer = CreateLayer(doc, "Vector Layer");
// Start a new page ------------------------------------
Page page = doc.PageCreate();
ElementBuilder builder; // ElementBuilder is used to build new Element objects
ElementWriter writer; // ElementWriter is used to write Elements to the page
writer.Begin(page); // Begin writing to the page
// Add new content to the page and associate it with one of the layers.
Element element = builder.CreateForm(CreateGroup1(doc, image_layer.GetSDFObj()));
writer.WriteElement(element);
element = builder.CreateForm(CreateGroup2(doc, vector_layer.GetSDFObj()));
writer.WriteElement(element);
// Add the text layer to the page...
if (false) // set to true to enable 'ocmd' example.
{
// A bit more advanced example of how to create an OCMD text layer that
// is visible only if text, image and path layers are all 'ON'.
// An example of how to set 'Visibility Policy' in OCMD.
Obj ocgs = doc.CreateIndirectArray();
ocgs.PushBack(image_layer.GetSDFObj());
ocgs.PushBack(vector_layer.GetSDFObj());
ocgs.PushBack(text_layer.GetSDFObj());
OCG::OCMD text_ocmd = OCG::OCMD::Create(doc, ocgs, OCG::OCMD::e_AllOn);
element = builder.CreateForm(CreateGroup3(doc, text_ocmd.GetSDFObj()));
}
else {
element = builder.CreateForm(CreateGroup3(doc, text_layer.GetSDFObj()));
}
writer.WriteElement(element);
// Add some content to the page that does not belong to any layer...
// In this case this is a rectangle representing the page border.
element = builder.CreateRect(0, 0, page.GetPageWidth(), page.GetPageHeight());
element.SetPathFill(false);
element.SetPathStroke(true);
element.GetGState().SetLineWidth(40);
writer.WriteElement(element);
writer.End(); // save changes to the current page
doc.PagePushBack(page);
// Set the default viewing preference to display 'Layer' tab.
PDFDocViewPrefs prefs = doc.GetViewPrefs();
prefs.SetPageMode(PDFDocViewPrefs::e_UseOC);
doc.Save("my.pdf", SDFDoc::e_linearized, 0);
注意:我是 PDFNet 开发人员。