pdfio icon indicating copy to clipboard operation
pdfio copied to clipboard

Allow multiple simultaneous open streams per PDF file

Open uddhavphatak opened this issue 2 months ago • 4 comments

Is your feature request related to a problem? Please describe. When parsing page content streams, it’s common to need nested resources (e.g., open a font’s /ToUnicode CMap stream while the page’s /Contents stream is still being read). Currently, PDFio returns an error if another stream is already open for the same file:

sample-tables.pdf: Another object (2389) is already open.

Describe the solution you'd like Allow multiple simultaneous read-only streams from the same pdfio_file_t.

Code Snippet

 // Find the named font...
  if ((page_dict = pdfioObjGetDict(page_obj)) == NULL)
    return;

  if ((resources_dict = pdfioDictGetDict(page_dict, "Resources")) == NULL)
    return;

  if ((font_dict = pdfioDictGetDict(resources_dict, "Font")) == NULL)
  {
    // Font resources not a dictionary, see if it is an object...
    if ((font_obj = pdfioDictGetObj(resources_dict, "Font")) != NULL)
      font_dict = pdfioObjGetDict(font_obj);

    if (!font_dict)
      return;
  }

  if ((font_obj = pdfioDictGetObj(font_dict, name)) == NULL)
    return;

  font_Subtype = pdfioObjGetSubtype(font_obj);

  if(!strcmp(font_Subtype, "Type0"))
  {
    if ((encoding_name = pdfioDictGetName(pdfioObjGetDict(font_obj), "Encoding")) == NULL)
      return;

    if(!strcmp(encoding_name, "Identity-H"))
    {
      pdfio_obj_t *To_unicode_obj = pdfioDictGetObj(pdfioObjGetDict(font_obj), "ToUnicode");
      if(To_unicode_obj)
      {
                pdfio_stream_t *unicode_stream = pdfioObjOpenStream(To_unicode_obj, true);
//      while (pdfioStreamGetToken(unicode_stream, buffer, sizeof(buffer)))
        {
          fprintf(stderr, "*******%s\n", buffer);
        }
//      pdfioStreamClose(unicode_stream);

      }
    }
  }

sample-tables.pdf

uddhavphatak avatar Oct 08 '25 07:10 uddhavphatak