普段よく扱っているDTPアプリ/ファイル(InDesign、Photoshop、Illustrator、PDF)の中、色々座標系が存在する。
- InDesign&Photoshop:座標は左上、x>0、y>0
- Illustrator:
GUI:座標は左上、x>0、y>0
API:座標は左上、x>0、y<0 - PDF:座標は左下、x>0、y>0
※pymupdfだと、自動変換してくれるので、座標は左上、x>0、y>0
参考コード(Adobe系):
// InDesign var sel = app.selection[0]; var bounds = sel.visibleBounds; var x = bounds[1]; var y = bounds[0]; $.writeln("x: " + x); $.writeln("y: " + y); // Photoshop var doc = app.activeDocument; doc.selection.select([[1, 2], [5, 2], [5, 5], [1, 5]]); // Illustrator var sel = app.selection[0]; var x = sel.position[0];//point var y = sel.position[1];//point $.writeln("x: " + x * 25.4 / 72);//mm $.writeln("y: " + y * 25.4 / 72);//mm //(Acrobat)PDF var mm2pt = 72 / 25.4; var x1 = 5 * mm2pt;// 5mm var y1 = 10 * mm2pt; var x2 = 15 * mm2pt;//width: 15-5 = 10mm var y2 = 15 * mm2pt;//height: 15-10 = 5mm this.addAnnot({ type: "Square", rect: [x1, y1, x2, y2], page: 0, width: 0.2, strokeColor: color.red });
参考コード(fitz(PyMuPDF), reportlab):
import fitz from reportlab.pdfgen import canvas mm2pt = 72 / 25.4 x = 5 * mm2pt # 5mm y = 10 * mm2pt # 10mm w = 15 * mm2pt # width=15 h = 5 * mm2pt # height=5 new_doc = fitz.open() rect = fitz.Rect(x, y, x + w, y + h) page = new_doc.new_page() page.draw_rect(rect, width=0.1) page.draw_circle((x, y), 1, color=(1, 0, 0), fill=(1, 0, 0)) page.insert_text((x, y), "fitz", fontsize=10, color=(0, 0, 0)) new_doc.save("test_fitz.pdf") page = canvas.Canvas("test_reportlab.pdf") page.setLineWidth(0.1) page.rect(x, y, w, h, stroke=1) # page.setFont("Helvetica", 10) page.drawString(x, y, "reportlab") # draw a circle page.setFillColorRGB(1, 0, 0) page.circle(x, y, 1, fill=1, stroke=0) page.save()