小编Adr*_*ian的帖子

使用 wicked_pdf 从生成的 PDF 生成 ZIP

在我的发票系统中,我想要一个备份功能,将所有发票一次性下载到一个 zip 文件中。该系统在 heroku 上运行 - 因此只能临时保存 pdf。

我已经安装了 ruby​​zip 和 wicked_pdf gem。

我在控制器中的当前代码:

  def zip_all_bills
    @bill = Bill.all
    if @bill.count > 0
      t = Tempfile.new("bill_tmp_#{Time.now}")
      Zip::ZipOutputStream.open(t.path) do |z|
        @bill.each do |bill|
          @bills = bill
          @customer = @bills.customer
          @customer_name = @customer.name_company_id
          t = WickedPdf.new.pdf_from_string(
              render :template => '/bills/printing.html.erb',
                     :disposition => "attachment",
                     :margin => { :bottom => 23 },
                     :footer => { :html => { :template => 'pdf/footer.pdf.erb' } }
          )

          z.puts("invoice_#{bill.id}")
          z.print IO.read(t.path)
        end
      end

      send_file t.path, :type => "application/zip", …
Run Code Online (Sandbox Code Playgroud)

heroku rubyzip ruby-on-rails-3 wicked-pdf

6
推荐指数
1
解决办法
1523
查看次数

CLGeocoder反向地理编码失败,错误域= NSURLErrorDomain Code = -1000 -

使用CLLocation对象(内容例如纬度= 48.196169,经度= 11.620237),我尝试获取当前的城市和国家:

if(!geocoder) {
    geocoder = [[CLGeocoder alloc] init];
}

if (geocoder.geocoding) [geocoder cancelGeocode];
    [geocoder reverseGeocodeLocation:lo completionHandler:^(NSArray *placemarks, NSError *error) {
    if(devMode) {
        NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
    }

    if (error == nil && [placemarks count] > 0) {
        // MY CODE - here placemarks is always (null)
    } else {
        if(devMode)
            NSLog(@"%@", error.debugDescription);
    }
}];
Run Code Online (Sandbox Code Playgroud)

大多数情况下,这很有效.但在极少数情况下,我只是得到错误:

PBRequester失败,错误错误域= NSURLErrorDomain代码= -1000"UngültigeURL"UserInfo = 0x16f5ff30 {NSUnderlyingError = 0x16f57810"UngültigeURL",NSLocalizedDescription =UngültigeURL}

找到地标:(null),错误:错误Domain = kCLErrorDomain Code = 2"操作无法完成.(kCLErrorDomain error 2.)"

我完全不知道为什么会这样.

cllocation clgeocoder ios7 xcode5

6
推荐指数
1
解决办法
2338
查看次数