2
$\begingroup$

I'm using Chemistry Development Kit (CDK) to create molecular drawings using the DepictionGenerator class. It allows me to set the drawing's width and height using the method withSize(w, h) but the unit is assumed to be mm. I want to change that to pixels but not sure where that should happen. Your help in resolving this would be greatly appreciated.

$\endgroup$
4
  • $\begingroup$ Does my answer solve your question? If so please do consider accepting my answer by clicking on the tick mark next to it. This way you also get +2 reputation points. $\endgroup$ Aug 29, 2023 at 9:48
  • $\begingroup$ Hi Vandan, thanks for trying to help me but what you shared is known to me but it doesn't solve the problem. I want to specify width and height in pixels for SVG but it is not possible. $\endgroup$ Aug 30, 2023 at 14:41
  • $\begingroup$ Perhaps you can use this formula to calculate the number of pixels from the mm SO-answer and then supply the pixels to CDK function $\endgroup$ Aug 30, 2023 at 17:10
  • $\begingroup$ The formula mm = ( pixels * 25.4 ) / DPI requires the knowledge of the screen resolution from which the DPI could be derived. The image creator (Depictor) doesn't have access to DPI. $\endgroup$ Aug 31, 2023 at 18:15

2 Answers 2

2
$\begingroup$

I was digging through the CDK code and found the solution. The following worked.

DepictionGenerator dg = new DepictionGenerator().withSize(width, height);
Depiction depiction = dg.depict(molecule);
String svg = depiction.toSvgStr(Depiction.UNITS_PX);

It was hard to realize the Depiction class has an overloaded toSvgStr method which accepted the width and height I wanted. It works like a charm now.

$\endgroup$
0
$\begingroup$

As per the CDK documentation for raster graphics (ex JPEG, TIFF etc) the dimension of the width and height is pixels and for vector graphics (SVG, EPS etc) the dimension is mm.

Here I quote the documentation found here : CDK-docs

withSize public DepictionGenerator withSize(double w,double h)

Specify a desired size of depiction. The units depend on the output format with raster images using pixels and vector graphics using millimeters.

$\endgroup$
2
  • 1
    $\begingroup$ Vandan, found a solution to the issue. Please check below. $\endgroup$ Sep 21, 2023 at 21:56
  • 1
    $\begingroup$ Awesome ! Upvoted. $\endgroup$ Sep 22, 2023 at 10:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .