ASP.NET: Dynamically direct a save to a fixed server loc?

User 8df34b26ae

12-01-2009 20:09:54

We are successfully using MarvinSketch into our ASP.NET application.  However, we would like our users to save a finished sketch as a .JPEG file to a location on a shared drive on the web server that we would dynamically determine at runtime.   Is there a way of dynamically setting the 'file/save' location (and filename and .JPEG file type) so that the user would not have to select the desired destination?   Thanks very much.  

ChemAxon 6e93227fcc

13-01-2009 15:14:39

Hi,


Thank you for your interest in our products.


Your problem request multiple steps to be solved. I will describe them bellow and hopfully you will be able to implement what you need.


1. From javascript you have to get the corresponded "mol" or "smiles" string format. You can do this like


var jsObject = your_applet_object.getMol('mol'); //the applet object can be obtain in multiple ways...even document.applets[0] or document.MSketch etc.


2. Once you have this string you have to send it to your web server from javascript. You can do it by POST or GET technology. I recomend to use POST.


3. Now that you have the mol string format on your server side you can implement the logic in ASP.NET. That logic will include using the Marvin API through jnbridge to convert the mol string into a JPEG. Then you can save the picture on your shared folder.


You can check also this link http://chemaxon.com/marvin/examples/applets/sketch/noliveconnect1.html for client side implementation.

User 8df34b26ae

13-01-2009 23:56:38

Hello,


Thanks for the response.   One question:  if I am correct, JNBridge is a third-party package, so using it would cause an extra expense for us?    I just need to confirm that there is not other (free) way to turn the captured .MOL string into a .JPG file from within ASP.NET?


 

ChemAxon 6e93227fcc

14-01-2009 14:51:08

Hi,Yes you're right JNBridge is a third party tool and is not free. Anyway we will release in few days a JChem and Marvin "pure .NET" API which will only require a free third party dll called IKVM. However the conversion from mol format to JPEG might not work with this new API's but it will work to obtain an EMF picture (we already use that functionality in .NET). Then from EMF you can create the JPEG. I know this a little bit complicated to simply obtain a JPEG but we will enhance these things in the future.

User 8df34b26ae

29-01-2009 00:38:01

Hello, Just checking in to see if the product mentioned below has actually been released yet.  Thanks.

ChemAxon 6e93227fcc

30-01-2009 13:22:39

Hi,





You can give it a try... Check http://chemaxon.com/jchem/download.html then "JChem API for .NET 2.0". You will need a forum user but I assume you already have one since you post here :).You can also give us your feedback after you try it out.








Good luck.





Calin.

User 8df34b26ae

04-02-2009 00:01:38

Calin,





I installed this and it looks like it should work for us, but I believe I am missing a basic point about the use of MolConverter to create a JPEG file on the server from a MOL string.   Hopefully, a quick look at my code will surface an obvious fix.  FYI, txtMol is a text box which receives the MOL string from the Marvin Sketch applet, its contents during my test are attached.  <span style="font-size: 10px;"><span style="font-size: 10px;">This code runs without a thrown exception and the .jpeg file in 'imgfile' is indeed created but it is empty?   Thanks for the review.




































































<span style="font-size: 10px;">Dim strEmbeddedFileName As String = "MarvinMOL_" & Now.Ticks & ".JPG"














Dim mol As String  = txtMol.Text











Dim ip As  ByteArrayInputStream











ip =  New  ByteArrayInputStream(System.Text.ASCIIEncoding.ASCII.GetBytes(mol))











Dim op As DataOutputStream











<span style="font-size: 10px;">Dim imgfile As String











<span style="font-size: 10px;">Dim convertParams As String = "jpeg:mono,H_heteroterm,wireframe,#ffffff"











<span style="font-size: 10px;">Dim mcv As MolConverter








'Ticks included to insure a unique Marvin file name on page








<span style="font-size: 10px;">


<span style="font-size: 10px;">strEmbeddedFileServerFullPath = Request.PhysicalApplicationPath &


"/" & <span style="font-size: 10px;">strEmbeddedFileName























imgfile = strEmbeddedFileServerFullPath





op =





mcv =





<span style="font-size: 10px;"><span style="font-size: 10px;">


New DataOutputStream(New FileOutputStream(imgfile))New MolConverter(ip, op, convertParams, False<span style="font-size: 10px;">)

ChemAxon 6e93227fcc

04-02-2009 10:05:55

Hi,





I will try to make a short example for you today but it will be in C# because I don't know much VB :). I also want to know if you try to run it on .NET mono (under Unix) or on normal .NET framework under windows?

User 8df34b26ae

04-02-2009 18:02:52

Thanks very much, C# will be fine.   We are running the normal .NET framework under windows. 

ChemAxon 6e93227fcc

04-02-2009 18:20:20

Hi,





I managed to make an example for you but I must admit I spent like 3 hours to figure out why I can't obtain a JPEG from an EMF and the problem was that it was drawing a black structure on a image with a black background so be careful with this :).





Here is the code:





string molStr = "your mol string data ";





chemaxon.marvin.MolPrinter molPrinter = new chemaxon.marvin.MolPrinter();





molPrinter.setMol(molStr);





java.io.ByteArrayOutputStream bArrOS = new java.io.ByteArrayOutputStream();





//you can change the size of the image as you need. I've just put 100x100








org.freehep.graphicsio.emf.EMFGraphics2D g = new org.freehep.graphicsio.emf.EMFGraphics2D(bos,new java.awt.Dimension(100,100));





molPrinter.setDispopts(molPrinter.getDispopts() | DispOptConsts.__Fields.RGROUPS_FLAG);





g.startExport();


molPrinter.paint(g, new java.awt.Rectangle(100, 100));


g.endExport();





byte[] barr = bArrOS .toByteArray();








Metafile metafile = new Metafile(new MemoryStream(barr));





Bitmap bitmapToSave = new Bitmap(100,100,PixelFormat.Format24bppRgb);





Graphics graphicUsedForConversion = Graphics.FromImage(bitmapToSave );





graphicUsedForConversion .FillRectangle(Brushes.White, 0, 0, 100, 100);





graphicUsedForConversion .DrawImage(metafile, 0, 0, 100, 100);


graphicUsedForConversion .Flush();


bitmapToSave .Save("your location", ImageFormat.Jpeg);














Please note that you will need to add references to freehep-graphicsio-emf-2.1.1,JChem and also IKVM.OpenJDK.ClassLibrary. You will also have to include some namespaces.





I hope this will help you.





P.S. We will try to fix the simple JPEG export in the future.

User 8df34b26ae

05-02-2009 20:04:41

Your example moved us a long way down the road.  I am now able to create the jpeg file with content on the web server (I did have to add some more dlls to the solution: freehep_graphicsio_2.1.1.dll, freehep_graphics2d_2.1.1.dll, IKVM.AWT.Winforms, freehep_util_2.0.2.dll and freehep_io_2.0.2.dll).





One issue remains:  you will see in the attached jpeg file that the content is very small and has very coarse resolution, such that it is not readable.   Attached also is the subroutine in which I included your example code (translated into vb.net, I also included intWidth and intHeight variables to allow customizing instead of having a hardcoded 100px value, I hope I did that correctly).  Do you have an idea as to how to enlarge/sharpen the jpeg content?





Thanks very much.

ChemAxon 6e93227fcc

05-02-2009 20:26:52

Hi,





You can also find a small example at http://www.chemaxon.com/marvin/help/developer/beans/api/chemaxon/marvin/MolPrinter.html .





The "magic" is to call the function "setScale" of the molprinter object.


p.setScale(p.maxScale(r)); // fit image in the rectangle where p is you molprinter object and r is you rectangle.





Calin.

User 8df34b26ae

06-02-2009 21:45:20

I may be missing another dll?   In the example, the import statements for java.awt.Color and java.awt.image.BufferedImage cause compilation errors (multiple kinds of members exist in the namespace?)

ChemAxon 6e93227fcc

06-02-2009 21:52:56

Hm this is strange... you should't get any compilation error because I tried the code by miself. Anyway you can try to remove the references and add them again. Also make a clean and a full rebuild.

ChemAxon 6e93227fcc

09-02-2009 15:13:15

Hi,





It seems the problem with jpg export directly from Molecule object is fixed in a newer version of IKVM (the third party tool). We will make a new build today and we will upload it on server.





In this was your original code should work without any workaround with EMF pictures.





Calin.

ChemAxon 6e93227fcc

09-02-2009 22:58:16

Hi,





You can check now the new .NET API release (it's name is the same 5.1.04) but now you should be able to obtain a JPEG directly using a code simillar with bellow:








Molecule molecule = MolImporter.importMol(molString);





byte[] binaryJpg = molecule .toBinFormat("jpeg");//put additional formatting in string parameter





save binary in a .jpeg file.














Calin.

User 8df34b26ae

13-02-2009 00:28:16

Calin, This looks to have done it, thanks!   I am now able to create .JPEG files with normal size/resolution.