1.Controller:指定了对应的后台Class文件
2.renderAs="pdf":设置成pdf格式
<apex:page renderAs="pdf" showheader="false" sidebar="false" applyHtmltag="false" Controller="QuoteController">
<head>
<style>
body {
font-family: Arial Unicode MS;
}
.table_one{
border:none;
margin:0px auto;
width:100%;
border-collapse:collapse;
font-size:13px;
}
.table_one th{
width:100px;
border:1px dotted black;
border-right:none;
}
.table_one td{
width:100px;
border:1px dotted black;
border-right:none;
}
</style>
</head>
<body>
<div class="div_info" style="100%;">
<div>
<apex:image url="{!$Resource.Meritor_Loge}" width="270" height="50"/>
</div>
<apex:outputText value="文件编号:SHS" style="font-size:13px;"/>
<apex:outputText value="{!quoteDate}" style="font-size:13px;"/>
<hr style="height:1px;border:none;border-top:1px solid black; margin-top:0px" />
<table class="table_one" >
<tr >
<th style="border-left:none;border-top:0.5px solid black;" >发至:</th>
<td style="border-top:0.5px solid black;"><apex:outputField value="{!Quote.Contact.Name}"/></td>
<th style="border-left:1px solid black;border-top:0.5px solid black;" > 来自:</th>
<td style="border-right:none;border-top:0.5px solid black;"><apex:outputText value="{!Quote.CreatedBy.Username}"/></td>
</tr>
<tr >
<th style="border-left:none;border-top:none;border-bottom:none;">公司:</th>
<td style="border-top:none;border-bottom:none;">{!Quote.Account.Name}</td>
<th style="border-left:1px solid black;border-top:none;border-bottom:none;">公司:</th>
<td style="border-right:none;border-top:none;border-bottom:none;"><apex:outputText value="{!Quote.CreatedBy.CompanyName}"/></td>
</tr>
<tr >
<th style="border-left:none;">传真:</th>
<td ><apex:outputField value="{!Quote.Fax}"/></td>
<th style="border-left:1px solid black;">传真:</th>
<td style="border-right:none;"><apex:outputText value="{!Quote.CreatedBy.Fax}"/></td>
</tr>
<tr >
<th style="border-left:none;border-top:none;border-bottom:none;">电话:</th>
<td style="border-top:none;border-bottom:none;" ><apex:outputField value="{!Quote.Phone}"/></td>
<th style="border-left:1px solid black;border-top:none;border-bottom:none;">电话:</th>
<td style="border-right:none;border-top:none;border-bottom:none;"><apex:outputText value="{!Quote.CreatedBy.Phone}"/></td>
</tr>
<tr >
<th style="border-left:none;">页数:</th>
<td></td>
<th style="border-left:1px solid black;">日期:</th>
<td style="border-right:none;">
<apex:outputText value="{0,date,yyyy-MM-dd}"> <apex:param value="{!Quote.QuoteDate__c}" /> </apex:outputText>
</td>
</tr>
<tr >
<th style="border-left:none;border-bottom:1px double black;border-top:none;">主题:</th>
<td style="border-bottom:1px double black;border-top:none;"><apex:outputField value="{!Quote.Name}"/></td>
<th style="border-left:1px solid black;border-bottom:1px double black;border-top:none;">邮件:</th>
<td style="border-right:none; border-bottom:1px solid black;border-top:none;"><apex:outputText value="{!Quote.CreatedBy.Email}"/></td>
</tr>
</table>
<hr style="height:1px;border:none;border-top:1px solid black;" />
<br/><br/>
<apex:outputText value="一:标的及价格" style="font-size:14px;"/>
<table class="table_two" style=" margin:0px auto;100%;border:1px solid black; font-size:13px; border-collapse:collapse;">
<thead>
<tr>
<th style="border-bottom:1px solid; black;border-top:1px solid black;border-left:1px solid black;text-align:center;">序<br/>号:</th>
<th style="border-bottom:1px solid; black;border-left:1px solid black;black;border-top:1px solid black;text-align:center;">客户零件号</th>
<th style="border-bottom:1px solid;black;border-left:1px solid black;black;border-top:1px solid black;text-align:center;">美驰零件号</th>
<th style="border-bottom:1px solid; black;border-left:1px solid black;black;border-top:1px solid black;text-align:center;">零件名称</th>
<th style="border-bottom:1px solid; black;border-left:1px solid black;black;border-top:1px solid black;text-align:center;">单位</th>
<th style="border-bottom:1px solid; black;border-left:1px solid black;black;border-top:1px solid black;border-right:1px solid black;text-align:center;">含税价</th>
</tr>
</thead>
<tbody>
<apex:repeat value="{!listItem}" var="item">
<tr >
<td style="border-left:1px solid black;border-bottom:1px solid black;text-align:center" >{!item.serial}</td>
<td style="border-left:1px solid black;border-bottom:1px solid black;text-align:center">{!item.plist.AccountProductCode__c}</td>
<td style="border-left:1px solid black;border-bottom:1px solid black;text-align:center">{!item.plist.Product2.Name}</td>
<td style="border-left:1px solid black;border-bottom:1px solid black;text-align:center">{!item.plist.Product2.ProductCode}</td>
<td style="border-left:1px solid black;border-bottom:1px solid black;text-align:center">{!item.plist.Unit__c}</td>
<td style="border-left:1px solid black;border-bottom:1px solid black;border-right:1px solid black;text-align:center">{!Quote.TotalPrice}</td>
</tr>
</apex:repeat>
</tbody>
</table>
<br/>
<apex:outputField value="{!Quote.Terms__c}" rendered="{!if(Quote.Recordtype.Name == '公路',true,false)}"/>
<apex:outputField value="{!Quote.Terms2__c}" rendered="{!if(Quote.Recordtype.Name == '非公路',true,false)}"/>
</div>
<div style="font-size:15px;position:absolute;right:50px;">
<apex:outputText value="徐州美驰车轿有限公司" /><br/>
<apex:outputField value="{!Quote.QuoteDate__c}" />
</div>
</body>
</apex:page>
public class QuoteController{
public Quote quote {get; set;}
public String quoteDate {get; set;}
public List<ProductItem> listItem{get; set;}
public QuoteController() {
//获取quoteId
String qtId = ApexPages.currentPage().getParameters().get('id');
//根据取到的quoteId去查询数据
quote=[select Id, Name,BillingName, Fax,Phone,QuoteDate__c,TotalPrice,Terms__c,Subtotal,Contact.Name,Terms2__c,
Account.Owner.Name,Account.Id,Account.Name,CreatedBy.Username,CreatedBy.CompanyName,CreatedBy.Phone,CreatedBy.Fax,
CreatedBy.Email,RecordType__c,RecordType.Name
FROM Quote
WHERE Id=:qtId];
System.debug('quote=>'+quote.RecordType.Name);
//获取订单产品
List<QuoteLineItem> quoteItems = [SELECT Id,Product2Id, Product2.Name, Product2.ProductCode, Product2.Family,
Product2.QuantityUnitOfMeasure,UnitPrice,Unit__c,AccountProductCode__c
FROM QuoteLineItem
WHERE QuoteId = :qtId];
quoteDate = quote.QuoteDate__c.format().replace('-','');
//循环赋值给quoteItems序列号
listItem = new List<ProductItem>();
Integer i = 1;
for(QuoteLineItem li: quoteItems) {
system.debug('quote.QuoteDate__c: ' + quote.QuoteDate__c);
listItem.add(new ProductItem(i, quote.QuoteDate__c.format().replace('-',''), li));
i++;
}
}
Class ProductItem {
public Integer serial {get; set;}
public QuoteLineItem plist {get; set;}
public String quoteDate {get; set;}
public ProductItem(Integer serial, String dlDate, QuoteLineItem plist) {
this.serial = serial;
this.quoteDate = dlDate;
this.plist = plist;
}
}
}