473,216 Members | 2,062 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,216 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>
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 20326
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>
  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>
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>
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; }
  12.    .finalpage { position: relative; }
  13. }
  14. </style>
  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?
Apr 29 '09 #5
I have the same problem and I can´t solve the problem yet... Any suggestion?
Sep 24 '09 #6
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

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...
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...
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...
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:...
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
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
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...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.