Skip to main content
Closed

Convert PDF to SVG

Anita Hæhre
  • Anita Hæhre
    Anita Hæhre

I have quite a few engineering diagrams that have been annotated in CDF and now we need to convert them to SVGs in order for some third party application to read them. The API supports this, but the Python SDK does not, or at least not directly. It is possible to force the behavior, but it requires a cumbersome workaround to “trick” the SDK.

The SDK seems to expect that the convert job is the next after detect, in theory this makes some sense, however in reality this is not how it will be done. The process will be to detect annotations, then get them approved, then generate the SVG file. The middle step is a manual and the convert job will be run as a separate pipeline.

As shown below, the API supports this by having the feature that we can send in the file and the annotations, the input for the SDK is the output of detect. It is possible to replicate the required input, but it is cumbersome. Is there a way to more simply use the files and the annotations through the SDK to convert the files after the fact?

Ideally I would want to do something like this:

files = client.files.list(data_set_external_ids=docDataSetExtId)
ext_ids = [f.external_id for f in files]
flt = AnnotationFilter(annotated_resource_type="file", annotated_resource_ids=[{"externalId": ext_id} for ext_id in ext_ids])
annotations = client.annotations.list(flt, limit=-1)

# This
client.diagrams.convert(files, annotations)

# or like this
for file in files:
    flt = AnnotationFilter(annotated_resource_type="file", annotated_resource_ids=[{"externalId": file.external_id}])
    annotations = client.annotations.list(flt, limit=-1)
    client.diagrams.convert(file, annotations)

# Or even just having the SDK handle all of it in the background (best option for me)
# And then the SDK or CDF itself just retrieves all annotations linked to the file
client.diagrams.convert(external_id=file.external_id)

 

https://cognite-sdk-python.readthedocs-hosted.com/en/latest/contextualization.html#convert-to-an-interactive-svg-where-the-provided-annotations-are-highlighted

https://api-docs.cognite.com/20230101/tag/Engineering-diagrams/operation/diagramConvert

 

5 replies

Mithila Jayalath
Seasoned Practitioner
Forum|alt.badge.img

@Markus Pettersen I not sure whether it’s possible. But as a workaround you can use the API directly in your Python code.


If I have to use the API directly then that somewhat defeats the purpose of having an SDK. However, it is possible to use the SDK, but to do so I will have to mimic the expected input of the convert method. In other words to do so I have to create an “DiagramDetectResults” instance without using the detect endpoint, it is possible but an annoying and very manual approach.


The ideal solution would be that the SDK is updated to support the more general use case for this feature, and not just the one someone initially thought would be the one and only use case.


Dilini Fernando
Seasoned Practitioner
Forum|alt.badge.img+2

Hi @Markus Pettersen 

I have changed this question into a product idea, and then our engineering team will review and respond to it.


  • Practitioner
  • 42 replies
  • August 15, 2024

Hi @Markus Pettersen,

Thank you for the suggestion.

The API is designed to take parsed output directly, similar to how it works in the SDK, rather than a list of annotations created by the Annotation API. We chose this approach because some use cases involve generating an SVG without creating annotations in CDF. For users who do create annotations in CDF, those annotations are already visible in applications like Data Explorer or Canvas, reducing the need to generate an SVG.

I understand this adds an extra step to your workflow for preparing the necessary input. However, if the inputs were annotations, other users would face the added complexity of creating and then deleting those annotations.

We're marking this request as 'Gathering Interest' and will revisit it if there’s increased demand for this improvement.

Thanks and regards,
Que


Reply


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings