Skip to content

Instantly share code, notes, and snippets.

@slazav
Last active July 31, 2020 11:29
Show Gist options
  • Save slazav/2c617b8e7ba09ec67e1e633b043f89dd to your computer and use it in GitHub Desktop.
Save slazav/2c617b8e7ba09ec67e1e633b043f89dd to your computer and use it in GitHub Desktop.
command-line converter DXF to PDF using QCAD
// Converting DXF file to PDF without GUI
// Usage:
// qcad -autostart dxf2pdf.js <in_file> <out_file>
//
// V.Zavjalov, 03.07.2020, GLP-3.0
include("scripts/simple.js");
include("scripts/File/Print/Print.js");
function main() {
if (args.length != 3) {
print("Usage: qcad -autostart " + args[0] + " <in_file> <out_file>");
return;
}
var i_file = getAbsolutePathForArg(args[1]);
var o_file = getAbsolutePathForArg(args[2]);
// create a document:
var doc = createOffScreenDocument();
// read DXF
var di = new RDocumentInterface(doc);
di.importFile(i_file);
// make view
var scene = new RGraphicsSceneQt(di);
var view = new RGraphicsViewImage();
view.setScene(scene);
// write PDF
var pr = new Print(undefined, doc, view);
pr.print(o_file);
}
main();
@slazav
Copy link
Author

slazav commented Jul 31, 2020

Converter script:

#!/bin/sh -efu

if [ $# -ne 2 ]; then
  printf "Usage $0 <in_file> <out_file>\n"
  exit 1
fi

XDG_RUNTIME_DIR=$(pwd)\
  qcad -no-dock-icon -no-gui -allow-multiple-instances -autostart @SCRIPTDIR@/dxf2pdf.js "$1" "$2"

See also Altlinux package: http://git.altlinux.org/people/slazav/packages/?p=qcad-dxf2pdf.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment