# PDF Reader

Portable Document Format (PDF)
File Extension | PDF [1]
Supported Versions | All versions
Platforms |
Tessellation | Read from file
B-rep | Supported
PMI | Supported

Portable Document Format (PDF) is a versatile file format developed by Adobe. It is commonly used for documents, including text, images, and vector graphics. The format can also include embedded 3D models, mentioned as 3D annotations..

Our support for PDF covers reading 3D annotations in PRC or U3D streams stored within any version of a PDF file on all platforms.

[1] | While .pdf is the usual extension for PDF files, HOOPS Exchange identifies and reads from PDF files with any extension.

## Loading a PDF Model

PDF files can contain multiple data streams, each encoding a 3D annotation. As a result, using basic functions like `A3DAsmModelFileLoadFromFile()` or `A3DAsmModelFileGet()` will only work if you are interested in the first 3D annotation stored in the PDF file, because these functions are designed to handle only a single data stream.

To load 3D content from a PDF file, you first need to extract the 3D data streams using `A3DGet3DPDFStreams()`. This function retrieves an array of 3D streams, allowing you to choose which one to process.

### Handling PRC and U3D Data

Once the 3D streams are extracted, they are stored in a C-style array of `A3DStream3DPDFData` objects. For each stream, you can determine if it contains PRC data by checking the `m_bIsPrc` flag. If the stream is not PRC, it contains U3D data.

You can then dump each stream into files and load them into model files using `A3DAsmModelFileLoadFromFile()`. PRC streams, however, can be loaded directly from memory using `A3DAsmModelFileLoadFromPrcStream()`.

The following example demonstrates how to load the first 3D stream from a PDF, check its format, and handle the stream appropriately:

    A3DStream3DPDFData* pStream3DPDFData;
    A3DInt32 iNumStreams;
    A3DGet3DPDFStreams((char*) pcFileName, &pStream3DPDFData, &iNumStreams);

    // a real use case might parse every stream in the input file. Here, we just take the first one (pStream3DPDFData[0]).
    if (pStream3DPDFData[0].m_bIsPrc) // test whether the data is PRC or U3D
    {
            // even an input PRC file must be read in memory and mapped into modelfile data structures
            A3DRWParamsPrcReadHelper* pPrcReadHelper;
            A3DAsmModelFileLoadFromPrcStream(pStream3DPDFData[0].m_pcStream, pStream3DPDFData[0].m_iLength, &pPrcReadHelper, ppModelFile);
    }
    else
    {
            // A U3D stream must first be stored as a physical file, then read by A3DAsmModelFileLoadFromFile
            sprintf(tempfilename, "%s.u3d", OUT_FILE);
            FILE * pFile = fopen(tempfilename , "wb");

            fwrite(pStream3DPDFData[0].m_pcStream, 1, pStream3DPDFData[0].m_iLength , pFile);
            fclose(pFile);

            // physical file to stream
            A3DAsmModelFileLoadFromFile(tempfilename, sReadParam, ppModelFile);

            // the temp file can be disposed of afterwards
            remove(tempfilename);
    }

    // Release memory for stream array
    A3DGet3DPDFStreams(0, &pStream3DPDFData, &iNumStreams);

### Loading a PDF with A3DAsmModelFileLoadFromFile

You can load a PDF file containing PRC or U3D streams using `A3DAsmModelFileLoadFromFile()`, but there are some limitations:

- Only the first stream in the PDF will be read; additional streams will be ignored.
- If the stream includes annotations, only the first annotation is processed, and subsequent annotations are disregarded.

To load a PDF file using `A3DAsmModelFileLoadFromFile()`, use the `A3DParamsLoadData` structure to customize the loading behavior:

    A3DAsmModelFile* pModelFile = 0;

    A3DRWParamsLoadData sReadParam = A3D_MAKE_DATA(A3DRWParamsLoadData);
    sReadParam.m_sGeneral.m_bReadSolids = true;

    // ... set other A3DRWParamsLoadData fields as necessary

    A3DAsmModelFileLoadFromFile("path/to/file.pdf", &sReadParam, &pModelFile);

See Simple Load and Export for more information about loading model files.

## Support Capabilities

Since our PDF reader reads streams in either a PRC or and U3D format, the support for reading tessellation data, B-rep and PMI depends on these specific readers.

For more information about their support, see PRC Reader and U3D Reader.

## Miscellaneous

### Advanced Publish

Advanced Publish is an authoring SDK within HOOPS Exchange that enables creation and export of rich engineering data using the PRC data model. It supports generating output for several supported formats, such as PDF, through file import or API-based authoring.

For more information about using Advanced Publish with this file format, refer to the Advanced Publish section of the Programming Guide here.

### Limitations

- Our PDF reader does not read 3D streams from password-protected PDF files.

Conversation saved
HOOPSY BETA

### Hello! I'm HOOPSY

Your multilingual generative AI assistant for documentation. Ask me anything about HOOPS Exchange in your own language, or choose a sample question below to start a conversation:

What is HOOPS Exchange?
What are the latest release notes for HOOPS Exchange?
How do I start evaluating HOOPS Exchange?
How do I write my first sample application?
How can I get assistance?

HOOPSY may store conversations according to OpenAI's policy. Responses may not always be accurate.

HOOPSY is thinking...