[solved] dxf to pdf

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
TSG
Premier Member
Posts: 337
Joined: Thu Oct 08, 2015 9:39 am
Location: Germany

[solved] dxf to pdf

Post by TSG » Wed Sep 30, 2020 3:42 pm

QCAD 3.25.2 is running on my iMac with macOS Catalina (10.15.7).

I would like to convert all dxf in a folder to pdf via batch or script. How do I have to proceed under macOS?
Please step-by-step, as my Unix and script knowledge is only rudimentary.
Ich will nicht streiten. Ich will nur deutlich machen, dass ich Recht habe und DU NICHT.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: dxf to pdf

Post by andrew » Wed Sep 30, 2020 8:30 pm

You can find the dwg2pdf command line tool under macOS under /Applications/QCAD-Pro.app/Contents/Resources.

To convert all files in a directory, you'd typically run a bash script that calls dwg2pdf for all files in the folder. Here's an example bash script that converts all DXF files in a directory to PDF size A4 (-p A4), auto fitting to page (-a), overwriting existing files (-f):

Code: Select all

for file in *.dxf
do
    /Applications/QCAD-Pro.app/Contents/Resources/dwg2pdf -a -p A4 -f "$file"
done

TSG
Premier Member
Posts: 337
Joined: Thu Oct 08, 2015 9:39 am
Location: Germany

Re: dxf to pdf

Post by TSG » Thu Oct 01, 2020 1:45 pm

Many Thanks. The procedure works for me if I set the path manually in the terminal (cd) and then enter the program loop you mentioned ("for i = ...") in the terminal window. So far so good.

Then I tried to create an executable shell script ("#! / Bin / sh" and "chmod 755" filename ") according to instructions found on the web. Unfortunately, the path does not change, it is always the path under which the executable script was created used.

Although it is no longer a QCAD problem, I still hope to find help here.
Ich will nicht streiten. Ich will nur deutlich machen, dass ich Recht habe und DU NICHT.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: dxf to pdf

Post by andrew » Thu Oct 01, 2020 3:44 pm

You'd typically create the script in a folder that is in your PATH environment variable and execute it from wherever the folder with your files is.

For example:

- Save your bash script to /Users/yourname/bin/alldwg2pdf.sh

- Make it executable:

Code: Select all

chmod a+x /Users/yourname/bin/alldwg2pdf.sh
- Add this to your ~/.profile file:

Code: Select all

export PATH="/Users/yourname/bin:$PATH"
From now on, your script will be found from any directory in any new Terminal.

- Start a new Terminal

- cd to the path where your drawings are:

Code: Select all

cd /Users/yourname/mydrawings
- run the script:

Code: Select all

alldwg2pdf.sh

TSG
Premier Member
Posts: 337
Joined: Thu Oct 08, 2015 9:39 am
Location: Germany

Re: dxf to pdf

Post by TSG » Fri Oct 02, 2020 10:55 am

Thanks again.
After some troubleshooting, I got the script to work.
I got stuck at your "./alldxf2pdf.sh".
It should read: "alldxf2pdf.sh".
Last edited by TSG on Fri Oct 02, 2020 11:09 am, edited 1 time in total.
Ich will nicht streiten. Ich will nur deutlich machen, dass ich Recht habe und DU NICHT.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: dxf to pdf

Post by andrew » Fri Oct 02, 2020 10:57 am

Yes, I've corrected it in case anyone else reads this, thanks.

TSG
Premier Member
Posts: 337
Joined: Thu Oct 08, 2015 9:39 am
Location: Germany

Re: dxf to pdf

Post by TSG » Fri Oct 02, 2020 11:32 am

I've added a second for-do-loop in the script:

for file in *.dwg
do
/Applications/QCAD-Pro.app/Contents/Resources/dwg2pdf -a -p A4 -f "$file"
done

With this dwg are also converted to pdf.
Ich will nicht streiten. Ich will nur deutlich machen, dass ich Recht habe und DU NICHT.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: dxf to pdf

Post by andrew » Fri Oct 02, 2020 2:16 pm

For the record, this would also work:

Code: Select all

for file in *.dxf *.dwg
Note: Make sure that the file names don't contain spaces.

Post Reply

Return to “QCAD 'How Do I' Questions”