joseluisq / printd Goto Github PK
View Code? Open in Web Editor NEWPrint HTML elements or pages in modern browsers.
License: MIT License
Print HTML elements or pages in modern browsers.
License: MIT License
Background colors for elements such as div do not show up. Was able to reproduce this in the playground as well
Base on :
1.4.0
here my code :
mounted() {
console.log("when component is mounted!");
this.d = new Printd();
const iframe = this.d.getIFrame();
const { contentWindow } = iframe;
contentWindow.addEventListener("beforeprint", () =>
console.log("before print event!")
);
contentWindow.addEventListener("afterprint", () =>
console.log("after print event!")
);
},
// Methods
methods: {
print() {
this.d.print(this.$el, [this.cssText]);
}
}
Is it possible to pass headers to the printURL() method? I'm testing printd in a single page application and the endpoint is locked behind JWT authentication.
I could attach the token to the url.
I feel a more elegant approach would be better.
Hi!, is there any way to disable headers and footers by default?
The plugin should create a <style> element if the element passed is not an url and a element if the element is a valid url.
When creating elements from urls the plugin alternatively creates a corrent element and an incorrect one.
For example:
const styles = [
"https://.../css/chunk-019a112c.78b8d35d.css",
"https://.../css/chunk-04aba45e.8c018d83.css"
]
results in
<link type="text/css" rel="stylesheet" href="https://.../css/chunk-019a112c.78b8d35d.css">
<style type="text/css">https://.../css/chunk-04aba45e.8c018d83.css</style>
v1.3.0
1.51
109.0.5414.87
(1) Press 'print button'
(2) Cancel print modal
mounted() {
// Printd
this.d = new Printd()
},
methods: {
print() {
const callback = ({ launchPrint }) => {
launchPrint()
}
this.d.print(document.getElementById('printing'), [], [], callback)
// then add your event handlers
const { contentWindow } = this.d.getIFrame()
if (contentWindow) {
contentWindow.addEventListener('beforeprint', () => {
console.log('before print event!')
})
contentWindow.addEventListener('afterprint', () => {
console.log('after print event!')
})
}
},
},
Hi, I'm trying to print a chart generated with chartjs but the chart doesn't appears in the print.
This what I'm doing
`const doc = new Printd()
const css = cssText: [`
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: 'Segoe UI';
font-size: 14px;
}
.chartjs-render-monitor {
-webkit-animation: chartjs-render-animation 0.001s;
animation: chartjs-render-animation 0.001s;
}
.table {
border: none;
border-right: solid 1px #C6E2FF;
border-collapse: separate;
border-spacing: 0;
margin-bottom: 15px;
}
.table thead th {
background-color: #ECF5FF;
/border: none;/
border-right: solid 1px #C6E2FF;
color: #336B6B;
padding: 10px;
text-align: center;
text-shadow: 1px 1px 1px #fff;
white-space: nowrap;
}
.table tbody td {
border-bottom: solid 1px #C6E2FF;
color: #333;
padding: 5px;
text-shadow: 1px 1px 1px #fff;
white-space: nowrap;
}]
const scripts = [
'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/0.2.0/Chart.min.js',
(() => console.log('Hello from IFrame!'))()
]
doc.print(document.getElementById('printArea'), css, scripts)`
All the rest of the elements shows in the print dialog except for the chart.
I'm working with vuejs, with the webpack template.
Hope you can help me.
Printing should work in IE11
Printing does not work in IE11. When attempting to print, a message is displayed in the console stating: "TypeError: Object doesn't support property or method 'assign'"
. It looks like this is caused by printd using Object.assign which isn't supported in IE11, so it needs a polyfill.
const printd = new Printd();
d.print( document.getElementById('myelement'), [ cssText ] );
Manually polyfill Object.assign, but I think the distributable code for printd should already be including the polyfill.
v1.4.1
v12.16.2
IE11 - v11.1425.17134.0
A selected option of select html tag should be printed
By default, the printed version is showing the first option of select tag and not the selected option.
...
v1.4.1
v0.0.0
v10.15.3
Chrome Versión 83.0.4103.61
Hello,
How can I use a css file located at the very same folder that is the .ts file using Printd. I mean, i want to use a sibling css file instead of passing plain text to the print function?. I've tried a lot of path form (absolute, relative), etc.
By the way, thanks a lot for the code!
Greetings!
Creating an instance of Printd passing an options object should function without errors.
Appending the iframe on the parent element results in an error "TypeError: parent.appendChild is not a function";
Passing manually window.document.body as the parent field of the options object doesn't solve the problem.
const options = { headElements }
const p = new Printd(options)
v1.3.0
Hi!
Is there a way to automatically include a page counter in the footer of all pages?
IE, Chrome and Firefox
Give an idea of how to change the title.
open print dialog
no action => when looking at the browser-console, there is no output
when looking at the browser-elements the iframe gets successfully created
use printURL function like following:
d.printURL(fileWithSignedUrl.signedUrl, ({ launchPrint }) => {
console.log('Content loaded!')
// fire printing!
launchPrint()
})
in the usecase above the url is a signed url from gcp storage, but we also tried it with another file
none
v1.6.0
v18.x.x
Maybe related to: #18
display style tailwingcss 3
not display style tailwingcss
i try 2 way to add tailwindcss but print not display tailwind style
1.
const d = new Printd()
d.print(element, [], ['https://cdn.tailwindcss.com']
const tailwind = document.createElement('script')
tailwind.setAttribute('src', 'https://cdn.tailwindcss.com')
const d = new Printd({
headElements: [tailwind],
})
d.print(element)
^1.6.0
v18.19.0
Upon clicking print in our application, the print dialog should show and allow us to print the data we send through
...
Upon clicking print, nothing appears and you are unable to click on anything on the webpage. You have to refresh to get it back to normal
...
Comments:
We found that it works consistently with early versions of chromium (98 & lower) but version 99 it is hit and miss.
On one device using Chrome or Brave and chromium version 99.0.4484.51, it doesn't produce the print window and on another device, with the same version of chromium it does show the print window.
When we inspect the page, it is producing the iframe with the correct data (we can open this in a new tab, and all the data is fine)
It works fine on Safari and Firefox.
^1.4.1
MAC and Windows
see above
First, thank you for your very useful utility code.
As you've pointed out if the div contains a select
element, Printd prints the default selection rather than what the user has chosen. Your demo has this issue.
To fix, you can make the following 3 changes.
function updateSelectedAttribute(e) {
let sel, i;
sel = document.getElementById(e.target.id);
// remove 'selected' from prior user selection
for (i = 0; i < sel.length; i += 1) {
sel[i].removeAttribute("selected");
}
// and add 'selected' to current selection
sel[sel.selectedIndex].setAttribute("selected", "selected");
}
change
event listener.document.getElementById("lang").addEventListener("change", updateSelectedAttribute);
I have tested this in current versions of Chrome, Edge, and Firefox. I have not tested it with any mobile device.
Make these changes and Printd will print what the user has selected. Probably best to have a demo that does what developers expect. ;-)
it's possible to printURL with params?
I have this dynamic endpoint ${process.env.API_URL}/invoice/${this.invoice.id}
but I got 404 not found, but if I change the url to a string said http://127.0.0.1:8080/invoice/13, I am able to see invoice.
d.printURL(`${process.env.API_URL}/invoice/${this.invoice.id}`, ({ launchPrint }) => {
console.log("Content loaded!");
// fire printing!
launchPrint();
});
...
...
...
v0.0.0
v0.0.0
v0.0.0
v0.0.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.