[返回博客](/cn/blog) # PDF底图现在是Teigha的标准功能

Sergey Sherstnev 七月 19, 2018 [\#pdf](/cn/blog/tag/pdf) [\#export](/cn/blog/tag/export) [\#News](/cn/blog/tag/news)

<a class="a2a_button_facebook"></a><a class="a2a_button_twitter"></a><a class="a2a_button_linkedin"></a>

随着Teigha 2019的发布，ODA成员现在可以使用Teigha新的PdfiumModule模块以底图形式导入.pdf文件。该模块基于Google开发的Pdfium库。Pdfium是开源且免费的。此前，ODA成员可以使用PdfVIModule模块以底图形式导入.pdf文件，但这需要额外费用。

除了免费之外，PdfiumModule比PdfVIModule更快（根据.pdf文件，速度可提高几个百分点到几倍），支持跨平台，并且由于源代码可访问性，未来有定制的可能性。下表比较了PdfiumModule和PdfVIModule可与Teigha产品一起使用的可用配置：

| 配置 | PdfiumModule | PdfVIModule |
| :--- | :---: | :---: |
| Visual Studio 2015及更高版本 (vc14, vc15) | 是 | 已停产 |
| Visual Studio 2013及更低版本 (vc9, vc10, vc11, vc12) | 否 | 已停产 |
| Linux GCC 4.7及更低版本 (4.1, 4.2, 4.4, 4.7) | 否 | 已停产 |
| Linux GCC 4.8及更高版本 | 是 | 已停产 |
| Mac OS X | 是 | 已停产 |
| iOS | 是 | 否 |
| Android | 是 | 否 |
| 请注意，PdfiumModule 也支持此表中列出的平台的静态配置 | | |

由此可见，PdfiumModule可以在所有支持C++ 11的平台上使用，包括动态和静态配置。

PdfiumModule的主要功能包括：

- 将.pdf文件渲染为位图，用于已渲染的.dwg文件
- 处理PdfUnderlays的捕捉点

渲染和处理捕捉点时会考虑PDF图层状态，这与PdfModuleVI不同，后者无法完全处理PDF图层状态。

#### 从PdfModuleVI切换到PdfiumModule

PdfiumModule的使用方式与PdfModuleVI相同，因此切换到Pdfium非常容易。以下是创建PdfUnderlay的示例：

```
OdDbUnderlayReferencePtr loadPdfToUnderlayInModelSpace(OdDbHostAppServices* pHostApp)
{
  OdRxModulePtr pModule = ::odrxDynamicLinker()->loadModule(OdPdfModuleVIModuleName);
  if (pModule.isNull())
   throw OdError(eNullObjectPointer);

  OdString shortFileName = OD_T("test.pdf");
  OdString inputPdfFile = pHostApp->findFile(shortFileName);
  OdDbDatabasePtr pDb = pHostApp->createDatabase();
  // Try to load pdf file
  OdDbUnderlayHostPEPtr pHost 
       = OdDbPdfDefinition::desc()->getX(OdDbUnderlayHostPE::desc());

  if (pHost.isNull())
    throw OdError(eNullObjectPointer);

  OdDbUnderlayFilePtr pUnderlayFile;
  OdResult res = pHost->load(*pDb, inputPdfFile, "", pUnderlayFile);
  if (res != eOk)
    throw OdError(res);

  // Create pdf definition, add it to dictionary
  OdDbUnderlayDefinitionPtr pDef = OdDbPdfDefinition::createObject();
  pDef->setSourceFileName(inputPdfFile);
  pDef->setItemName( "1" ); // Page number

  OdString dictName = OD_T("MyPdfUnderlay - ") + activeLayout;
  OdDbObjectId definitionId = pDef->postDefinitionToDb(pDb, dictName);

  // Add Pdf underlay reference to model space
  OdDbUnderlayReferencePtr pRef = OdDbPdfReference::createObject();

  pRef->setDatabaseDefaults(pDb);

  OdDbBlockTableRecordPtr pSpace 
     = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite);
  pSpace->appendOdDbEntity(pRef);
  pRef->setDefinitionId(definitionId);

  return pRef;
}

```

只需替换此内容：

```
OdRxModulePtr pModule = ::odrxDynamicLinker()->loadModule(OdPdfModuleVIModuleName);

```

使用此内容：

```
OdRxModulePtr pModule = ::odrxDynamicLinker()->loadModule(OdPdfiumModuleName);

```

然后就完成了。

## 今天就开始行动

**免费试用 ODA 软件 60 天。  
无风险，无需信用卡。**

[免费试用](https://www.opendesign.com/cn/free-trial)
