0

Is there another way to retrieve geometry from a pdf particular layer using fitz, except get_cdrawings()?

I've tried to use get_cdrawings, but the value for "layer" is always empty.

import fitz
from fitz import Document, Page

with open("test.pdf",'rb') as f:
     doc = fitz.open(stream=f.read(), filetype="pdf")
     geometry = Page.get_cdrawings(doc[0], True)
     for item in geometry:
         print(item["layer"]) # empty value
         if item["type"] == "s":
             for i in item["items"]:
                 print(i)
Gennady K
  • 1
  • 2
  • The layer name is currently not correctly returned. To achieve what you want, set the desired layer(s) ON or OFF and then do `page.get_drawings()`. The list of available layers is returned via `doc.layer_ui_configs()`. Each of these items is a dictioanry describing an OCG. to set a lay ON (0), OFF (2) or to toggle it (1), execute `doc.set_layer_ui_config(ui["number"], action=action)`. Where action is 0,1,2 and `ui` is a dictionary of that list. – Jorj McKie Jun 09 '23 at 11:36
  • 1
    Thanks a lot! More than enough for my needs. – Gennady K Jun 09 '23 at 12:02

0 Answers0