Click here to Skip to main content
16,022,339 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a requirement to create DXF file from HTML div content/ image/pdf . I have tried many methods. but nothing was success. i can create dwg/dxf file. but its not opening in some case or may be blank.

What I have tried:

ezdxf

This is for image conversion
image_path = 'C:/Users/Downloads/home.jpg'
        with open(image_path, "rb") as image_file:
            encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
        base64_image = encoded_string
        print(base64_image,'base64_image')
        image_data = b64decode(base64_image)
        doc = ezdxf.new("R2000")
        temp_image_path = 'temp_image.jpg'
        print(image_data,'image_data')
        with open(temp_image_path, 'wb') as f:
            f.write(image_data)
        image = Image.open(temp_image_path)
        image.show()
        width, height = 800, 400  
        my_image_def = doc.add_image_def(filename=temp_image_path, size_in_pixel=(width, height))

        msp = doc.modelspace()
        image_width, image_height = 400, 200  
        msp.add_image(insert=(2, 1), size_in_units=(image_width, image_height), image_def=my_image_def, rotation=0)

        dxf_output_path = "new_dxf.dxf"
        doc.saveas(dxf_output_path)

        os.remove(temp_image_path)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900