Create a PDF document with the background of the input text included and printable

I am trying to find a way to make the background image of the input text appear when saving the page as a PDF (right-click, select "Print ...," and then "Save as PDF").

The page has a square background image that creates the effect of each character being typed into a square.

Below is an example code snippet to illustrate my point:

#text
    {
    background-image: url("http://3.bp.blogspot.com/-4oAWWCcNNz4/Tjr3nKNyVUI/AAAAAAAAPLU/Pouua-pNsEY/s1600/sq.gif");     
    width: 213px;
    height: 18px;
    background-size: 20px;
    border: none;
    font-family: monospace;
    font-size: 13px;
    padding-left: 5px;
    letter-spacing: 12px;
    }
Name: <input type="text" size="10" maxlength="10" id="text"/>

If anyone has any suggestions on how to enable this feature for printing or any other solution that provides the same functionality of continuous typing, highlighting, and deleting text, I would greatly appreciate it.

Answer №1

To achieve this, utilize the 'color-adjust' CSS property and define specific configurations for '@media print' CSS at-rule when printing.

The following code provides a simple solution using only color-adjust along with -webkit-print-color-adjust:

#text {
    background-image: url("http://3.bp.blogspot.com/-4oAWWCcNNz4/Tjr3nKNyVUI/AAAAAAAAPLU/Pouua-pNsEY/s1600/sq.gif");        
    width: 213px;
    height: 18px;
    background-size: 20px;
    border: none;
    font-family: monospace;
    font-size: 13px;
    padding-left: 5px;
    letter-spacing: 12px;
    -webkit-print-color-adjust: exact !important;   /* Chrome, Safari */
    color-adjust: exact !important;                 /*Firefox*/
}
Name: <input type="text" size="10" maxlength="10" id="text"> 

Confirmed to work on FireFox 85.

This response was influenced by the discussion in the thread How can I force browsers to print background images in CSS?, which delves into the advantages and disadvantages of printing background images.

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

Is it possible to securely share login details on the internet?

I'm currently brainstorming different ways to securely display FTP, database, and hosting information for website projects on my project management site. One potential solution I'm considering is encrypting the passwords and developing an applica ...

Retry request with an AngularJS interceptor

Currently, I am in the process of developing an Angular application and encountering some challenges while implementing a retry mechanism for the latest request within an HTTP interceptor. The interceptor is primarily used for authentication validation on ...

Ways to eliminate the default margin surrounding an image within a div

Struggling with CSS while building websites is a common issue for me. In my current project, I have encountered a challenge where I placed two images inside a div container. Oddly enough, when I add text to the div, it adjusts its height accordingly. How ...

Guide on placing a featured image in a div element within genesis theme

I'm encountering a minor issue when trying to work with the genesis framework. My objective is to have each post's featured image inside a div with the same class. I aim to be able to set a background image for the outer div so that when a user h ...

Unexpected Website Homepage (Vue / Javascript)

I am looking to display a different .vue file each time a visitor refreshes the Home page. Currently, I only have one page called Home.vue. I am attempting to randomly load either Home1.vue or Home2.vue with each refresh. { path: '/', name: ...

Using jQuery to dynamically insert an HTML element into a table

I'm trying to insert a hyperlink into an empty HTML table. This function works perfectly fine on Firefox and Chrome, taking only 0.2 seconds to load. However, when I try it on IE9, it takes at least 3 minutes to display the link. The issue seems to be ...

What is the process for utilizing the Bootstrap required field for a type of "button" rather than "submit"?

Check out my code below: <form> <div class="input-group"> <span class="input-group-addon"><i class="fa fa-envelope fa-10x"></i></span> <input type="email" class="for ...

What is the method of locating the default export reference of a file in Visual Studio Code?

Is it possible to locate the reference file that is exported by default in Visual Studio Code? The key shortcut to find all references in VSCode is: alt + shift + f12. For instance, consider finding data.js. async function update(req, res) { res.render ...

The browser does not support the display of Spanish special characters

I am working on a website and need to incorporate support for the Spanish language. I have prepared an XML file with both English and Spanish text. The XML file is being read based on the user's selection of language from a dropdown menu. Everything s ...

Customizing skin CSS for DNN Portal and Page images

Currently, I have a unique custom skin that I personally created. It is implemented on multiple portals that I am responsible for managing. My goal is to incorporate the ability for the header image to change based on the specific page being viewed. The he ...

Arranging numbers in JavaScript lists

empList = [ { "Account": "AAA - 0029", "Available": "$100" }, { "Account": "BBB- 0146", "Available": "200" }, { "Account": "AAA - 1812", "Available": "300"}, { "Account": "CCC- 2019", "Available": "400"}, { "Account" ...

Troubleshooting Node.js TypeScript breakpoints in Visual Studio Code

I've attempted multiple solutions, but none seem to be working for me. Although the code is running, I'm having trouble setting breakpoints and debugging it. Can you offer any assistance? Below is the configuration script I've tried in VSCo ...

Is it acceptable to debut a full-screen iframe widget compared to an embedded one?

My current project involves integrating a custom widget into users' websites for my application. I am considering using an iframe as it seems to be the most efficient option for several reasons: Utilizing the custom framework of the application will ...

What could be causing the user object to be undefined in the NextAuth session callback function?

I'm experiencing an issue with NextAuth while trying to implement signIn with Discord provider. My goal is to add the userID into the session object using the session callback, but I keep encountering an error message stating: [next-auth][error][JWT ...

When you hover over the page, the content shifts to reveal a hidden div

Trying to figure out how to show additional content when a photo is hovered over without shifting the rest of the page's content placement? Looking for alternative solutions rather than using margin-top: -22%. Here's a link to the website in que ...

Getting the IDs of selected nodes all the way up to the root node in jsTree

How can I retrieve the IDs of all parent nodes from a selected node to the root node in jsTree? If node C is selected, how can I obtain the IDs of all its parent nodes? Tree Structure: B C +C1 +c2 The following code snippet only returns the imme ...

What is the best way to ensure the alignment of list content and numbering remains separate in HTML while using list-style-position set to inside?

Below is a list with customized styling: ol { background: #ff9999; padding: 20px; list-style-position: inside; } ol li { background: #ffe5e5; padding: 5px; } <ol> <li>Coffee</li> <li>Tea</li> <li>Coca ...

The visibility of the button background created with :before will only be apparent when a content property is specified

There's an unusual issue I've encountered... I have a simple button, nothing out of the ordinary, just a basic button like this <button class="btn btn--error"> Button Text </button> Now, I want to add an image next to my button ...

Detecting page change cancellation using jQuery/Javascript event

Is there a way to detect when a user cancels a page load in an AJAX-based website with heavy modal/loading screen usage? We rely on modal/loading screens to indicate important actions, but for full page changes that can take a couple seconds, we want to i ...