javascript - Generate custom size pdf using browser print function - Stack Overflow

I have an application that allows users to edit an online business card. once the user has entered thei

I have an application that allows users to edit an online business card. once the user has entered their details, I would like to download the business card as pdf. my issue is that when I download the pdf, it takes a standard A4 size instead of the size of my business card making it difficult to print directly. How can I define the pdf dimension to match the size of my business card? Please check this link

.php?cardid=100&side=1

I tried the following css rule

#printarea {
position: relative;
margin: 0 auto;
width: 400px;
}
   body,html
    {
   width:400px;
   margin: 0 auto;
   }

I have an application that allows users to edit an online business card. once the user has entered their details, I would like to download the business card as pdf. my issue is that when I download the pdf, it takes a standard A4 size instead of the size of my business card making it difficult to print directly. How can I define the pdf dimension to match the size of my business card? Please check this link

http://thecardguys.co.ke/modules/onecard.php?cardid=100&side=1

I tried the following css rule

#printarea {
position: relative;
margin: 0 auto;
width: 400px;
}
   body,html
    {
   width:400px;
   margin: 0 auto;
   }
Share Improve this question edited Aug 24, 2015 at 15:48 Sid 4636 silver badges14 bronze badges asked Aug 24, 2015 at 15:39 jonahjonah 2134 silver badges16 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 5

You'll have to set a couple more CSS bits to ensure that your print is correct.

@page {
  size: 91.44mm 53.34; // set appropriately
  margin: 0;
}
@media print {
  html, body {
    width: 91.44mm; // set appropriately
    height: 53.34mm; // set appropriately
  }
  /* ... the rest of the rules ... */
}

This tells the browser what page size it should go to and what width and height in mm is required of the actual page.

What you also need to remember is that the page size to print will always be the same as the paper that the printer is loaded with.

  • CSS3 Page Documentation

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745502835a4630493.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信