From 5a226cd7cad340241b515e2bb1aa2932de885a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylvain=20Hall=C3=A9?= Date: Sun, 30 Sep 2018 17:11:19 -0400 Subject: [PATCH 1/2] Added command-line parameters to override the default x-width and y-width settings. Some documents don't have the default proportions of 1872x1404 pixels (for example, US Letter documents). Exporting the lines file as SVGs will result in lines placed at incorrect locations when superimposed onto the original PDF in those cases. The problem is solved when overriding these default settings with the proper pixel values for the document size (1805x1404 in the case of US Letter). The proposed modification allows users to specify these values as (optional) command line arguments. The default behavior of the program is left unchanged. --- tools/rM2svg | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/tools/rM2svg b/tools/rM2svg index ed1c268..c39c0c5 100755 --- a/tools/rM2svg +++ b/tools/rM2svg @@ -6,13 +6,9 @@ import argparse __prog_name__ = "rM2svg" -__version__ = "0.0.1beta" +__version__ = "0.0.2beta" -# Size -x_width = 1404 -y_width = 1872 - # Mappings stroke_colour = { 0: "black", @@ -56,8 +52,26 @@ def main(): parser.add_argument('--version', action='version', version='%(prog)s {version}'.format(version=__version__)) + parser.add_argument("-x", + "--x_width", + help="Set width of document in pixels.", + metavar="N", + ) + parser.add_argument("-y", + "--y_width", + help="Set height of document in pixels.", + metavar="N", + ) args = parser.parse_args() + if (args.x_width): + x_width = args.x_width + print(x_width) + + if (args.y_width): + y_width = args.y_width + print(y_width) + if not os.path.exists(args.input): parser.error('The file "{}" does not exist!'.format(args.input)) @@ -70,7 +84,7 @@ def main(): 3: "yellow" } - lines2svg(args.input, args.output, args.singlefile, args.coloured_annotations) + lines2svg(args.input, args.output, args.singlefile, args.coloured_annotations, args.x_width, args.y_width) def abort(msg): @@ -78,7 +92,7 @@ def abort(msg): sys.exit(1) -def lines2svg(input_file, output_name, singlefile, coloured_annotations=False): +def lines2svg(input_file, output_name, singlefile, coloured_annotations=False, x_width=1404, y_width=1872): # Read the file in memory. Consider optimising by reading chunks. with open(input_file, 'rb') as f: data = f.read() From cd694dd1491e2e1c58c353d87d301f1bfb09ff84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylvain=20Hall=C3=A9?= Date: Fri, 5 Oct 2018 07:39:14 -0400 Subject: [PATCH 2/2] Output files have 3 digits instead of 2 (to accommodate for documents of more than 99 pages) --- tools/rM2svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/rM2svg b/tools/rM2svg index c39c0c5..c1a8025 100755 --- a/tools/rM2svg +++ b/tools/rM2svg @@ -130,7 +130,7 @@ def lines2svg(input_file, output_name, singlefile, coloured_annotations=False, x if singlefile: output.write(''.format(page, 'none' if page != 0 else 'inline')) # Opening page group, visible only for the first page. else: - output = open("{}_{:02}.svg".format(output_name, page+1), 'w') + output = open("{}_{:03}.svg".format(output_name, page+1), 'w') output.write('\n'.format(y_width, x_width)) # BEGIN page fmt = '