Lower pixel density in PDF using python

With some help from this forum already, I’ve managed to produce good PDF images from DWF files with the aspose.cad for python library. However, when I try to import those PDF’s into another application I use, I receive an error that the pixel size of the image is too large.

I am looking through the methods in the aspose.cad library, but I don’t know how to use them. Is there a way to lower the pixel count / density, yet maintain high quality so that the images can be zoomed in on the resulting pdf?

@virgev,
Hi.
We need more details to reproduce the issue on our side. Please, share the initial DWF file, the code you use to export it to PDF, what is the application that shows the error?

.dwf wasn’t supported, so I changed the extension to pdf - just change it back.
Mandalay Bay Tower Level 03.pdf (163.2 KB)

Here’s the code that works to produce a PDF:

import aspose.cad as cad

image = cad.Image.load("Mandalay Bay Tower Level 03.dwf")
# pix = cad.ResolutionSetting()

rasterizationOptions = cad.imageoptions.CadRasterizationOptions()
rasterizationOptions.page_width = 800.0
rasterizationOptions.page_height = 800.0

pdfOptions = cad.imageoptions.PdfOptions()
pdfOptions.vector_rasterization_options = rasterizationOptions
pdfOptions.core_pdf_options = cad.imageoptions.PdfDocumentOptions()

image.save("Mandalay_Bay_Twr_Lvl3.pdf", pdfOptions)

I’m testing this for an import to a network management platform to have maps of floors. I’ve tried a couple different tools, just to see if it was just the one that was giving me problems. One gives me an actual error about the pixel size; the other seems to import successfully, but then it just shows a black box in place of the map.

The 2 tools are Ekahau Site Survey and Cisco Catalyst Center. I’ve tried several different methods, based on their names, but I’m either not calling them correctly or I don’t know what to give them for input and doing a “>>> print(help(whatever.whatever))” isn’t giving me anything useful.

@virgev,
we have created investigation ticket CADPYTHON-25 and will come back with more information.

Hello,

Is there any update on this as of yet?

@virgev,
Hi.
Not yet, this task is pending for the investigation this week. Hope to have more information in next few days.

1 Like

@virgev,
Hello.

The Ekahau Site Survey application supports PDF files with a maximum size of 10000*10000 points. So it is possible to set up the resulting PDF to be within this limit. Please try if this example works:


image = cad.Image.load("Mandalay Bay Tower Level 03.dwf")

size_in_points = 9999

rasterizationOptions = cad.imageoptions.CadRasterizationOptions()

rasterizationOptions.page_width = size_in_points / 72
rasterizationOptions.page_height = size_in_points  / 72
rasterizationOptions.unit_type = cad.imageoptions.UnitType.INCH
rasterizationOptions.draw_type = cad.fileformats.cad.CadDrawTypeMode.USE_OBJECT_COLOR
  
pdfOptions = cad.imageoptions.PdfOptions()
pdfOptions.vector_rasterization_options = rasterizationOptions
pdfOptions.core_pdf_options = cad.imageoptions.PdfDocumentOptions()

image.save("Mandalay_Bay_Twr_Lvl3.pdf", pdfOptions)

Hello Oleksii,
Thank you for this response; I was unable to test yesterday, but I am doing so today.

Oleksii,

The other application I’m trying to use these files in (the actual target; Ekahau was just a test for me), is now throwing an error (did not receive one before). The error states:

“The PDF document is too larger to render. The maximum allowed size is 2500 square inches (50 x 50 inches).”

That being said, do I just need to reduce the size_in_points variable you had set?

@virgev,
yes, the example above produces PDF with height and width 9999 / 72 = 139 inches (approx.), you can decrease the size_in_points to fit the required size.

@oleksii.gorokhovatskyi - I’ve done just that and tested. Everything appears to be working exactly as I need it now.

My customer will end up with probably 1000 or more files to run this on, so I will work with them to get a license for the library and setup so we can proceed. I really appreciate all the help - this is a huge time-saver for us!

@virgev,
We were happy to help, feel free contacting us in case of any issues and questions :slight_smile: