When importing text objects from PDF to .dwg, the font used by text objects is often missing from the system. In older ODA SDK versions, all fonts that were not found were replaced with Arial, but starting with version 22.5 you can replace any font used in a PDF document with a preferred font when importing.
Note: To select a preferred Type3 font, switch on the ImportType3AsTrueTypeText
import option
(see PDF Import Parameters for details).
Type3 fonts are typically used to represent SHX fonts during PDF export.
The callback function mechanism provides the ability to select a preferred font.
You can set a special function that returns the preferred font name for the importer object
(an instance of a class derived from the OdPdfImport
abstract class)
by a call of the setPreferableFontCallback()
method, which accepts an STL wrapper of a function
that determines the preferable font:
std::function<OdAnsiString(const char*, const char*, const bool)>
This function accepts the following arguments:
The function returns either the name of the preferred font or an empty string if font substitution is not needed.
The substitution font can also be an SHX font. In this case, the name of the font file is returned, for example: romans.shx
.
Below is example source code that sets a function wrapper to determine the preferable font:
OdPdfImportModulePtr pModule = ::odrxDynamicLinker()->loadModule(OdPdfImportModuleName, false);
PdfImporterExPtr pImporter = pModule->create();
OdRxDictionaryPtr pProps = pImporter->properties();
// fill main PdfImport properties
//Set the preferred font selection function
pImporter->setPreferableFontCallback([](const char* font_name, const char* font_family, const bool is_found)
{
OdAnsiString ret;
if (!is_found)
ret = " MS Gothic";
static const OdAnsiString times_str("Times New Roman");
if (0 == times_str.compare(font_family))
ret = "Tahoma";
return ret;
});
OdPdfImport::ImportResult importResult = pImporter->import();
In this example, all fonts that are not found within the operating system are substituted with the MS Gothic font, fonts that are based on the Times New Roman font family are substituted with the Tahoma font, and other fonts remain unchanged.
You can find another example of preferred font selection in the PdfImportCommand
example.
Note: The font replacement mechanism takes precedence over the value of the Type3TextDefaultFont
property.
The process of choosing the font for imported text can be summarized as:
Type3TextDefaultFont
import property)
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|