Esempio n. 1
0
def prepare_badge_pdf(svg_filepath):
    """ from the badge SVG file path prepare a PDF for printing. Returns the pdf file path. """
    pdf_filepath = svg_filepath.replace('.svg', '.pdf')

    svg2pdf(svg_filepath, pdf_filepath, dpi=300)

    pdf_pair_file = create_badge_faces(pdf_filepath)

    return pdf_pair_file
Esempio n. 2
0
def prepare_badge_pdf(svg_filepath, doublepages=True):
    """ from the badge SVG file path prepare a PDF for printing. Returns the pdf file path. """
    pdf_filepath = svg_filepath.replace('.svg', '.pdf')

    svg2pdf(svg_filepath, pdf_filepath, dpi=300)

    if doublepages:
        pdf_pair_file = create_badge_faces(pdf_filepath)
        return pdf_pair_file
    else:
        return pdf_filepath
Esempio n. 3
0
    def create_badge_pdf(contact, output_dir,  ):
        """

        Parameters
        ----------
        contact

        Returns
        -------

        """
        CONTACT = create_contact(ATTENDEE)

        if not get_attendee_type(CONTACT.Email) is BADGE_TYPE:
            continue

        badge_filepath = get_badge_filename(CONTACT, output_dir, with_email=True)
        pdf_filepath   = badge_filepath.replace('.svg', '.pdf')

        TEST_BADGE = False
        if CHECK_IF_EXIST:
            # if check will create a new file and compare it to the old one.
            if op.exists(pdf_filepath):
                ORIG_BADGE_FILEPATH = badge_filepath
                ORIG_PDF_FILEPATH   = pdf_filepath
                BADGE_FILEPATH      = badge_filepath.replace('.svg', '.2.svg')
                pdf_filepath        = pdf_filepath.replace  ('.pdf', '.2.pdf')
                TEST_BADGE = True

        # generate pdf file
        generate_contact_badge(CONTACT, badge_filepath)
        svg2pdf(badge_filepath, pdf_filepath, dpi=300) #, inkscape_binpath=INKSCAPE_BINPATH)

        time.sleep(3)
        os.remove(badge_filepath)

        #check if the generated if the same as the old one
        if TEST_BADGE:
            if not filecmp.cmp (pdf_filepath, ORIG_PDF_FILEPATH, shallow=False):
                shutil.copyfile(pdf_filepath, ORIG_PDF_FILEPATH)
                os.remove      (pdf_filepath)
                PDF_FILEPATH  = ORIG_PDF_FILEPATH
            else:
                os.remove(pdf_filepath)
                continue

        #create pair-of-badges pdf
        PDF_PAIR_FILE = create_badge_faces(PDF_FILEPATH)
        BADGE_FILEPATHS.append(PDF_PAIR_FILE)
        print(BADGE_FILEPATH)
Esempio n. 4
0
                        choices=['pdf', 'png'],
                        action='store',
                        dest='file_type',
                        default='pdf',
                        help='Output file type')
    #parser.add_argument('--dpi', type=int, action='store', dest='dpi',
    #                    default=150, help='Output file resolution')
    return parser


if __name__ == '__main__':

    parser = create_argparser()

    try:
        args = parser.parse_args()
    except argparse.ArgumentError as exc:
        log.exception('Error parsing arguments.')
        parser.error(str(exc.message))
        exit(-1)

    input_file = args.input
    output_file = args.output
    file_type = args.file_type
    dpi = args.dpi

    if file_type == 'png':
        svg2png(input_file, output_file, dpi=dpi)
    elif file_type == 'pdf':
        svg2pdf(input_file, output_file, dpi=dpi)
Esempio n. 5
0
    parser.add_argument('-o', '--output', action='store', dest='output',
                        help='Output file path')
    parser.add_argument('-t', '--type', choices=['pdf', 'png'],
                        action='store', dest='file_type', default='pdf',
                        help='Output file type')
    parser.add_argument('--dpi', type=int, action='store', dest='dpi',
                        default=150, help='Output file resolution')
    return parser


if __name__ == '__main__':

    parser = create_argparser()

    try:
        args = parser.parse_args()
    except argparse.ArgumentError as exc:
        log.exception('Error parsing arguments.')
        parser.error(str(exc.message))
        exit(-1)

    input_file = args.input
    output_file = args.output
    file_type = args.file_type
    dpi = args.dpi

    if file_type == 'png':
        svg2png(input_file, output_file, dpi=dpi)
    elif file_type == 'pdf':
        svg2pdf(input_file, output_file, dpi=dpi)
Esempio n. 6
0
def svg_to_pdf(ctx, output_dir):
    for filepath in glob(os.path.join(output_dir, '**', '*.svg')):
        svg2pdf(filepath, filepath.replace('.svg', '.pdf'))
Esempio n. 7
0
    logger.debug(f"Adding QR code to {badge_filepath}.")
    assert os.path.exists(badge_filepath)

    qrcode_figure = get_person_qrcode_figure(person)

    badge_figure = _add_qrcode(badge_filepath, qrcode_figure)
    badge_figure.save(badge_filepath)

# In[ ]:

from glob import glob
from docstamp.inkscape import svg2pdf

for svg_file in glob(os.path.join(docstamp_output_dir, "*.svg")):
    logger.info(f"Converting {svg_file} to PDF.")
    svg2pdf(svg_file, svg_file.replace(".svg", ".pdf"), dpi=150)
    os.remove(svg_file)

# In[ ]:

import shlex


def pdf_to_cmyk(input_file: str, output_file: str):
    cmd = ("gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite "
           "-sColorConversionStrategy=CMYK "
           "-dProcessColorModel=/DeviceCMYK "
           '-sOutputFile="{}" "{}"'.format(output_file, input_file))
    logger.info(f"Calling: {cmd}")
    subprocess.call(shlex.split(cmd))