Spaces:
Running
Running
import gradio as gr | |
import subprocess | |
def rasterize_pdf(input_pdf): | |
output_pdf = "/tmp/output.pdf" | |
cmd = [ | |
"gs", | |
"-o", output_pdf, | |
"-sDEVICE=pdfwrite", | |
"-dFILTERVECTOR", | |
"-dCompatibilityLevel=1.4", | |
"-dPDFSETTINGS=/screen", | |
"-dNOPAUSE", | |
"-dBATCH", | |
"-dQUIET", | |
input_pdf | |
] | |
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
if result.returncode != 0: | |
return f"エラー: {result.stderr.decode()}", None | |
return "ラスタライズ完了", output_pdf | |
demo = gr.Interface( | |
fn=rasterize_pdf, | |
inputs=gr.File(file_types=[".pdf"]), | |
outputs=[gr.Text(), gr.File()], | |
title="PDFラスタライズ変換(Ghostscript)", | |
description="SVGベクターPDFをビットマップ化PDFに変換し、Audiveris用に軽量化します。" | |
) | |
demo.launch() | |