pdf not well formatted

67 views
Skip to first unread message

Dott. Scolavino Alessandro

unread,
Dec 2, 2009, 9:19:54 AM12/2/09
to prawn...@googlegroups.com
I got this error wheni try to open a generated pdf:

**** File has unbalanced q/Q operators (too many Q's) ****

**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Prawn <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.

what it means?
i send the code that generate my pdf as attachment...


--
- --
Ai sensi del DL 196/2003 si precisa che le informazioni contenute in questo
messaggio sono riservate ed a uso esclusivo del destinatario. Qualora il
messaggio in parola Le fosse pervenuto per errore, la Preghiamo di
eliminarlo senza copiarlo e di non inoltrarlo a terzi, dandocene gentilmente
comunicazione. Grazie.

Cordiali saluti

- ---- Dott. Alessandro Scolavino ----
- ---- http://www.webair.it ----
- ---- http://www.clerk.it ----
scolas.vcf
fattura.pdf.prawn

Henrik Nyh

unread,
Dec 2, 2009, 10:10:45 AM12/2/09
to prawn...@googlegroups.com
Did you generate this PDF on Windows? People have mentioned Windows
issues on this list lately.

That is a lot of code. Please try removing parts of the code,
generating the file and opening it, until you get a minimal file that
has the error.
> --
>
> You received this message because you are subscribed to the Google Groups "Prawn" group.
> To post to this group, send email to prawn...@googlegroups.com.
> To unsubscribe from this group, send email to prawn-ruby+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/prawn-ruby?hl=en.
>
>
>
> pdf.instance_variable_set("@left_margin", 20)
> pdf.instance_variable_set("@right_margin", 20)
> pdf.instance_variable_set("@top_margin", 12)
> pdf.instance_variable_set("@bottom_margin", 12)
> pdf.instance_variable_set("@page_size", 'A4')
> pdf.instance_variable_set("@compress", true)
>
> border_color = "97b4d7"
> back_color = "cde0f7"
>
> web_path = "/gallery/#{Setting.actual_setting.sitename}/Setting/#{Setting.actual_setting.id}/"
> pdf.fill_color "0b0b0b"
> pdf.stroke_color "0b0b0b"
> pdf.padded_box(20) do
>  pdf.stroke_bounds
>
>  if File.file?("#{RAILS_ROOT}/public#{web_path}images/barra_header.jpg")
>    pdf.image  "#{RAILS_ROOT}/public#{web_path}images/barra_header.jpg", :fit => [pdf.bounds.width, 107]
>  end
>
>  if File.file?("#{RAILS_ROOT}/public#{web_path}images/barra_footer.jpg")
>    move_by = pdf.cursor()
>    pdf.move_down(move_by - 31.5)
>    pdf.image  "#{RAILS_ROOT}/public#{web_path}images/barra_footer.jpg", :fit => [pdf.bounds.width() -1, 107], :position => :center
>    pdf.move_up(move_by)
>  end
>
>  pdf.rectangle [0,pdf.cursor], (pdf.bounds.width)-1, 50
>  pdf.fill_and_stroke
>  pdf.move_down(10)
>
>  pdf.fill_color "ffffff"
>  company = Setting.actual_setting.company
>  pdf.text company.full_name, :align => :center, :size => 8
>  if !company.address.nil?
>    pdf.text "#{company.address.street}, #{company.address.number} - #{company.address.zip} - #{company.address.town}#{(company.address.province != "") ? "(#{company.address.province})" : ""} #{company.address.country}", :align => :center, :size => 8
>  end
>  pdf.text "#{_("C.F.")} #{company.fiscal_code} - #{_("P.Iva")} #{company.vat_code}", :align => :center, :size => 8
>  pdf.text "#{_("Tel.")} #{(company.phone_numbers.nil? or company.phone_numbers.empty?) ? "" : company.phone_numbers[0].number} - em@il : #{company.email}", :align => :center, :size => 8
>
>  pdf.move_down(20)
>
>  pdf.fill_color "0b0b0b"
>  if @detail.proforma
>    pdf.text _("FATTURA PROFORMA"), :at => [10, pdf.cursor], :size => 9
>  else
>    pdf.text %(#{(@detail.receipt ? _("RICEVUTA N°") : _("FATTURA N°"))}), :at => [10, pdf.cursor], :size => 9
>    pdf.fill_color back_color
>    pdf.stroke_color border_color
>    pdf.rectangle [80, (pdf.cursor) + (pdf.font.height) -3 ], 30, (pdf.font.height) +2
>    pdf.fill_and_stroke
>    pdf.fill_color "0b0b0b"
>    pdf.text @detail.code, :at => [85, pdf.cursor], :size => 9
>  end
>
>  pdf.move_down(30)
>  pdf.text _("Date"), :at => [10, pdf.cursor], :size => 9
>  pdf.fill_color back_color
>  pdf.stroke_color border_color
>  pdf.rectangle [80, (pdf.cursor) + (pdf.font.height) -3 ], 80, (pdf.font.height) +2
>  pdf.fill_and_stroke
>  pdf.fill_color "0b0b0b"
>  pdf.text @detail.date.strftime("%d/%m/%Y"), :at => [85, pdf.cursor], :size => 9
>
>  pdf.move_up(30)
>  pdf.text _("Spettabile"), :at => [240, pdf.cursor], :size => 9
>  pdf.fill_color back_color
>  pdf.stroke_color border_color
>  pdf.rectangle [300, (pdf.cursor) + (pdf.font.height) -3 ], 200, 50
>  pdf.fill_and_stroke
>  pdf.fill_color "0b0b0b"
>
>  pdf.move_up(5)
>
>  pdf.span(180, :position => 325) do
>    address = (!@detail.company.billing_address.nil? ? @detail.company.billing_address : @detail.company.address )
>    pdf.text %(#{@detail.company.full_name}), :size => 8
>    pdf.text %(#{address.street}, #{address.number} #{address.internal}), :size => 8
>    pdf.text %(#{address.zip} - #{address.town}#{(address.province != "") ? "(#{address.province})" : ""} #{address.country}), :size => 8
>    pdf.text %(#{_("C.F.")} : #{@detail.company.fiscal_code} - #{_("P.Iva")} : #{@detail.company.vat_code}), :size => 8
>  end
>
>  pdf.move_down(60)
>  righe = Array.new
>  total = 0
>  @detail.free_lines.each do |free_line|
>    total = total + free_line.total
>    righe << [free_line.quantity, free_line.description, %(€ #{format("%.2f",free_line.price)}), %(€ #{format("%.2f",free_line.total)})]
>  end
>
>  pdf.stroke_color "0b0b0b"
>  pdf.fill_color "0b0b0b"
>  pdf.table righe,
>            :border_style => :grid,
>            :row_colors => [ back_color, "FFFFFF"],
>            :headers => [_("Q.Tà"), _("Descrizione"), _("IMP. UNIT"), _("IMP. TOT")],
>            :header_color => '97b4d7',
>            :font_size => 6,
>            :align => { 0 => :center, 1 => :left, 2 => :right, 3 => :right },
>            :column_widths => { 0 => 40, 1 => 355, 2 => 50, 3 => 50 },
>            :position => pdf.bounds.width - 505
>
>
>  righe = Array.new
>  righe << [_("Totale"), %(€ #{format("%.2f",total)})]
>  righe << [%(#{_("Iva")} #{@detail.vatrate.to_s}%), %(€ #{format("%.2f",(total / 100) * @detail.vatrate)}) ]
>  righe << [%(#{_("Totale")} + #{_("Iva")}), %(€ #{format("%.2f",((total / 100) * @detail.vatrate) + total)}) ]
>  if @detail.ritenuta
>    righe << [%(#{_("Ritenuta di acconto 20% su")} € #{total}), %(€ #{format("%.2f",((total / 100) * @detail.vatrate))}) ]
>    righe << [_("Netto da pagare"), %(€ #{format("%.2f",total)})]
>  end
>
>
>  pdf.table righe,
>            :border_style => :grid,
>            :font_size => 6,
>            :align => { 0 => :left, 1 => :right },
>            :column_widths => { 0 => 120, 1 =>  50 },
>            :position => pdf.bounds.width - 180
>  if @detail.proforma
>    pdf.move_down(20)
>    pdf.text _("Nota spese non valida ai fini IVA. La fattura verrà emessa al momento del pagamento."),:at =>  [10, pdf.cursor], :size => 5
>  end
>  pdf.move_down(pdf.cursor() - 70)
>
>  pdf.text _("Modalità di pagamento"),:at =>  [10, pdf.cursor], :size => 9
>  pdf.fill_color back_color
>  pdf.stroke_color border_color
>  pdf.rectangle [130, (pdf.cursor) + (pdf.font.height) -3 ], pdf.bounds.width - 140, 30
>  pdf.fill_and_stroke
>  pdf.fill_color "0b0b0b"
>  pdf.move_up(6)
>  pdf.span( pdf.bounds.width - 165, :position => 160) do
>    pdf.text @detail.payment_type.description, :size => 9
>    if !@detail.payment_type.bank_account.nil?
>      pdf.text %(#{@detail.payment_type.bank_account.bank_name}#{
>                  (@detail.payment_type.bank_account.address.nil? ? "" :
>                                                                    %(#{@detail.payment_type.bank_account.address.street}, #{@detail.payment_type.bank_account.address.number} #{@detail.payment_type.bank_account.address.internal} - #{@detail.payment_type.bank_account.address.zip} - #{@detail.payment_type.bank_account.address.town}#{(@detail.payment_type.bank_account.address.province != "") ? "(#{@detail.payment_type.bank_account.address.province})" : ""} #{@detail.payment_type.bank_account.address.country}) )
>                  } - #{_("IBAN")} : #{@detail.payment_type.bank_account.iban}), :size => 9
>    end
>  end
> end
>
> if @detail.proforma
>  filename = %(#{_("proforma").camelcase}_#{@detail.date.strftime("%d_%m_%Y")}.pdf)
> elsif @detail.receipt
>  filename = %(#{_("ricevuta").camelcase}_#{@detail.code.to_s}_#{@detail.date.strftime("%d_%m_%Y")}.pdf)
> else
>  filename = %(#{_("fattura").camelcase}_#{@detail.code.to_s}_#{@detail.date.strftime("%d_%m_%Y")}.pdf)
> end
> FileUtils.mkdir_p "#{RAILS_ROOT}/public/gallery/#{Setting.actual_setting.sitename}/Company/#{@detail.company.id.to_s}/attachments"
> pdf.render_file "#{RAILS_ROOT}/public/gallery/#{Setting.actual_setting.sitename}/Company/#{@detail.company.id.to_s}/attachments/#{filename}"
>

Dott. Scolavino Alessandro

unread,
Dec 2, 2009, 10:13:27 AM12/2/09
to prawn...@googlegroups.com
Henrik Nyh ha scritto:
> Did you generate this PDF on Windows? People have mentioned Windows
> issues on this list lately.
No under linux

>
> That is a lot of code. Please try removing parts of the code,
> generating the file and opening it, until you get a minimal file that
> has the error.

Ok i try, maybe that way i can find the problem myself (was a too simple
solution to come in mind ... :P )
scolas.vcf

Dott. Scolavino Alessandro

unread,
Dec 2, 2009, 10:48:45 AM12/2/09
to prawn...@googlegroups.com
the line that generate my error is this:

pdf.render_file "#{path}"

I think the problem arise since i'm saving the pdf and also i'm sending
it as render result, any suggestion to accomplish this task without
having that error (that prevent the pdf from being printed...)?

Henrik Nyh ha scritto:
>> pdf.text %(#{(@detail.receipt ? _("RICEVUTA N�") : _("FATTURA N�"))}), :at => [10, pdf.cursor], :size => 9
>> righe << [free_line.quantity, free_line.description, %(� #{format("%.2f",free_line.price)}), %(� #{format("%.2f",free_line.total)})]
>> end
>>
>> pdf.stroke_color "0b0b0b"
>> pdf.fill_color "0b0b0b"
>> pdf.table righe,
>> :border_style => :grid,
>> :row_colors => [ back_color, "FFFFFF"],
>> :headers => [_("Q.T�"), _("Descrizione"), _("IMP. UNIT"), _("IMP. TOT")],
>> :header_color => '97b4d7',
>> :font_size => 6,
>> :align => { 0 => :center, 1 => :left, 2 => :right, 3 => :right },
>> :column_widths => { 0 => 40, 1 => 355, 2 => 50, 3 => 50 },
>> :position => pdf.bounds.width - 505
>>
>>
>> righe = Array.new
>> righe << [_("Totale"), %(� #{format("%.2f",total)})]
>> righe << [%(#{_("Iva")} #{@detail.vatrate.to_s}%), %(� #{format("%.2f",(total / 100) * @detail.vatrate)}) ]
>> righe << [%(#{_("Totale")} + #{_("Iva")}), %(� #{format("%.2f",((total / 100) * @detail.vatrate) + total)}) ]
>> if @detail.ritenuta
>> righe << [%(#{_("Ritenuta di acconto 20% su")} � #{total}), %(� #{format("%.2f",((total / 100) * @detail.vatrate))}) ]
>> righe << [_("Netto da pagare"), %(� #{format("%.2f",total)})]
>> end
>>
>>
>> pdf.table righe,
>> :border_style => :grid,
>> :font_size => 6,
>> :align => { 0 => :left, 1 => :right },
>> :column_widths => { 0 => 120, 1 => 50 },
>> :position => pdf.bounds.width - 180
>> if @detail.proforma
>> pdf.move_down(20)
>> pdf.text _("Nota spese non valida ai fini IVA. La fattura verr� emessa al momento del pagamento."),:at => [10, pdf.cursor], :size => 5
>> end
>> pdf.move_down(pdf.cursor() - 70)
>>
>> pdf.text _("Modalit� di pagamento"),:at => [10, pdf.cursor], :size => 9
scolas.vcf

Brad Ediger

unread,
Dec 2, 2009, 11:00:10 AM12/2/09
to prawn...@googlegroups.com
On Wed, Dec 2, 2009 at 9:48 AM, Dott. Scolavino Alessandro
<sco...@gmail.com> wrote:
> the line that generate my error is this:
>
> pdf.render_file "#{path}"
>
> I think the problem arise since i'm saving the pdf and also i'm sending
> it as render result, any suggestion to accomplish this task without
> having that error (that prevent the pdf from being printed...)?

What PDF reader are you using? Prawn only officially supports Adobe
Reader and OS X Preview[0], but that error message may be indicative
of a problem in the PDF that Prawn is generating.

Brad

[0] http://wiki.github.com/sandal/prawn/supported-pdf-viewers

Dott. Scolavino Alessandro

unread,
Dec 2, 2009, 11:04:18 AM12/2/09
to prawn...@googlegroups.com
On my pc i'm using Adobe Reader 9, but i have tryed with various version
on different OS..

Brad Ediger ha scritto:
scolas.vcf

Gregory Brown

unread,
Dec 2, 2009, 11:07:41 AM12/2/09
to prawn...@googlegroups.com
On Wed, Dec 2, 2009 at 11:04 AM, Dott. Scolavino Alessandro
<sco...@gmail.com> wrote:
> On my pc i'm using Adobe Reader 9, but i have tryed with various version
> on different OS..

Can you send us a code sample that we can run that is very short? (As
short as possible to reproduce the problem)
And then also send us the generated PDF.

Make sure to do this outside of Rails.

-greg
Reply all
Reply to author
Forward
0 new messages