개정판 bd75998a
add batch pdf export
Change-Id: I71a2ef02657930325d13f5bca131d29e8765efc3
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
1541 | 1541 |
options |= QFileDialog.DontUseNativeDialog |
1542 | 1542 |
file_name, _ = QFileDialog.getSaveFileName(self, "Export PDF", name, "pdf files(*.pdf)", options=options) |
1543 | 1543 |
name += '.png' |
1544 |
if file_name: |
|
1545 |
#pixMap = self.graphicsView.grab(QRect(QPoint(0, 0), QSize(int(self.graphicsView.scene().sceneRect().width()), int(self.graphicsView.scene().sceneRect().height())))) |
|
1546 |
#pixMap.save(name) |
|
1547 |
#return |
|
1548 |
|
|
1549 |
image = QImage(QSize(int(self.graphicsView.scene().sceneRect().width()), int(self.graphicsView.scene().sceneRect().height())), QImage.Format_ARGB32_Premultiplied) |
|
1550 |
painter = QPainter(image) |
|
1551 |
scene = self.graphicsView.scene() |
|
1552 |
canvasRect = scene.sceneRect() # or canvasRect = scene.border.boundingRect() |
|
1553 |
source = canvasRect |
|
1554 |
scene.render(painter, QRectF(image.rect()), source) |
|
1555 |
painter.end() |
|
1556 |
image.save(name) |
|
1557 |
image = Image.open(name) |
|
1558 |
image = image.convert('RGB') |
|
1559 |
image.save(name.replace('.png', '.pdf')) |
|
1560 |
os.remove(name) |
|
1561 |
painter.device() |
|
1544 |
if file_name: |
|
1545 |
self.save_PDF(name) |
|
1562 | 1546 |
|
1563 | 1547 |
QMessageBox.about(self, self.tr("Information"), self.tr('Successfully saved.')) |
1564 | 1548 |
return |
1549 |
elif len(checked_drawings) > 1: |
|
1550 |
name = os.path.join(project.getTempPath(), 'Select a Folder') |
|
1551 |
|
|
1552 |
options = QFileDialog.Options() |
|
1553 |
options |= QFileDialog.DontUseNativeDialog |
|
1554 |
file_name, _ = QFileDialog.getSaveFileName(self, "Export PDF", name, "pdf files(*.pdf)", options=options) |
|
1555 |
if file_name: |
|
1556 |
directory = os.path.dirname(file_name) |
|
1557 |
|
|
1558 |
for drawing in checked_drawings.keys(): |
|
1559 |
self.open_image_drawing(drawing, force=True, ocrUnknown=False) |
|
1560 |
|
|
1561 |
self.save_PDF(os.path.join(directory, drawing.name)) |
|
1562 |
|
|
1563 |
QMessageBox.about(self, self.tr("Information"), self.tr('Successfully saved.')) |
|
1565 | 1564 |
|
1566 | 1565 |
''' |
1567 | 1566 |
#app_doc_data = AppDocData.instance() |
... | ... | |
1601 | 1600 |
sys.exc_info()[-1].tb_lineno) |
1602 | 1601 |
self.addMessage.emit(MessageType.Error, message) |
1603 | 1602 |
|
1603 |
def save_PDF(self, file_name): |
|
1604 |
#pixMap = self.graphicsView.grab(QRect(QPoint(0, 0), QSize(int(self.graphicsView.scene().sceneRect().width()), int(self.graphicsView.scene().sceneRect().height())))) |
|
1605 |
#pixMap.save(name) |
|
1606 |
#return |
|
1607 |
|
|
1608 |
image = QImage(QSize(int(self.graphicsView.scene().sceneRect().width()), int(self.graphicsView.scene().sceneRect().height())), QImage.Format_ARGB32_Premultiplied) |
|
1609 |
painter = QPainter(image) |
|
1610 |
scene = self.graphicsView.scene() |
|
1611 |
canvasRect = scene.sceneRect() # or canvasRect = scene.border.boundingRect() |
|
1612 |
source = canvasRect |
|
1613 |
scene.render(painter, QRectF(image.rect()), source) |
|
1614 |
painter.end() |
|
1615 |
image.save(file_name) |
|
1616 |
image = Image.open(file_name) |
|
1617 |
image = image.convert('RGB') |
|
1618 |
image.save(file_name.replace('.png', '.pdf')) |
|
1619 |
os.remove(file_name) |
|
1620 |
painter.device() |
|
1621 |
|
|
1604 | 1622 |
def onSymbolThickness(self): |
1605 | 1623 |
""" symbol thickness reinforcement by using configuration filter drawing dilate size """ |
1606 | 1624 |
try: |
내보내기 Unified diff