A PDF (Portable Document Format) underlay is an entity that represents a .pdf file attached to a drawing database and referenced from that database. A PDF underlay entity references an external PDF document, which is not an essential part of a drawing database but can be processed (for example, rendered) by Drawings SDK. The following picture illustrates a few renderings of a PDF underlay entity:
Drawings SDK provides PDF underlay support with the Google PDFium library. To get detailed information about working with PDF underlays using Google PDFium, see PDF Underlays with Google PDFium.
Drawings SDK provides a unified public API for PDF underlay functionality based on the Google PDFium library.
All source is available in the release packages (in the Drawing/Extensions/PdfUnderlayCommon
folder).
For the API Reference, please refer to:
PdfUnderlayModule
classOdDbPdfDefinition
classOdDbPdfReference
classLet's assume that you want to add the following .pdf file to model space as an underlaying entity.
To add a .pdf file to model space as an underlaying entity:
ExSystemServices
and ExHostAppServices
classes to provide access to platform-dependent functionality:
class MyServices : public ExSystemServices, public ExHostAppServices
{
protected:
ODRX_USING_HEAP_OPERATORS(ExSystemServices);
};
OdStaticRxObject svcs;
odInitialize(&svcs);
OdString fileName = svcs.findFile(L"Template_ISO_1.dwg");
OdDbDatabasePtr pDb = svcs.readFile(fileName);
OdDbBlockTableRecordPtr bBTR = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite);
if (OdDbPdfDefinition::loadPdfUnderlayModule().isNull())
throw OdError(eNullObjectPointer);
OdDbUnderlayHostPE
object), and check the result:
OdDbUnderlayHostPEPtr pHost = OdDbPdfDefinition::desc()->getX(OdDbUnderlayHostPE::desc());
if (!pHost.get())
throw OdError(eNullObjectPointer);
underlayFilePath
variable is an OdString object that contains the full path to the .pdf file):
OdDbUnderlayFilePtr pUnderlayFile;
OdResult res = pHost->load(*pDb, underlayFilePath, "", pUnderlayFile);
if (res != eOk)
throw OdError(res);
OdDbPdfDefinition
class), and set the source .pdf file and the page number that contains the underlay data:
OdDbUnderlayDefinitionPtr pPdfDef = OdDbPdfDefinition::createObject();
OdString itemName(OD_T("1"));
pPdfDef->setSourceFileName(underlayFilePath);
pPdfDef->setItemName(itemName);
Note that the setItemName()
method sets the number of the PDF document's page.
Pages are enumerated starting from 1.
OdDbObjectId idDef = pPdfDef->postDefinitionToDb(pDb, OD_T("DocSnippets_Cmds_") + itemName);
The PDF definition object is then in the database structure:
OdDbUnderlayReferencePtr pPdfRef = OdDbPdfReference::createObject();
pPdfRef->setDatabaseDefaults(pDb);
bBTR->appendOdDbEntity(pPdfRef);
pPdfRef->setDefinitionId(idDef);
The PDF reference object is added to model space and references the PDF definition object:
A rendering of the PDF underlay looks like the following:
Before finishing your client application, do not forget to deinitialize Drawings SDK functionality:
odUninitialize();
The loadPdfUnderlayModule()
method of the OdDbPdfDefinition
class tries to load the
PDFiumModule
first and if it fails, tries to load the PdfModuleVI
module; therefore to force using the
PdfModuleVI
, you need to load it explicitly:
if (::odrxDynamicLinker()->loadModule(OdPdfModuleVIModuleName).isNull())
throw OdError(eNullObjectPointer);
Instead of:
if (OdDbPdfDefinition::loadPdfUnderlayModule().isNull())
throw OdError(eNullObjectPointer);
Additional examples for working with PDF underlay entities are located in the sample applications:
Drawing/Examples/OdWriteEx
.
addPdfUnderlay()
method of the DbFiller
class declared in the DbFiller.h
file and its implementation in the appropriate DbFiller.cpp
file.
The Insert PDF underlay dialog window displays:
You can switch on or off any of the available layers from the origin PDF document in the layers list:
To select a .pdf file for the underlay, click Browse. To insert the underlaying entity, click Insert.
In addition, there are two user commands related to PDF underlay support that are available from the main menu:
Location: Core\Examples\win\OdaMfcApp
.
Note that the OdaMfcApp sample is available only for Windows platforms.
_showPdfGrips_func()
for the showPdfGrips command implementation and the function _showPdfSnaps_func()
for the showPdfSnaps command implementation. Both functions are defined in
the DrxDebugCmds.cpp
source file.
Location: Drawing/Examples/ExCustObjs
.
PDF Underlays with Google PDFium.
Additional information can be found at the ODA Forum.
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|