full pages
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
// components/MarkdownModal.tsx
|
||||
// app/components/MarkdownModal.tsx
|
||||
|
||||
import { X, Download } from "lucide-react";
|
||||
import { jsPDF } from "jspdf";
|
||||
import { useState } from "react";
|
||||
import { type PageObject } from "../page"; // Importer le type depuis la page principale
|
||||
|
||||
interface HtmlModalProps {
|
||||
content: string[] | null;
|
||||
content: PageObject[] | null; // Utilise le type PageObject importé
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
// Moteur de rendu HTML vers PDF, robuste et récursif
|
||||
const renderHtmlOnPdfPage = (pdf: jsPDF, htmlContent: string) => {
|
||||
const pageHeight = pdf.internal.pageSize.getHeight();
|
||||
const pageWidth = pdf.internal.pageSize.getWidth();
|
||||
@@ -105,10 +107,13 @@ export default function MarkdownModal({ content, onClose }: HtmlModalProps) {
|
||||
try {
|
||||
const pdf = new jsPDF({ orientation: "p", unit: "mm", format: "a4" });
|
||||
pdf.setFont("Helvetica", "normal");
|
||||
content.forEach((pageHtml, index) => {
|
||||
|
||||
// Mis à jour pour boucler sur les objets et passer le contenu HTML
|
||||
content.forEach((page, index) => {
|
||||
if (index > 0) pdf.addPage();
|
||||
renderHtmlOnPdfPage(pdf, pageHtml);
|
||||
renderHtmlOnPdfPage(pdf, page.htmlContent);
|
||||
});
|
||||
|
||||
pdf.save("document_anonymise.pdf");
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la génération du PDF:", error);
|
||||
@@ -117,9 +122,12 @@ export default function MarkdownModal({ content, onClose }: HtmlModalProps) {
|
||||
}
|
||||
};
|
||||
|
||||
const previewHtml = content.join(
|
||||
'<hr style="margin: 2.5rem 0; border-style: dashed; border-color: rgba(255,255,255,0.2);">'
|
||||
);
|
||||
// Mis à jour pour extraire le contenu HTML de chaque page avant de l'afficher
|
||||
const previewHtml = content
|
||||
.map((page) => page.htmlContent)
|
||||
.join(
|
||||
'<hr style="margin: 2.5rem 0; border-style: dashed; border-color: rgba(255,255,255,0.2);">'
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user