Skip to content

Instantly share code, notes, and snippets.

@slazav

slazav/dxf2pdf.js

Last active Jul 31, 2020
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@slazav 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