我正在使用pdfkit从ruby中的html生成pdf。我能够生成pdf,但pdf上的渲染文本有一些不均匀间隔的字符,即使html渲染是完美的。
def self.generate_invoice
content = File.read( "#{Rails.root}/engines/restaurant_service/app/views/restaurant_service/settlement_mailer/settlement_invoice.html.erb")
template = ERB.new(content)
set_margin = 0.1.to_s
kit = PDFKit.new(template.result(binding), :page_size => 'Letter',:margin_top => set_margin+'in', :margin_right => set_margin+'in', :margin_bottom => set_margin+'in', :margin_left => set_margin+'in')
kit.to_file(file_path)
end
答案 0 :(得分:0)
您可以在config / initializers / pdfkit.rb
中添加以下行NSArray *arr1 = [pJson1 objectForKey:@"Response"];
for (int i=0; i<arr1.count; i++)
{
int yval;
int x ;
btnNew = [[UIButton alloc]initWithFrame:CGRectMake(0,yval, 50, 30)];
btnNew.backgroundColor = [UIColor blackColor];
NSString *str = [NSString stringWithFormat:@"%@",[[arr1 objectAtIndex:i]objectForKey:@"name"]];
[btnNew setTitle:str forState:UIControlStateNormal];
btnNew.center = CGPointMake(160.0, 240.0);
CGSize stringsize = [str sizeWithFont:[UIFont systemFontOfSize:14]];
//or whatever font you're using
[btnNew setFrame:CGRectMake(5,yval+10,100, 20)];
btnNew.tag = i;
[self.categoryView addSubview:btnNew];
x += 2;
yval +=10;
}
然后重新启动服务器。