Python API: convert between PLT and SVG

Dear Aspose company,

I am a new user, and I need to convert files between PLT and SVG via API by python language.

Could you share the sample code please?

After testing phase, I will buy an account to use.

Thank you very much.

Dat Nguyen

@Kat_Lazy

Yes, you can convert PLT to SVG using the Convert API method. However, I am afraid the API method is not updated in Aspose.CAD Cloud SDK for Python. We have logged a ticket(CADCLOUD-498) to fix the issue.

Meanwhile, you can use the API in Python via some REST Client. Please find a sample cURL command for reference.

// First get Access Token
// Get App Key and App SID from https://dashboard.aspose.cloud/
curl "https://api.aspose.cloud/oauth2/token" -X POST -d "grant_type=client_credentials&client_id=xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json"

#Convert PLT to SVG
curl -X POST "https://api.aspose.cloud/v3.0/cad/Convert?outputFormat=SVG" -H "accept: application/json" -H "Authorization: Bearer eyJhbGciO....Al1kfw" -H "Content-Type: multipart/form-data" -H "x-aspose-client: Containerize.Swagger" -F "drawing"="@C:/Temp/B747.plt" --output C:/Temp/PLTtoPDF.svg
1 Like

Dear @tilal.ahmad ,
Thank you for your support.

After I run the command line in Windows 11. Using my own credentials & secret information

curl "https://api.aspose.cloud/oauth2/token" -X POST -d "grant_type=client_credentials&client_id=xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json"

it returns nothing.

Then I run the second command,

curl -X POST "https://api.aspose.cloud/v3.0/cad/Convert?outputFormat=SVG" -H "accept: application/json" -H "Authorization: Bearer eyJhbGciO....Al1kfw" -H "Content-Type: multipart/form-data" -H "x-aspose-client: Containerize.Swagger" -F "drawing"="@D:\input\abc.PLT" --output "D:\input\abc.svg"

but it returns the abc.svg file as an empty (0kb)

Could you please recheck this problem?
Thank you very much

@Kat_Lazy

Please use the following command with your credentials to get a JWT Access Token and use it in your conversion request.

# First get Access Token
# Get Client ID and Secret from https://dashboard.aspose.cloud/
curl -X POST "https://api.aspose.cloud/connect/token" -d "grant_type=client_credentials&client_id=xxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxx" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json"
1 Like

Thank you,

Now the access token works :innocent:
And I got the SVG file as I use your web to convert.

The last problem as I see.

  1. The shape of image is correct but the size of the image is smaller than the real size in PLT file.
    What should I do ?
    Which setting that I should change ?
    or I am wrong in the image size ?

Thank you very much

@Kat_Lazy

Please share your input, output and expected document with us. We will look into the issue and guide you accordingly.

1 Like

Dear @tilal.ahmad ,

These file are:
data.zip (16.5 KB)

In which:

  • Original file : P520215-BKL.PLT
  • Other SVG files are converted by aspose web, aspose API and another converter.

Those SVG files are in different size (width, height) and line width. The aspose API provide very thick line.

I don’t know which SVG size is correct. As I see, the aspose API and other converter seem to be correct.

Which params that I should check in the PLT file to know the correct Size ?
Because the problem in mapping between pixel to centimeter => How many pixel for one centimeter

Thank you very much

@Kat_Lazy

I am afraid at the moment, Aspose.CAD Cloud API does not provide options/parameters to set the size in the conversion. However, as requested above, please share your expected output SVG file. We will investigate it and try to produce the closest output.

Dear @tilal.ahmad

Please share your knowledge on plt file because the problem as I see

  • PLT file is measure in cm or milimet to print exactly.
  • SVG file is in pixel and can scale those vectors to the size that we want.

In the past, I print by single plt file.
But now, I want to combine those images and print.

So now, I want to do:

  1. Merge SVG files into a big SVG file.
  2. Convert the big SVG file to a PLT file and print it.
    => The problem of image size is important here.
    Hope you can help me on this problem.

Thank you very much.

@Kat_Lazy

We have logged a ticket(CADCLOUD-500) to look into your requirements. We will share our findings with you as soon as possible.

1 Like

Thank you very much.

Hope to hear your answer soon.

If this is good, I will buy API from your company.

Dat Nguyen

Dear @tilal.ahmad

When I use

curl -X POST "https://api.aspose.cloud/v3.0/cad/Convert?outputFormat=SVG" -H "accept: application/json" -H "Authorization: Bearer eyJhbGciO....Al1kfw" -H "Content-Type: multipart/form-data" -H "x-aspose-client: Containerize.Swagger" -F "drawing"="@C:/Temp/B747.plt" --output C:/Temp/PLTtoPDF.svg

Which option that I can add, if I want the property of path, stroke-width=β€œ1” ?
It make the line thinner. Because the API conversion return stroke-width=β€œ13”, too thick.

Thank you

@Kat_Lazy

I am afraid currently, Aspose.CAD Cloud does not support setting a property in conversion. We have shared the information with our product team and will update you accordingly.

1 Like

Thank you @tilal.ahmad ,
Now I can use Python code to call API as below:

import requests
access_token = "xyzabcdef"
ip_file = "abc.PLT"
op_file = "abc.svg"
web_link = "https://api.aspose.cloud/v3.0/cad/Convert"

headers = {
    'accept': 'application/json',
    'Authorization': f'Bearer {access_token}',
    'Content-Type': 'multipart/form-data',
    'x-aspose-client': 'Containerize.Swagger',
}

params = {
    'outputFormat': 'SVG',
}

fdata = open(ip_file, 'rb')
files = {
    'drawing': fdata,
}

response = requests.post(web_link, params=params, headers=headers, files=files)

with open(op_file, 'wb') as f:
    f.write(response.content)

print('--- Finished')

The settings to converts, I think, we can put into the params variable.
Please share your solution.
Thank you very much.

@Kat_Lazy

Sure, we will share an update/ETA with you as soon as the issue investigation is completed.

1 Like