diff --git a/client/src/app/core/ui-services/html-to-pdf.service.ts b/client/src/app/core/ui-services/html-to-pdf.service.ts index cc5b6532f..648061c4f 100644 --- a/client/src/app/core/ui-services/html-to-pdf.service.ts +++ b/client/src/app/core/ui-services/html-to-pdf.service.ts @@ -75,6 +75,23 @@ export class HtmlToPdfService { */ public constructor() {} + /** + * Determine the ideal margin for a given node + * + * @param nodeName the parsing node + * @returns the margin bottom as number + */ + private getMarginBottom(nodeName: string): number { + switch (nodeName) { + case 'li': { + return this.LI_MARGIN_BOTTOM; + } + default: { + return this.P_MARGIN_BOTTOM; + } + } + } + /** * Takes an HTML string, converts to HTML using a DOM parser and recursivly parses * the content into pdfmake compatible doc definition @@ -154,8 +171,10 @@ export class HtmlToPdfService { case 'h4': case 'h5': case 'h6': - case 'p': { - const children = this.parseChildren(element, newParagraph); + case 'li': + case 'p': + case 'div': { + const children = this.parseChildren(element, styles); if (this.lineNumberingMode === LineNumberingMode.Outside) { newParagraph = this.create('stack'); @@ -165,15 +184,14 @@ export class HtmlToPdfService { newParagraph.text = children; } - newParagraph.margin = [0, this.P_MARGIN_BOTTOM]; + newParagraph.margin = [0, this.getMarginBottom(nodeName)]; newParagraph.lineHeight = this.LINE_HEIGHT; - styles = this.computeStyle(styles); const implicitStyles = this.computeStyle(this.elementStyles[nodeName]); newParagraph = { ...newParagraph, - ...styles, + ...this.computeStyle(styles), ...implicitStyles }; break; @@ -240,19 +258,6 @@ export class HtmlToPdfService { newParagraph.lineHeight = this.LINE_HEIGHT; break; } - case 'li': - case 'div': { - newParagraph = this.create('text'); - newParagraph.lineHeight = this.LI_MARGIN_BOTTOM; - newParagraph = { - ...newParagraph, - ...this.computeStyle(styles) - }; - - const children = this.parseChildren(element, styles); - newParagraph.text = children; - break; - } case 'ul': case 'ol': { newParagraph = this.create(nodeName); diff --git a/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts b/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts index 905c5eb0c..decf429a6 100644 --- a/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts +++ b/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts @@ -1155,7 +1155,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { public onDownloadPdf(): void { const exportCr = this.motion.isStatuteAmendment() ? ChangeRecoMode.Diff : this.crMode; // TODO: apparently statue amendments never have line numbers and are always in crMode - this.pdfExport.exportSingleMotion(this.motion, LineNumberingMode.None, exportCr); + this.pdfExport.exportSingleMotion(this.motion, this.lnMode, exportCr); } /** diff --git a/client/src/app/site/motions/services/motion-pdf.service.ts b/client/src/app/site/motions/services/motion-pdf.service.ts index f388427f1..3d3801303 100644 --- a/client/src/app/site/motions/services/motion-pdf.service.ts +++ b/client/src/app/site/motions/services/motion-pdf.service.ts @@ -10,6 +10,7 @@ import { MotionRepositoryService } from 'app/core/repositories/motions/motion-re import { StatuteParagraphRepositoryService } from 'app/core/repositories/motions/statute-paragraph-repository.service'; import { ViewMotion, LineNumberingMode, ChangeRecoMode } from '../models/view-motion'; import { ViewUnifiedChange } from '../models/view-unified-change'; +import { LinenumberingService } from 'app/core/ui-services/linenumbering.service'; /** * Type declaring which strings are valid options for metainfos to be exported into a pdf @@ -41,6 +42,7 @@ export class MotionPdfService { * @param configService Read config variables * @param htmlToPdfService To convert HTML text into pdfmake doc def * @param pollService MotionPollService for rendering the polls + * @param linenumberingService Line numbers */ public constructor( private translate: TranslateService, @@ -49,7 +51,8 @@ export class MotionPdfService { private changeRecoRepo: ChangeRecommendationRepositoryService, private configService: ConfigService, private htmlToPdfService: HtmlToPdfService, - private pollService: MotionPollService + private pollService: MotionPollService, + private linenumberingService: LinenumberingService ) {} /** @@ -436,6 +439,8 @@ export class MotionPdfService { // order of changes applied to the motion changes.sort((a, b) => a.getLineFrom() - b.getLineFrom()); motionText = this.motionRepo.formatMotion(motion.id, crMode, changes, lineLength); + // reformat motion text to split long HTML elements to easier convert into PDF + motionText = this.linenumberingService.splitInlineElementsAtLineBreaks(motionText); } return this.htmlToPdfService.convertHtml(motionText, lnMode);