473,324 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Absolute positioned HTML elements not printing

I am having an issue with HTML elements not printing when positioned absolutely when they extend beyond the first page. I am working on some foreign tax refund forms. The forms are cut into multiple jpg images, so that I can position them on the HTML page, so that they print properly (page1, page2, etc). The information to complete the forms is then positioned using position: absolute and a z-index of +1.

Here is an example code of my problem:
(*note: I am using Mac OS X 10.5.6 and Firefox 3.0.8)

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <div id="1" STYLE="position: absolute; top: 0px; left: 0px;">test1</div>
  4. <div id="2" STYLE="position: absolute; top: 1000px; left: 0px;">test2</div>
  5. </body>
  6. </html>
  7.  
Everything displays fine in the browser, but when I go to print, anything past page one, that is aligned using absolute, will not print. I have tried saving directly to .pdf as well (since I have a mac), changed the print settings to include background images and colors (stab in the dark), and have tried using relative and static, but then the images that are the form do not show properly (they get pushed down the page).

If you need more code, let me know. Also, the reason I am using inline css is because these divs are actually created on the fly, and trying to create a stylesheet to apply to each div(since the data is always going to be changing) will not work.
Apr 6 '09 #1
7 20372
Alright, so it gets more interesting.

I've been trying to get the printing to work, and tried setting up the absolute positioned element within a relative positioned element (since an absolute positioned element is based on its most recent ancestor with positioning applied)

Here was my first test:

Expand|Select|Wrap|Line Numbers
  1.  <html>
  2.  <body>
  3.  <div id="1" STYLE="position: absolute; top: 0px; left: 0px;">test1</div>
  4.  
  5. <div id="3" STYLE="position: relative; margin-top: 1000px;">test3
  6.  <div id="2" STYLE="position: absolute; top: 10px; left: 0px;">test2</div>
  7. </div>
  8. </body>
  9. </html>
  10.  
It would print a blank second page.

So, I tried this:

Expand|Select|Wrap|Line Numbers
  1.  <html>
  2.  <body>
  3.  <div id="1" STYLE="position: absolute; top: 0px; left: 0px;">test1</div>
  4. <div id="4" STYLE="margin-top: 1000px;">test4</div>
  5. <div id="3" STYLE="position: relative; margin-top: 1000px;">test3
  6.  <div id="2" STYLE="position: absolute; top: 10px; left: 0px;">test2</div>
  7. </div>
  8. </body>
  9. </html>
  10.  
This kind of works. It displays in the browser really oddly, but it will print two pages, with test2 and test 3 at the top of the second page....

Still don't know why, and I would like to so that I can get the browser to display it properly AND the page to print properly...maybe I should use two different style sheets, one for screen and one for print? Then I just wouldn't display the <div id="4"> when its on screen, but its there for print?
Apr 6 '09 #2
The solution is actually pretty simple (kicking myself).

Since I am using images, I am placing a div around each image that needs to be displayed to create the form. The div is positioned using position: relative. So, both the image AND the information are placed within the div. Then, the absolute positioned information is adjusted based on the div it is now contained in, and prints as well.

Moral of the story:

Placing an HTML element with absolute position relative to the top of the page will not translate correctly into page breaks (at least with Mac OS X 10.5.6 and Firefox 3.0.8), so, place HTML elements with absolute position within a relatively placed HTML element.

Thanks if you read all of this. Hope it helps someone else.
Apr 6 '09 #3
Interesting thread. I've got a similar problem.

I've got a web page in which I want to display images that are precisely positioned on a number of pages. Here's the code:
Expand|Select|Wrap|Line Numbers
  1. <html lang="en" dir="ltr" >
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4. <style type="text/css">
  5. @page { size: portrait; }
  6. @media all
  7. {
  8.    .page {
  9.       position: relative;
  10.       page-break-after: always; }
  11.  
  12.    .finalpage { position: relative; }
  13. }
  14. </style>
  15.  
  16. </head>
  17. <body>
  18. <div class="page" style="top:0px;">
  19. <div style="position:absolute; left:500px; top:0px;">
  20. <img src="img1.jpg" /></div>
  21. <div style="position:absolute; left:0px; top:0px;">
  22. <img src="img2.jpg" /></div>
  23. <div style="position:absolute; left:50px; top:400px;">
  24. <img src="img3.jpg" /></div>
  25. </div> <!-- closes the 1st page -->
  26. <div class="page" style="top:1414px;">
  27. <div style="position:absolute; left:250px; top:300px;">
  28. <img src="img4.jpg" /></div>
  29. </div>  <!-- closes the 2nd page -->
  30. </body></html>
What should happen is the web page should show img1 near the top-right of page 1, img2 on the top-left of page 1, img3 around in the middle of page 1, and img4 on page 2.

What actually happens is that the images appear where expected on screen, but in Print Preview only the 1st page is rendered: the 2nd page doesn't appear. I'm using Firefox 3.0.10 on Windows XP.

Since each image is precisely placed within its page, each page div needs to have "position:absolute" or "position:relative". I chose relative. One of my CSS rules should force a page break after the 1st page.

I've trawled the web but with no luck. Does anyone have any ideas?
Apr 29 '09 #4
I found this (the very last post is the interesting bit). Anyone else have this problem?
http://www.codingforums.com/archive/...p/t-24135.html
Apr 29 '09 #5
I have the same problem and I can´t solve the problem yet... Any suggestion?
Sep 24 '09 #6
drhowarddrfine
7,435 Expert 4TB
I wish I could be helpful but haven't dealt with this in a long time. The thing to remember is what you see on a web page is not always what you'll get on the printed page, particularly when it crosses page boundaries.

I'm sure I have some articles and/or links about that but I'd have to look them up.
Sep 24 '09 #7
I have "solved" my problem... I had to use a div with position relative and inside it I have put my real page... In this div, at the first page the margin-top=0 and in the others I have put margin-top=900, but this wasn´t enough to solve the problem, so I put a <br> inside the div, and then the problem was solved... The screen is exactly the same as the printed page!
Sep 25 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: mickjames | last post by:
Hi, I'd like to include the whole web page content (as opposed to just the headlines) into RSS/XML to enable people to read them via rss feed readers. Question: how to convert HTML elements...
4
by: Philipp Lenssen | last post by:
Is it possible in IE6+NS7 to center-align a div of fixed width which itself contains elements which use "position: absolute"? Using "margin-left: auto" and "margin-right: auto" works well to center...
4
by: mike eli | last post by:
Hi, I have several absolute positioned elements inside an absolute positioned DIV. I would like one of the nested elements to have a dynamic width. I set it's left and right attributes to 5, so...
22
by: Luke | last post by:
Elements with name attribute: form, input, textarea, a, frame, iframe, button, select, map, meta, applet, object, param, img (if you know more reply...) Methods of addresing html elements:...
2
by: Linus Martinsson | last post by:
How can I change attribute in html elements from my aspx.cs page? For example if I want to change the src-attribute in an iframe. //Linus
5
by: Urs Vogel | last post by:
Hi how do I add HTML elements dynamically to my page? Is there some similar way like with ASPX controls, or do I have to render them out in a custom control? Thanks, Urs
0
by: shu fenghua | last post by:
The problem is when i want to put an element("a" in my code) into an absolute positioned element and i also want this element("a") has a fixed height, then ie6 will render this element("a") as a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.