如何格式化A4尺寸的页面?

时间:2015-07-15 05:02:37

标签: javascript php jquery html css

我是PHP新手。我有一个包含多个内联文本编辑器的文件代码。在所有编辑器中从db获取的数据。我想格式化我的页面。我的页面输出如下。

这里我在打印时遇到问题。当我按Ctrl+P时,我的页面格式将会改变。文字从页面中消失。

我有什么解决方案吗?

我的代码是

<?php
$con=mysqli_connect("localhost","root","","pacra1");

         $id2 = $_GET['id'];
        $sql = "SELECT * FROM test1 where id='$id2'";

            $result=mysqli_query($con,$sql);

            $row= (mysqli_fetch_array($result,MYSQLI_ASSOC));

$editor1 =trim($row['editor1']);
$editor2 =trim($row['editor2']);
$editor3 =trim($row['editor3']);
$editor4 =trim($row['editor4']);
$editor5 =trim($row['editor5']);
$editor6 =trim($row['editor6']);
$editor7 =trim($row['editor7']);
$editor8 =trim($row['editor8']);
$editor9 =trim($row['editor9']);
$editor10 =trim($row['editor10']);
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="newstyles.css">
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script> 
<script type="text/javascript" src="../../scripts/demos.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxdropdownbutton.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxcolorpicker.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxwindow.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxeditor.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxtooltip.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script> 
</head>

<body>
  <script type="text/javascript">
        $(document).ready(function () {
            $('#editor1').jqxEditor({tools: 'bold italic underline | left center right'
            });

            $('#editor2').jqxEditor({tools: 'bold italic underline | left center right'
            });

            $('#editor3').jqxEditor({tools: 'bold italic underline | left center right'
            });

            $('#editor4').jqxEditor({ 
            });

             $('#editor5').jqxEditor({tools: 'bold italic underline | left center right'
            });
            $('#editor6').jqxEditor({ 
            });
            $('#editor7').jqxEditor({tools: 'bold italic underline | left center right'
            });
            $('#editor8').jqxEditor({tools: 'bold italic underline | left center right'
            });
            $('#editor9').jqxEditor({tools: 'bold italic underline | left center right'
            });
            $('#editor10').jqxEditor({tools: 'bold italic underline | left center right'
            });
            $('#editor11').jqxEditor({
            });

        });
    </script>

    <div style=" margin-left:auto; margin-right:auto; width: 60%">
    <div style="margin-top: 10px; width: 800px; font-family: 'Times New Roman', Times, serif;">

    <div style=" margin:auto; width:60px; height:auto; align: middle">
    <img src="image/pacra_logo.png" alt="logo">
    </div>
    <div style="margin:auto; width:auto; text-align:center; font-family:'Times New Roman', Times, serif; font-variant: small-caps; font-size:20px; font-weight:bold">
    The Pakistan Credit Rating Agency Limited 
    <hr>
    </div>

    <div style="width: 30%;" contenteditable="true" id="editor1"><?php echo !empty(nl2br($editor1))?(nl2br($editor1)):'';?></div>

           <div style=" margin-top:30px; width:35%; float:left; font-family:'Times New Roman', Times, serif; text-align:left; font-size:14px; line-height:1" contenteditable="true" id="editor2"><?php echo !empty(nl2br($editor2))?(nl2br($editor2)):'';?></div>

            <div style=" margin-top:30px; margin-left:220px; width:35%; float:left; font-family:'Times New Roman', Times, serif; text-align:right; line-height:1; font-size:14px" contenteditable="true" id="editor3"><?php echo !empty(nl2br($editor3))?(nl2br($editor3)):'';?></div>

             <div style="clear: both;"></div>
          <div style="margin-top:40px; margin-right:auto; width:auto; font-family:'Times New Roman', Times, serif; text-align:center; font-variant:small-caps; font-size:18px; font-weight:bold" contenteditable="true" id="editor4"><p> <?php echo !empty(nl2br($editor4))?(nl2br($editor4)):'';?> </p></div>

         <div style=" margin-top:20px; width:20%; float:left; font-family:'Times New Roman', Times, serif; text-align:left; font-size:16px" contenteditable="true" id="editor5"> 
         <?php echo !empty(nl2br($editor5))?(nl2br($editor5)):'';?>
         </div> 
    </div>
    <div style="clear: both;"></div>
    <div style="margin-top: 10px; width: 800px; text-align:justify; font-family:'Times New Roman', Times, serif; font-size:14px" contenteditable="true" id="editor6">

            <?php echo !empty(trim(nl2br($editor6)))? (trim(nl2br($editor6))):'';?>
        </div>

    <div style="margin-top:30px; width:auto; float:left; text-align:left; font-family:'Times New Roman', Times, serif; font-size:16px" contenteditable="true" id="editor7">
    <?php echo !empty(nl2br($editor7))?(nl2br($editor7)):'';?>
    </div>

    <div style="clear: both;"></div>

    <div style="margin-top:100px; width:auto; float:left; text-align:left; font-family:'Times New Roman', Times, serif; font-size:16px; font-variant:small-caps" contenteditable="true" id="editor8">
    <strong><p><?php echo !empty(nl2br($editor8))?(nl2br($editor8)):'';?></p></strong>
    </div>

<div style="clear: both;"></div>

    <div style="margin:auto; width:auto; float:left; text-align:left; font-family:'Times New Roman', Times, serif; font-size:16px;" contenteditable="true" id="editor9">
  <p><?php echo !empty(nl2br($editor9))?(nl2br($editor9)):'';?></p>
    </div>    

    <div style="clear: both;"></div>

    <div style="margin-top:40px; width:auto; float:left; text-align:left; font-family:'Times New Roman', Times, serif; font-size:16px;" contenteditable="true" id="editor10">
  <p><?php echo !empty(nl2br($editor10))?(nl2br($editor10)):'';?></p>
    </div>

<div style="clear: both;"></div>

    <div style="margin-top:70px; width:800px; float:left; text-align:center; font-family:'Times New Roman', Times, serif; font-size:18px;">
    <hr>
 <strong></strong>  
 </br>
    </div>
    </div>
</div>

</body>
</html>

2 个答案:

答案 0 :(得分:1)

您可以在单独的CSS中指定打印样式。

<link rel="stylesheet" href="css/print.css"/ media="print">

答案 1 :(得分:0)

是的,我这样做。 查看我的更新代码

func fetchAllInformation() -> BFTask {

    // First, create all tasks (if you need more, than just create more, it is as easy as that
    var task1 = BFTaskCompletionSource()
    var task2 = BFTaskCompletionSource()
    var tasks = [task1, task2]

    // What you do, is you set result / error to tasks and the propagate in the chain upwards (it is either result, or error)
    // You run task 1 in background
    API.instance.fetchFirstDetailsInBackgroundWithBlock {
        (object: AnyObject!, error: NSError!) -> Void in

        // On error or on success, you assign result to task (whatever you want)
        if error == nil {
            task1.setResult(object)
        } else {
            task1.setError(error)
        }
    }

    // You run task 2 in background
    API.instance.fetchSecondDetailsInBackgroundWithBlock {
        (object: AnyObject!, error: NSError!) -> Void in

        // On error or on success, you assign result to task (whatever you want)
        if error == nil {
            task2.setResult(object)
        } else {
            task2.setError(error)
        }
    }

    // Now you return new task, which will continue ONLY if all the tasks ended
    return BFTask(forCompletionOfAllTasks: tasks)
}