Author Topic: Convert2DXF Command Line App  (Read 2246 times)

Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Convert2DXF Command Line App
« on: September 24, 2016, 10:52:01 AM »
Convert2DXF command line app is available to download and test.
Convert2DXF Command Line App

Included in the zip file is a readme.txt file that has several examples on how to call it.

The order of the parameters does not matter and the simplest way to call it is with one parameter, the PDF filename and path. If any paths have spaces in them you will need to wrap them in double quotes ("C:\my folder\mypdf.pdf", "C:\my folder\mydxf.dxf"). Specifying only the PDF file name and path will create the DXF file in the same directory as the PDF.

Parameters are separated by a space.

Other parameters include ...
The path and filename where to save the DXF file (file extension must be .dxf).
IN to specify Inches (defaults to Millimeters)
BCLMODE to convert paths to LwPolylines, arcs, and circles where it can.

If you have any issues please let me know.
Thanks
John

Zax

  • T2Laser
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5234
    • View Profile
    • T2Laser
Re: Convert2DXF Command Line App
« Reply #1 on: September 24, 2016, 12:29:39 PM »
That's perfect, I can interface to it without actually having to include it in the distribution.

Is this otherwise the same as Convert2DXF, just one has a GUI and the other is command line?

When you convert to lines (T2LMode) what is the "flatten" resolution used?

Zax

  • T2Laser
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5234
    • View Profile
    • T2Laser
Re: Convert2DXF Command Line App
« Reply #2 on: September 24, 2016, 02:54:45 PM »
I've implemented it in T2Laser but have a question/request.

I see it outputs a message of success or failure, but it doesn't appear to set the exit code. Is this something you could add?


Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Convert2DXF Command Line App
« Reply #3 on: September 24, 2016, 04:02:04 PM »
That's perfect, I can interface to it without actually having to include it in the distribution.

Is this otherwise the same as Convert2DXF, just one has a GUI and the other is command line?

When you convert to lines (T2LMode) what is the "flatten" resolution used?

yes, both the form and command line apps use the same library. This way I can throw on any UI and just make the calls to convert the PDF.

I don't specifically call any method to flatten it so I'm not sure what the answer to that is. I did change to high precision mode in the netDXF library so are you seeing something different than before? if it is causing problems I can default it to normal precision or you can pass in the PMLOW parameter and it will use normal precision like it was before. High precision mode enables more decimal places but that's about it as far as I can tell.

I will look into setting the exit code.

Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Convert2DXF Command Line App
« Reply #4 on: September 24, 2016, 04:17:03 PM »
Ok I figured out the exit code. I guess you learn something new every day.

Exit code 0 = all went well.
Exit code 1 = no PDF file specified
Exit code 2 = failed to convert PDF

If you just want 0 & 1 I can do that too.

The link in the first post has the latest version now.

Zax

  • T2Laser
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5234
    • View Profile
    • T2Laser
Re: Convert2DXF Command Line App
« Reply #5 on: September 24, 2016, 04:17:15 PM »
No problem, it works great. I can select a PDF now just like a vector file and it opens right up.

I was wondering if there was any advantage to using the BCL method and converting back to line segments (as I do for DXF files, with the user setting for resolution). I guess that makes no sense, conversions rarely do anything but make quality worse.

Thanks for all your effort on this, I really like the command line solution. It was so easy to implement.

Zax

  • T2Laser
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5234
    • View Profile
    • T2Laser
Re: Convert2DXF Command Line App
« Reply #6 on: September 24, 2016, 04:18:36 PM »
That was fast. Fantastic, that's exactly what I was hoping for.

I will test it and add the user responses based on the exit code.

Thanks again"

Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Convert2DXF Command Line App
« Reply #7 on: September 24, 2016, 04:31:01 PM »
No problem, it works great. I can select a PDF now just like a vector file and it opens right up.

I was wondering if there was any advantage to using the BCL method and converting back to line segments (as I do for DXF files, with the user setting for resolution). I guess that makes no sense, conversions rarely do anything but make quality worse.

Thanks for all your effort on this, I really like the command line solution. It was so easy to implement.

Probably not for your app but feel free to give it a try and nothing says you have to use T2LMode ;) . It is nice in BCL because it can reduce the number of total objects you have to work with when fixing direction and grouping, etc... When I do add the optimization routines it will be available in both T2LMode and BCLMode. This should help address the multiple copies of paths that lay on top of each other and this affects both modes because it is coming from the PDF that way. 

My pleasure :)

Next is text and images or optimization, not sure yet but I saw a post about images in dxf files and it made me wonder. netDXF has the ability to imbed images in the DXF file. I'm able to get the coordinates of the images from the PDF and the image data. Would you be able to use a DXF with an image in it and if so would that help you with the raster alignment issue? If that would help you at all I could work on adding that next.

Zax

  • T2Laser
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5234
    • View Profile
    • T2Laser
Re: Convert2DXF Command Line App
« Reply #8 on: September 24, 2016, 04:42:28 PM »
Perhaps if it works the same way, and saves the DXF and image (PNG or JPG) then I could load both. It may not help the alignment but it would still be a nice feature.

SVG would be great too, is the same DLL capable of converting those or is that a different project?

Exit code is working in T2Laser now.
« Last Edit: September 24, 2016, 04:47:52 PM by Zax »

Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Convert2DXF Command Line App
« Reply #9 on: September 24, 2016, 05:08:41 PM »
Perhaps if it works the same way, and saves the DXF and image (PNG or JPG) then I could load both. It may not help the alignment but it would still be a nice feature.

SVG would be great too, is the same DLL capable of converting those or is that a different project?

Exit code is working in T2Laser now.

I will have to play around with embedding an image in the DXF file, I assumed it was storing it in the PDF file but it may just be storing a reference to a file. Not sure but, I could save the image and just not imbed it in the DXF. Right now the test code just saves it to a file and writes the coordinates to the debug window. The trick would be getting you the path to the images and their coordinates. I can write the image paths and coordinates to the command window but then you would have to read the output to get that info.

SVG is another open source library that I will have to reference in my project and figure out how to convert its paths to dxf objects. I have the library just haven't figured it out yet lol. My goal is to make it seamless to the user so that if the program sees a filename with a PDF or SVG extension, it will call the appropriate code, do the conversion, and output a dxf file. So in your case, the user could pick a PDF or SVG file and your call to the command line app would be the same.

Zax

  • T2Laser
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5234
    • View Profile
    • T2Laser
Re: Convert2DXF Command Line App
« Reply #10 on: September 24, 2016, 06:07:57 PM »
I would be OK with getting the location and reference from the DXF, I wrote my own importer from scratch so can tweak it as needed. I don't think a DXF can actually hold an image so it must be a reference.

The problem I can see though is T2Laser doesn't currently support offsetting an image to coordinates, the lower left is always 0,0. That wouldn't be difficult to fix of course but it's just "something" else. You know how that is  ;D

I really like your concept for DXF or SVG, that would be excellent.

Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Convert2DXF Command Line App
« Reply #11 on: September 24, 2016, 07:51:05 PM »
Yeah I do know how that is lol.

I'll play around with the image in DXF and see what it does. netDXF has some samples in the source code for this so it shouldn't take much to find out what is going on in there.

Thanks for the support and kind words :)

Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Convert2DXF Command Line App
« Reply #12 on: September 25, 2016, 06:01:05 AM »
I confirmed that the images are stored as references to image files on disk. Here is an example from the netDXF library samples.

The image in this case needs to be in the same location as the dxf because it is in the dxf file without a path.

From the PDF, I can get the image's location, width, height, and image data which just means I can save the image to disk and create the ref for it in the DXF.

When I add this and text, should I add another parameter to include/exclude images and/or text in the conversion?

Thanks
John

Zax

  • T2Laser
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5234
    • View Profile
    • T2Laser
Re: Convert2DXF Command Line App
« Reply #13 on: September 25, 2016, 07:20:26 AM »
That's pretty cool, yes make it an option.

Obviously if the option isn't selected the image won't be saved out or referenced in the DXF. I will review my code to see how I'm going to implement the offset, I have a few ideas to make it quick and simple so will probably do that. Then I can test to see how the alignment looks and make an alignment adjustment feature if needed.

I have decided for now not to support text in my DXF importer, as it wasn't always coming in looking the same as exported. I found too many inconsistencies in how different programs were saving the information. It's also so easy to convert in most programs that it doesn't seem important. Your utility does a great job of converting it already so in a sense text is already supported for T2LMode.

Agastar

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1878
    • View Profile
Re: Convert2DXF Command Line App
« Reply #14 on: September 25, 2016, 10:19:41 AM »
Yeah I was surprised the first time I saw text in one of my tests but after looking into it I realized that some programs store the text as paths in the PDF. Another thing I may not have mentioned is that I'm handling both fill and stroke paths. Obviously I'm not filling any shapes but you get their outlines.

Yeah, stuff like image, text, and optimizations will be optional.

Since my brain is still somewhat wrapped around the PDF stuff I will probably finish up those items before I start working on the SVG support.