Vue 3's Paged.js does not respond to requests for page breaks

Currently, I'm working on implementing page breaks in Vue.js 3. Despite my efforts and utilization of the specified CSS code, I am facing challenges with the ".page-break" class parameter. While I can successfully modify other elements like titlePage for alignment adjustments, the execution of the page break feature remains elusive. Below are all the methods I've tried so far, without any external CSS imports except for the Vue-Showdown plugin that converts markdown to HTML.

Unfortunately, none of the attempted page break solutions showcased below have yielded positive results, leaving me perplexed as to why they are not functioning correctly.

*Please note that this functionality works perfectly fine if directly invoking a print function without involving PagedJS.

The specific requirement necessitates leveraging PagedJS to generate paginated content for updating a Table of Contents (TOC) with corresponding page numbers, which will be subsequently printed.

I have exhausted numerous attempts to troubleshoot the issue but to no avail, resulting in considerable frustration over the lack of success.

I have experimented with different styles and approaches to facilitate page breaks; however, the content does not seem to segment accordingly based on the provided specifications.

Answer №1

Utilizing Vue.js Variables within the DOM

If you're using Vue.js, you have the ability to display variable values enclosed within {{ and }} symbols. Additionally, if you wish to display HTML code alongside, make use of the v-html attribute.

You can also designate an existing DOM element as a reactive variable. By referring to my demonstration, observe how the copyableElement variable operates, allowing the transfer of content from the first div to the fourth one.

const { createApp, ref, reactive } = Vue;

const app = createApp({
  setup() {
    const titleContent = ref('My Title Content <br>and <strong>can\'t use</strong> HTML elements between {{ and }}');
    const restOfContent = reactive({
      innerHTML: `<strong>My</strong><br>HTML Content`
    });
    
    const copyableElement = ref(null);

    return {
      titleContent,
      restOfContent,
      copyableElement,
    };
  }
}).mount('#app');
div {
  margin: 10px 0;
}
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fc8a8999bccfd2cfd2c8">[email protected]</a>/dist/vue.global.prod.js"></script>

<div id="app">
  <div ref="copyableElement">Example Text What Can Copy<br>To Another Element</div>

  <div class="title-page">titleContent text: {{ titleContent }}</div>
  <div class="content-page" v-html="restOfContent.innerHTML"></div>
  <div class="content-page" v-html="copyableElement?.innerHTML ?? ''"></div>
</div>

Guidance on Applying Paged.js

The .pagedjs_pages represents the CSS class for styling the complete document. Within this structure, you have access to the .pagedjs_page class for individual page styling. To incorporate custom CSS stylings to content within these pages, consider adding your designated class such as .myPage to the relevant divs up for pagination.

Upon assigning the .myPage class as per necessity, Paged.js automatically identifies it and allocates the corresponding .pagedjs_page classes.

⚠️ Cautious Reminder
page-break-before, page-break-after, page-break-inside tend to be outdated

const { createApp, ref } = Vue;

const app = createApp({
  setup() {
    const pages = ref([]);

    // Generating content for pages
    function generateContent() {
      // Demonstrative simulated content
      const content = [
        "<h1>Page 1</h1><p>This is content for page 1.</p>",
        "<h1>Page 2</h1><p>This is content for page 2.</p>",
        "<h1>Page 3</h1><p>This is content for page 3.</p>"
      ];
      pages.value = content;
    }
    generateContent();

    return {
      pages,
    };
  }
});

app.mount('#app');
@page {
  size: A5;
  margin: 20mm;
  @bottom-right-corner {
    vertical-align: center;
    text-align: center;
    background: #fafafa;
    color: purple;
    content: "P. " counter(page);
  }
}

.pagedjs_page {
  border: 1px solid black;
  background-color: white;
}

.myPage {
  break-after: page;
}
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ec9a9989acdfc2dfc2d8">[email protected]</a>/dist/vue.global.prod.js"></script>
<script src="https://unpkg.com/pagedjs/dist/paged.polyfill.js"></script>

<div id="app">
  <div class="myPage" v-for="(pageContent, index) in pages" :key="index">
    <div v-html="pageContent"></div>
  </div>
</div>

Illustration Featuring Entirely HTML DOM

const { createApp, ref, reactive } = Vue;

const app = createApp({
  setup() {
    const content = ref('');
    
    const titleContent = ref('My Title Content');
    const restOfContent = reactive({
      innerHTML: `<strong>My</strong><br>HTML Content`
    });

    // Generating content
    function generateContent() {
      // Simulated content showcased for explanation
      content.value = `<html>
        <head>
          <title>Print Markdown</title>
          <style>
            /* shifted to component's style */
          </style>
        </head>
        <body>
          <div class="title-page">${titleContent.value}</div>
          <div class="content-page">${restOfContent.innerHTML}</div>
          <div class="footer"></div>
        </body>
        </html>
      `;
    }
    generateContent();

    return {
      content,
    };
  }
});

app.mount('#app');
/* refined layout */

.pagedjs_page {
  border: 1px solid black;
  background-color: white;
}

/* original settings */

@page {
  size: A5; /* revised from A4 */
  margin: 20mm;
  @bottom-right-corner {
    vertical-align: center;
    text-align: center;
    background: #fafafa;
    color: purple;
    content: "P. " counter(page);
  }
}

h1 {
  break-before: page;
  page-break-before: always;
}

.pagedjs_page {
  break-before: page;
  page-break-before: always;
}

@media print {
  h1, h2 {
    break-before: page;
    page-break-before: always;
  }
  .page-break {
    break-before: page;
    page-break-before: always;
  }
}

@media screen {
  h1, h2 {
    break-before: page;
    page-break-before: always;

  }
  .page-break {
    break-before: page;
    page-break-before: always;
  }
}

table, figure {
  page-break-inside: avoid; /* Preventing breaks across pages for these elements */
} 

.title-page {
  break-after: always;
  page-break-before: always;
  text-align: center;
  padding-top: 60mm;
}

.page-break {
  break-before: page;
  page-break-before: always;
}

.content-page {
  padding: 15mm 20mm;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 10mm auto;
} 
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1563607055263b263b21">[email protected]</a>/dist/vue.global.prod.js"></script>
<script src="https://unpkg.com/pagedjs/dist/paged.polyfill.js"></script>

<div id="app">
  <div v-html="content"></div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Vue application experiencing an issue with data not being populated

I am having trouble retrieving data from my vuex store in a component using computed. Strangely, I am unable to access userInfo.uid in some of my components. Even though VueTools shows that it has been successfully imported, it keeps throwing an error stat ...

Samsung mini devices experiencing issues displaying Unicode symbol (25be)

I'm currently facing an issue with an iconfont that I have included in my website. I am using Unicode symbols for the characters of the icons, and most of them are displaying correctly. However, there are a couple that are showing up as blank on the s ...

Move the footer down to the bottom of the page

I'm struggling to create a footer that consistently stays at the bottom of the page, regardless of the amount of content on the page. I've tried following various tutorials but haven't had much success. I'm starting to think I must be d ...

Is it possible to place a secondary read more button next to the first one using CSS?

If you notice the code snippet, you will see that a "read more" button appears. How can I add another "read more" button to align side by side? I may even want to include three "read more" buttons, each opening in a separate modal box. ...

What is the best way to make a JavaScript cookie remember the state of a DIV?

Seeking assistance with a test site here that is currently in development. I am attempting to make the notification at the top remain hidden once the close button is clicked. Below is my current script: <style type="text/css"> <!-- .hide { displ ...

What is the best way to modify the input value in a Vue component when it is initially set, and then update it if it becomes an array

When looping through my array of articles, I dynamically generate multiple input boxes. Each input box's value is populated using the "value" key within each object in the array. <div v-for="(option, i) in this.articles" :key="i& ...

The Element should take up the entire page with the exception of a 20px margin

I am struggling to create an element that covers the entire page except for a 20px margin on all sides. I have tried implementing a solution using this code, which works in webkit browsers and Firefox but seems to have issues with Internet Explorer (10) an ...

What is the best way to delete previously entered characters in the "confirm password" field after editing the password

Is there a way to automatically remove characters in the confirm password field if characters are removed from the password field? Currently, when characters are entered into the password field, characters can also be entered into the confirm password fiel ...

What is the best way to synchronize the image dimensions and source when dynamically loading images?

I am facing an issue with a function that updates images by altering the src and css (width/height) of an IMG tag within the document. Below is a simplified example to demonstrate the problem: updateImage = function(src, width, height) { $("#changeMe"). ...

Ways to resolve the form submission issue on ASP.NET Core 3.1 with jQuery integration

I've been encountering issues and I'm looking to the community for help. A year or two ago, a web application was created using ASP.NET Core 3.1 with Razor Pages and C# code behind files. jQuery is also being utilized on the site. The problem li ...

What is the method for altering the text color within a disabled input field?

Currently facing difficulty in changing the color of the text within the input field when it's disabled. I'm utilizing Material UI for this purpose. import React from "react"; import { makeStyles } from "@material-ui/core/st ...

The mouseover animation doesn't reset to its original position during quick movements, but instead continues to move without interruption

Greetings! Welcome to my live page. Currently, I am facing an issue with the sliding animation on the header. Specifically, the small gray slide-up divs at the bottom of the sliding pictures are not behaving as expected. They are meant to slide up on mous ...

Guide on serving static HTML files using vanilla JavaScript and incorporating submodules

Is it possible to serve a static html file with elements defined in a javascript file using imports from submodules using vanilla JS? Or do I need bundling tools and/or other frameworks for this task? Here's an example code structure to showcase what ...

Choose an element on a webpage by leveraging the power of Selenium

When working with Selenium in FireFox, I encountered an issue while trying to select specific fields on a webpage. The HTML pages I am referring to are available at the following links: Sample HTML Page, another sample page. The code snippet I used is sh ...

Issue with AngularJS in Internet Explorer 7: "querySelector" property or method not supported by object

Incorporating angularjs into an existing asp.net project has presented a challenge due to the project's dependency on IE 7 compatibility mode. Upon running the project, an error from the angularjs file was encountered: Object doesn't support pro ...

Internet Explorer is having issues displaying CSS text accurately, particularly in relation to the background-

Having an issue with Internet Explorer not displaying my background clipped text correctly. In other browsers like Chrome and Firefox, the code renders fine: https://i.stack.imgur.com/x9lio.png However, in IE it appears differently: Your code: HTML: & ...

Ensure that the child div remains at the bottom of the parent div

I'm trying to make sure that the subfooter div stays at the bottom of the childbox div like a footer. You can see the code on this jsfiddle link <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <title ...

Issue with closing collapsed menu on click in Bootstrap version 3

Here is the code snippet: <li> <a href="#" id="statics" class="main-bar"> <span class="glyphicon glyphicon-stats" aria-hidden="true"></span> </a> </li> I am trying to toggle the responsive menu on eleme ...

IFrame transparency setting not recognized

I am encountering an issue with transparency when adding an iframe to a webpage. I have set the allowTransparency attribute of the iFrame to true, but upon inspecting the element using Internet Explorer's F12 Developer Tools, I noticed that although t ...

What are the best practices for utilizing bootstrap-vue's panel component effectively?

Transitioning my project from vue-strap to bootstrap-vue has hit a snag for me. I'm having difficulty migrating the panel. Here's the current vue-strap code snippet: <div class="col-sm-3"> <panel is-open type="info"> < ...