Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Printing Problems
Options
-
18-07-2007 4:40pmProblem 1
I'm having a problem with this, basically I'm printing a row of 3 months and as many months as I choose from a form that is submitted. What I'm having the problem with though is that the calendar that I've printed is overlapping and I'm trying to make it break after printing 3 months.<table cellspacing="0" cellpadding="0" style="position:absolute; top: 0px; left: 0px;"> <% Dim myRows Dim myTotalRows Dim myColumns Dim myMonth Dim myYear Dim myMonthsToDisplay Dim myMonthsCheck Dim myMonthsDisplayed Dim MyCalendar '***CHECKS IF FORM HAS BEEN SUBMITTED WITH DATES AND MONTHS NEEDED TO PRINT CALENDAR if Request.Form("startMonth") = "" then '**IF NOT SET THEN CHOOSE TO DISPLAY FULL YEAR myMonthsDisplayed = 1 myMonth = 1 myYear = Year(Date()) myMonthsToDisplay = 12 else myMonthsDisplayed = 1 myMonth = CInt(Request.Form("startMonth")) myYear = CInt(Request.Form("yearOfCal")) myMonthsToDisplay = CInt(Request.Form("monthsToDisplay")) end if '**CALCULATING THE TOTAL NUMBER OF ROWS REQUIRED FOR THE MONTHS TO BE DISPLAYED myMonthsCheck = myMonthsToDisplay myTotalRows = 0 do while myMonthsCheck > 0 myTotalRows = myTotalRows + 1 myMonthsCheck = myMonthsCheck - 3 loop '***DECIDES ON THE TOTAL NUMBER OF ROWS TO DISPLAY, DEPENDING ON THE AMOUNT OF MONTHS COULD BE LARGER for myRows = 1 to myTotalRows %> <tr style="page-break-after: always;"> <% '**SETS HOW MANY MONTHS ARE DISPLAYED IN EACH ROW for myColumns = 1 to 3 %> <td valign="top"> <% '**CHECKS IF ALL THE MONTHS THAT NEED TO BE DISPLAYED HAVE ALREADY BEEN DISPLAYED if myMonthsDisplayed > myMonthsToDisplay then else '**SETS THE NEW CALENDAR OBJECT TO THE VARIABLE Set MyCalendar = New Calendar '**SETS THE MONTH AND YEAR TO BE DISPLAYED IN THE CALENDAR MyCalendar.setDate(myMonth & "/7/" & myYear) '**INCREMENETS THE MYMONTH VARIABLE BY ONE FOR THE NEXT MONTH TO BE DISPLAYED myMonth = myMonth + 1 '**CHECKS THAT THE MONTHS HASN'T RAN OVER THE YEAR END, IF IT HAS INCREMENTS YEAR if myMonth > 12 then myMonth = 1 myYear = myYear + 1 end if 'SETS DIFFERENT VARIABLES OF THE CALENDAR OBJECT MyCalendar.Width = 340 MyCalendar.SetDrawStyle true '**ADDS ALL THE LEAVES TO THE HOLIDAY OBJECT mAddCalendarHolidays objEEtoView '**REMOVES THE DATE SELECT FEATURE ON THE DISPLAY OF THE CALENDARS MyCalendar.ShowDateSelect = false '**DISPLAYS THE CALENDAR AND THEN INCREMEMTS THE NUMBER OF MONTHS ALREADY DISPLAYED BY 1 MyCalendar.Draw() myMonthsDisplayed = myMonthsDisplayed + 1 end if %> </td> <% next %> </tr> <% next %> <tr> <td colspan="6" align="center"> <input type="button" value="Print" onclick="window.print()"> </td> </tr> </table>
I've tried adding<p style="page-break-before:always;">
in at the correct point but it doesn't make any difference. It still overlaps.
Problem 2
After a certain amount of lines of code for some reason my calendars change in appearance. The size of all the cells are fixed and since this is a for loop all the calendars should appear the same. When printing a full year for some reason when I send the page to the printer the last quarter messes up and the sizes of all the cells mess up. I'm thinking this could be something to do with a buffer problem.
Can anyone help me with either of these problems?0
Comments
-
Yes and no. I ran into a similar problem a few months back,(it was for printing lablels of a fixed size instead of months but 3 labels across 7 rows to a page so a similar idea to what you are encountering) encountered the same problems you are having and in the end I had to admit it was impossible to get what I wanted from HTML.
So I moved to Microsoft word or rather ASP and word. I scripted an ASP page to output as a word document (which can be exactly sized so that it matched up to the label size) and of course no need to worry anymore about page breaks or style changing after a page is printed. If you would like to see this option I can post example code or give you a link to a good tutorial.
I'm sure a similar effect can be achieved with other scripting languages (PERL or PHP) so if you are more familiar with one of those you can trawl the internet for a tutorial.
If however you can only write HTML then I don't know if I can help. The first problem is that even if you can get the page to line up correctly how do you prevent the users browser from messing your alignment (most browsers print default adds a header and footer and generally has some heavy margins either side)
Perhaps if you send me on/post up the HTML I can see if anything can be done.
Sorry I can't be more help.
-RD
PS Sorry just looked at your question again and saw the posted code. I'll see what can be done with it now.0 -
Thanks Ron, I'd appreciate the sample code and link to a tutorial. I am actually writing everything in ASP but for some reason couldn't find any useful information about printing with ASP so I decided to change to JS and HTML.
Any help with printing through ASP would be greatly appreciated.
I do have another problem though, printing a few tables inside cells is fine, but once I get to the third row/fourth row everything seems to give up. Changing it's display which is strange, because in the web browser it displayers perfect.0 -
<%@ Language = VBScript%> <% Dim strConn, strQ, objConn, objRS, cusRS Set objConn = Server.CreateObject("ADODB.Connection") strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/DATABASE_PATH/DATABASE.mdb") & ";User Id=;Password=;" %> <% Dim strSource If Request.ServerVariables("CONTENT_LENGTH") <> 0 Then Response.ContentType = "application/vnd.ms-word" Response.AddHeader "content-disposition", "attachment; filename = docket_labels.doc" strSource = Request.Form("source") %> <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"> <html> <head> <title>label test</title> <style> body { background-color: white; color: black; margin: 0px; font-size: 6pt; font-family: arial; } td { font-size: 8pt; } @page Section1 { size: 595.3pt 841.9pt; margin: 8.5pt 8.5pt 8.5pt 8.5pt; mso-header-margin: 0cm; mso-footer-margin: 0cm; mso-paper-source:0; } div.Section1 { page:Section1; } </style> </head> <body lang="EN-US" style="tab-interval:0.5in;"> <div class="Section1"> <% objConn.Open strConn strQ = "SELECT * FROM [todays manifest] WHERE [source] = '" & strSource & "' ORDER BY [source], [depot], [sender], [deliver_to];" Set objRS = objConn.Execute(strQ) Dim num_jobs, i, num_pages, j, k If Not objRS.EOF Then While Not objRS.EOF num_jobs = num_jobs + 1 objRS.MoveNext Wend End If num_pages = Round((num_jobs / 21)) If num_pages * 21 < num_jobs Then num_pages = num_pages + 1 End If objRS.MoveFirst Dim dkt, sdr, del, del_add, g_desc, qty, dpt, p, t, src Set dkt = objRS("consignment_number") Set sdr = objRS("sender") Set del = objRS("deliver_to") Set del_add = objRS("deliver_to_address") Set dpt = objRS("depot") Set g_desc = objRS("goods_description") Set qty = objRS("quantity") Set src = objRS("source") If num_jobs > 0 Then For j = 1 to num_pages %> <table style="table-layout:fixed;width:196mm;" valign="middle" align="center" cellspacing="0" cellpadding="0" border="0" bordercolor="black" cellspacing="0" cellpadding="0"> <tr> <td colspan="3" bordercolor="white" style="height:12mm;"> </td> </tr> <% For i = 1 to 7 %> <tr> <% For k = 1 to 3 If Not objRS.EOF Then strQ = "SELECT [quantity], [goods_description] FROM [todays manifest] WHERE [consignment_number] = '" & objRS("consignment_number") & "';" Set cusRS = objConn.Execute(strQ) p = 0 While Not cusRS.EOF p = p + 1 cusRS.MoveNext Wend cusRS.MoveFirst %> <td style="width:<% If j <> 2 Then %>64mm;<% Else %>68mm;<% End If %>height:38mm;" background="<% Response.write(Server.MapPath("/node/art/" & src & ".bmp")) %>" valign="top"> <table align="left" width="100%" valign="middle" cellspacing="0" cellpadding="0" frame="box"> <tr> <td style="width:20mm;"> </td> <td> </td> </tr> <tr> <td align="center"colspan="2" style="font-family:code 39;font-size:16pt;padding-right:2mm;"> *<%= dkt %>* </td> </tr> <tr> <td valign="top" colspan="2" align="center"> <%= dkt %> </td> </tr> <tr> <td colspan="2" valign="top" style="padding-left:8mm;font-variant:small-caps;font-size:7pt;" align="left"> <%= sdr %> <i>(<%= dpt %>)</i> </td> </tr> <tr> <td align="right" valign="top" style="width:20mm;"> Deliver To: </td> <td align="left" valign="top" style="font-size:7pt;"> <b><%= Mid(del, 1, 30) %><br /> <%= Mid(Replace(del_add, vbCrLf, ""), 1, 35) %></b> </td> </tr> <tr> <td align="right" style="width:15mm;" valign="top"> Freight: </td> <td align="left" valign="top"> <% While Not cusRS.EOF Response.write "(" & cusRS("quantity") & ") " Response.write cusRS("goods_description") & "<br />" cusRS.MoveNext Wend For t = 1 to (p - 1) objRS.MoveNext Next %> </td> </tr> </table> </td> <% Next %> </tr> <% Next %> </table> <% Next End If %> </div> </body> <% objConn.Close Set objRS = Nothing Set objConn = Nothing %> </html>
The above code won't do anything for you as it is based around a database that you do not have (and will in fact give you a load of error messages if you do try to run it) however it does show you the theory and basic coding behind what you are trying to achieve. Adapt it to suit your own code. The issue with the style changing after a few rows won't happen if you use the script as it outputs a word document (where the style will not change) instead of a HTML document where the style will change after the first line break.
http://www.codeave.com/asp/code.asp?u_log=129 is a pretty good example of how to output a word document from ASP.
Hope that helps
-RD0
Advertisement