在我的示例中,我定义了一个简单的页面,其中包含一个巨无霸和两列,每列都有不同的标题和背景色。在浏览器中查看HTML模板时,按预期将看到Jumbotron的2列布局。在查看IronPdf创建的pdf时,列会折叠成一个单列布局,其中每个div都堆叠且全宽。
我遵循了IronPDF https://ironpdf.com/docs/questions/html-to-pdf-responsive-css/
提供的示例证明问题的项目位于: https://github.com/crumdev/IronPdfExample
我希望PDF的输出能够反映浏览器中显示的内容,因为我需要使用列格式才能创建具有所需的多列布局的PDF布局。
答案 0 :(得分:1)
我处于相同的情况,但适用于4.0.0引导程序并遵循以下代码:
注意:如果看不到某些列,请尝试在每行内组织col div
import sys
import matplotlib
matplotlib.use('Qt5Agg')
import mplcursors
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow, QMenu, QVBoxLayout, QHBoxLayout, QSizePolicy, QWidget, \
QTextBrowser, QLineEdit
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.animation import FuncAnimation
from Entities import Soldier, CompanyCommander, BTW, FieldObjects
class MyMplCanvas(FigureCanvas):
fig = Figure(figsize=(5, 4), dpi=200)
ax = fig.add_subplot(1, 1, 1)
def __init__(self, parent=None):
FigureCanvas.__init__(self, MyMplCanvas.fig)
self.setParent(parent)
FigureCanvas.setSizePolicy(self,
QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
class ApplicationWindow(QtWidgets.QMainWindow):
soldiers = []
picked_soldier = []
s1 = Soldier(1, (3, 4), 100)
s2 = Soldier(2, (5, 6), 100)
s3 = Soldier(3, (1, 6), 100)
s4 = BTW(1, (2, 3), 100)
s5 = BTW(2, (3, 3.5), 100)
s6 = BTW(3, (4.2, 3.7), 100)
s7 = Soldier(1, (5.3, 4), 100)
s8 = Soldier(2, (2.6, 4.3), 100)
s9 = Soldier(3, (7, 5.2), 100)
soldiers = [s1, s2, s3, s4, s5, s6, s7, s8, s9]
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setWindowTitle("application main window")
self.main_widget = QtWidgets.QWidget(self)
vbox = QtWidgets.QVBoxLayout(self.main_widget)
self.canvas = MyMplCanvas(self.main_widget) ###attention###
vbox.addWidget(self.canvas)
hbox = QtWidgets.QHBoxLayout(self.main_widget)
self.setLayout(vbox)
self.main_widget.setFocus()
self.setCentralWidget(self.main_widget)
self.ani = FuncAnimation(self.canvas.figure, self.animate, interval=1000, blit=False)
self.curs = mplcursors.cursor(hover=True, highlight=True).connect("add", lambda sel: sel.annotation.set_text(sel.artist.get_label()))
self.canvas.figure.canvas.mpl_connect('pick_event', ApplicationWindow.on_pick)
def animate(self, i):
self.canvas.ax.clear()
self.create_plot()
def create_plot(self):
for s in self.soldiers:
if s.company_number == 1:
if type(s) == Soldier:
self.canvas.ax.plot(s.x, s.y, marker='o', markersize=5, color="blue", picker=5, label=s.__str__())
else:
self.canvas.ax.plot(s.x, s.y, marker='*', markersize=5, color="blue", picker=5, label=s.__str__())
elif s.company_number == 2:
if type(s) == Soldier:
self.canvas.ax.plot(s.x, s.y, marker='o', markersize=5, color="red", picker=5, label=s.__str__())
else:
self.canvas.ax.plot(s.x, s.y, marker='*', markersize=5, color="red", picker=5, label=s.__str__())
elif s.company_number == 3:
if type(s) == Soldier:
self.canvas.ax.plot(s.x, s.y, marker='o', markersize=5, color="green", picker=5, label=s.__str__())
else:
self.canvas.ax.plot(s.x, s.y, marker='*', markersize=5, color="green", picker=5, label=s.__str__())
else:
continue
def on_pick(event):
this_point = event.artist
x_data = this_point.get_xdata()
y_data = this_point.get_ydata()
ind = event.ind
for soldier in ApplicationWindow.soldiers:
if soldier.x == x_data and soldier.y == y_data:
index = soldier.ID - 1
ApplicationWindow.picked_soldier.append(soldier)
break
print(str(float(x_data[ind])) + ", " + str(float(y_data[ind])))
print(str(ApplicationWindow.soldiers[index].__str__()))
MyMplCanvas.fig.canvas.mpl_connect('button_press_event', ApplicationWindow.on_click)
MyMplCanvas.fig.canvas.mpl_disconnect(MyMplCanvas.fig.canvas.mpl_connect
('pick_event', ApplicationWindow.on_pick))
def on_click(event):
x_data = event.xdata
y_data = event.ydata
if len(ApplicationWindow.picked_soldier) > 0:
soldier = ApplicationWindow.picked_soldier.pop(0)
soldier.update_location(x_data, y_data)
print(x_data, y_data)
MyMplCanvas.fig.canvas.mpl_connect('pick_event', ApplicationWindow.on_pick)
MyMplCanvas.fig.canvas.mpl_disconnect(MyMplCanvas.fig.canvas.mpl_connect('button_press_event', ApplicationWindow.on_click))
if __name__ == "__main__":
App = QApplication(sys.argv)
aw = ApplicationWindow()
aw.show()
sys.exit(App.exec_())
答案 1 :(得分:1)
我收到IronPdf的回复:
我让我的工程师对此进行了研究,目前引导程序与IronPDF尚不完全兼容。这是我们已经计划在今年晚些时候为我们的下一个版本进行开发的东西。我已将其记录下来,当我们能够解决此问题时,它将使您保持最新。谢谢你的耐心。