/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef _PDFIMPORT_INCLUDED_ #define _PDFIMPORT_INCLUDED_ #include "RxModule.h" #include "RxDictionary.h" #include "DynamicLinker.h" ////////////////////////////////////////////////////////////////////////// #include "OdPlatformSettings.h" #include #ifdef PDFIMPORT_EXPORTS #define PDFIMPORT_TOOLKIT OD_TOOLKIT_EXPORT #define PDFIMPORT_TOOLKIT_STATIC OD_STATIC_EXPORT #else #define PDFIMPORT_TOOLKIT OD_TOOLKIT_IMPORT #define PDFIMPORT_TOOLKIT_STATIC OD_STATIC_IMPORT #endif ////////////////////////////////////////////////////////////////////////// class OdDbDatabase; /** \details Defines preferable font type options. */ enum OdImportPreferableFontType { /** Font file. */ kPdfImportFontType = 0, /** Big font file. */ kPdfImportBigFontType }; /** \details This is a prototype of the function that selects the preferred font function. \param font_name [in] The name of the current font. The name is the same as the one displayed in the properties of the PDF document. \param font_family [in] The FamilyName for the current font. \param is_found [in] A flag that determines whether the current font is found in the list of fonts installed in the operating system. \param font_type [in] A value of the ImportPreferableFontType enumeration that represents the requested font type. \returns The name of the preferred font. The preferred font replaces the current system font. If the current system font should not be replaced, the function returns an empty string. */ using PreferableFontCallback = std::function; //DD:EXPORT_ON /** \details An abstract class that represents the interface for the import from a PDF file. */ class OdPdfImport : public OdRxObject { public: /** \details Contains a list of the PDF import operation results that are handled by the . */ enum ImportResult { /** The import process is successfully finished.*/ success, /**The import process failed.*/ fail, /** The import process failed because of an incorrect password.*/ bad_password, /** The import process failed because of an incorrect input PDF file.*/ bad_file, /** The import process failed because of an incorrect destination database object.*/ bad_database, /** The import process failed because of an encrypted input PDF file.*/ encrypted_file, /** The import process failed because of an invalid page number of the input PDF file.*/ invalid_page_number, /** The import process failed because of an error while saving the image file (the possible reason is an invalid directory for saving).*/ image_file_error, /** The import process failed because no objects were imported.*/ no_objects_imported, /** The import process failed because of an error while saving the embedded font file (the possible reason is an invalid directory for saving).*/ font_file_error }; /** \details Imports a PDF file's contents to a drawing database with specified properties. This method should be reimplemented to provide the functionality for importing from a PDF file. \returns A value of the enumeration that contains the result of the import process. \remarks To specify import properties, use the method to get access to the import properties dictionary object. */ virtual ImportResult import() = 0; /** \details Retrieves a dictionary object that contains the set of PDF import properties. \returns A smart pointer to the dictionary object that contains properties used for the import of a PDF file's content to a drawing database. \remarks The list of supported properties for the PDF import operation is represented in the table below.
Property Name Description
Database A target database object (an instance of the OdDbDatabase class). The contents of the PDF file are imported to this database.
PdfPath A full path to the imported PDF file.
Password A password for the input PDF file (empty by default).
PageNumber A page number of the input PDF file. Starts from 1 (by default).
LayersUseType A method that determines how imported objects should be assigned to layers in the target database.
ImportVectorGeometry A flag that determines whether the PDF geometry data types are imported (true by default).
ImportSolidFills A flag that determines whether all solid-filled areas are imported (true by default).
ImportTrueTypeText A flag that determines whether text objects that use TrueType fonts should be imported (true by default). Some symbols exported from a PDF document may display incorrectly because the PDF document uses symbols that the origin TrueType font does not contain. To correctly display all symbols, switch on the ImportTrueTypeTextAsGeometry option for the import process.
ImportWidgets A flag that determines whether widget (text fields, buttons, etc.) data types are imported. Widgets are imported as a set of geometric objects, solid-filled objects, images, and text, so enabling options to import these corresponding objects affects the import of widgets. By default, the property is equal to true.
ImportRasterImages A flag that determines whether raster images are imported by saving them as PNG files and attaching them to the current drawing (true by default).
ImportGradientFills A flag that determines whether shaded objects are imported as images by saving them as PNG files and attaching them to the current drawing (true by default).
ImportAsBlock A flag that determines whether the PDF file is imported as a block, not as separate objects (false by default).
JoinLineAndArcSegments A flag that determines whether contiguous segments are joined into a polyline if it is possible (true by default).
ConvertSolidsToHatches A flag that determines whether 2D solid objects are converted to solid-filled hatches (true by default).
ApplyLineweight A flag that determines whether lineweight properties of the imported objects remain (if true) or are ignored (if false). By default, the property is equal to true.
ImportTrueTypeTextAsGeometry A flag that determines whether text objects that use TrueType fonts are imported as polylines and solid-filled hatches (false by default). To import text as geometry, switch on the ImportVectorGeometry and ImportSolidFills import options.
Scaling Specifies the scale factor for imported objects (equal to 1.0 by default).
Rotation Specifies the rotation angle for imported objects (equal to 0.0 by default).
InsertionPointX The x-coordinate of the imported PDF content location relative to the location of the current UCS (equal to 0.0 by default).
InsertionPointY The y-coordinate of the imported PDF content location relative to the location of the current UCS (equal to 0.0 by default).
UseProgressMeter A flag that determines whether a progress meter is used for the import (true by default). Using the progress meter can reduce performance.
UseGeometryOptimization A flag that determines whether a geometry optimization algorithm is used for the import (true by default).
ImportType3AsTrueTypeText A flag that determines whether text objects that use Type3 fonts are imported as objects that use TrueType fonts (false by default). Some symbols exported from a PDF document may display incorrectly because the PDF document uses Type3 font glyphs that the origin TrueType font does not contain.
ImportPatternAndClipTextAsText A flag that determines whether text objects represented as a clip outline or as a pattern filled object are imported as text objects(defaults to true).
UseRgbColor A flag that determines whether RGB colors are used or colors are selected from the palette, if possible (false by default).
ImportInvalidTTTextAsGeometry A flag that determines whether text objects that use invalid TrueType fonts are imported as polylines and solid-filled hatches (true by default).
UseClipping A flag that determines whether clipping is used during import (false by default).
UsePageBorderClipping A flag that determines whether clipping is used at the border of the page (false by default). Used only if the UseClipping option is turned on.
UseImageClipping A flag that determines whether image clipping is used during import (false by default). The image is modified on import so that the clipped part of the image becomes transparent. Used only if the UseClipping option is turned on.
TakeAddMeasurementFactors A flag that determines whether additional measurement factors are used for the PDF page (true by default).
CombineTextObjects A flag that determines whether text objects that use the same font and are on the same line are combined (false by default).
CharSpaceFactor Specifies the factor for the width of the space between characters in words (equal to 0.6 by default). If the distance between text objects in a string is less than the width of the space taken from the font metric multiplied by this factor, the text objects are combined into one word. Used only if the CombineTextObjects option is turned on.
SpaceFactor Defines the factor for the width of the space between words on a line (equal to 1.5 by default). If the distance between text objects in a string is greater than the width of the space between characters in a word (specified by CharSpaceFactor) but less than the width of the space taken from the font metrics multiplied by this factor, the text objects are combined into one word. Used only if the CombineTextObjects option is turned on.
UsePdfTransparency A flag that determines whether transparency for geometric objects is used from a PDF stream (if true) or set to 50% for objects that will be imported as solid-filled areas (if false). By default, the property is equal to false.
ImportHyperlinkMethod Defines how hyperlinks are imported. Can accept the following values: * 0 - Import as a hyperlink (OdDbHyperlink) belonging to an entity. Hyperlinks are assigned to entities if the hyperlink's bounding box contains an entity bounding box and the hyperlink with the smallest bounding box is selected. The other hyperlinks are ignored. * 1 - Hyperlinks are imported as transparent OdDbHatch objects with assigned OdDbHyperlinks. In this case, all hyperlinks are imported over other objects and according to the drawing order. * 2 - Mixed method. Hyperlinks are imported as in mode "0". If the hyperlink does not match the conditions of this mode, it is imported as a transparent hatch object with OdDbHyperlinks assigned to it. The default value is 0.
ConsiderINSUNITS A flag that determines whether the INSUNITS value is used when importing a PDF file. If true, all imported object dimensions are scaled according to the INSUNITS value. By default the property is false.
Type3TextDefaultFont The name of the font that is used when importing text objects that use a Type3 font. Can take the value of a TrueType typeface name or a Unifont filename. By default, the value of this property is empty.
ImagePath String parameter that determines the directory to save the images when importing a PDF file. If not specified, the value of the PDFIMPORTIMAGEPATH system variable is used; if the system variable value is also not specified, the images are saved in the application's temporary directory. By default, the value of the property is empty.
ExtractEmbeddedFonts A flag that determines whether extraction of embedded fonts is supported. Embedded font extraction is used only if it is possible (by default the flag equals false).
EmbeddedFontsPath String parameter that determines the path to the directory where embedded fonts are extracted during the PDF import operation. If a path to the directory is not specified, embedded fonts are extracted to the application's temporary directory. By default, the value of the property is empty.
TryFixUnicodeTable A flag that determines whether ToUnicode table fixing for CID and Type3 fonts is supported in cases when it is possible. By default, the property value is equal to false.
DPIForImagePattern Defines DPI for objects with pattern fill. If the flag UseDownScaleForImagePattern is false, the image pattern is only upscaled, otherwise downscaling is possible. The default value is 300.
UseDownScaleForImagePattern A flag that determines whether image patterns will be downscaled on import (DPI for these images patterns is set by DPIForImagePattern property). By default, the property value is equal to false.
ImportShadingAsGradientHatch A flag that determines whether shaded objects will be imported as gradient hatch objects, if possible. By default, the property value is equal to false.
LineTypeFromCollinearDashes A flag that determines whether collinear segments will be imported as line objects with a line style, if possible. By default, the property value is equal to false.
ImportInvisibleText A flag that determines whether invisible text is imported (false by default). The import retains the color and transparency specified in the PDF (which is typically opaque).
*/ virtual OdRxDictionaryPtr properties() = 0; /** \details Sets a function to select the preferred font. \param callback [in] A pointer to the function that implements the selection of the preferred font. \remarks If the font name is changed by calling a function that selects the preferable font, the Type3TextDefaultFont option is ignored. */ virtual void setPreferableFontCallback(PreferableFontCallback callback) = 0; }; /** \details A data type that represents a smart pointer to a object. */ typedef OdSmartPtr OdPdfImportPtr; /** \details An abstract class that provides an interface for the PDF import module. */ class OdPdfImportModule : public OdRxModule { public: /** \details Creates an instance of the PDF import module if it was not created yet; otherwise, provides access to the previously created module. \returns A smart pointer to the . */ virtual OdPdfImportPtr create () = 0; }; /** \details A data type that represents a smart pointer to a . */ typedef OdSmartPtr OdPdfImportModulePtr; /** \details Creates an instance of the class. \returns Returns a smart pointer to the . */ inline OdPdfImportPtr createImporter() { OdPdfImportModulePtr pModule = ::odrxDynamicLinker()->loadApp(OdPdfImportModuleName); if ( !pModule.isNull() ) return pModule->create (); return (OdPdfImport*)0; } //DD:EXPORT_OFF #endif // _PDFIMPORT_INCLUDED_