White lines in PDF output

40 views
Skip to first unread message

aslak hellesoy

unread,
Jun 22, 2009, 1:26:52 PM6/22/09
to ruby-...@googlegroups.com
Hi again,

Barcodes rendered onto PDFs seem to have some thin white lines that ought not to be there. This happens with both Prawn and PDF::Writer. I have tried with both QrCode and PDF417 (which I added a couple of days ago). PNG rendering seems fine.

Here is a test script: http://gist.github.com/134084

The bug is probably in Barby's prawn_outputter.rb and pdfwriter_outputter.rb - in how coordinates are calculated. -Or how line_to is invoked.

Any ideas?

Cheers,
Aslak

aslak hellesoy

unread,
Jun 22, 2009, 1:36:43 PM6/22/09
to ruby-...@googlegroups.com

It turns out the white lines are visible when the PDF is viewed in OS X Preview.app, but not in Adobe Acrobat Reader on Windows. I haven't tried any other viewers.

Stumped!
 

Cheers,
Aslak

Tore Darell

unread,
Jun 22, 2009, 3:37:38 PM6/22/09
to Barby
Hi Aslak,
Yeah, I've had the same experience; the white lines appear when I use
the Evince document viewer in Gnome, but Adobe's Acrobat Reader will
display it just fine. I'm not sure if it's the way the PDFs are being
generated (i.e. Barby's outputters) or inaccuracy in some readers in
positioning the elements. If you zoom in and out sometimes you can see
some lines disappearing and others reappearing in the same way widths
using the same "em" size in CSS can vary in width because it's
converting a relative size to fixed pixels, which could point to the
problem being the reader's accuracy.

I encountered the problem first when generating 1D barcodes where I
would paint each "x dimension" or "module" (a 1 on the encoding
string) separately, so when two 1s appeared next to each other there
would be a small gap in some readers. I fixed this by painting
adjacent black modules as one element (the boolean_groups method; if
you look closely at 2D barcodes you'll notice the lines appear only
horizontally because this method is used for each row); I guess this
is possible for 2D barcodes too if there's a way to figure out all the
black modules whose edges touch, but this feels like fixing the
symptom while the cause still remains unknown.

Another possible fix is to stroke each module to make sure they
overlap, but this too feels like a hack to me. It could possibly serve
as a quick fix if you need something working fast though.

Tore

> Stumped!
>
>
>
> > Cheers,
> > Aslak
>
>

aslak hellesoy

unread,
Jun 22, 2009, 3:57:04 PM6/22/09
to ruby-...@googlegroups.com

The fix I ended up using is to use png instead. With Prawn:

    png = qr_code.to_png :xdim => 10
    def png.read # Monkey patch to fool Prawn into thinking png is a File.
      self
    end
    pdf.image png

Good enough for me. Since I'm using JRuby I also had do patch png:
http://github.com/aslakhellesoy/png/commit/6df909bdf7e5328843a893c01648f822db4d07dd

Aslak
 

Tore

> Stumped!
>
>
>
> > Cheers,
> > Aslak
>
>


Tore Darell

unread,
Jun 22, 2009, 4:02:01 PM6/22/09
to Barby
I just remembered I've seen this in PDFs not generated by Barby too,
so I tried printing them and my cheap inkjet printer has no problem
"filling in" barcodes in either the Barby or other documents..

aslak hellesoy

unread,
Jun 22, 2009, 4:17:21 PM6/22/09
to ruby-...@googlegroups.com

I just remembered I've seen this in PDFs not generated by Barby too,
so I tried printing them and my cheap inkjet printer has no problem
"filling in" barcodes in either the Barby or other documents..

That's good to know. All PDFs I'm generating are going to be printed, so it's probably not going to be an issue if I end up using annotate_pdf instead of embedding pngs.

Thanks!

Aslak
 
Reply all
Reply to author
Forward
0 new messages