Hey all, I''ve got a question about some strange behavior I''m getting by using the rpdf handler example that Austin wrote in the RoR wiki (http://wiki.rubyonrails.com/rails/pages/HowtoGeneratePDFs). I used that example, and my document generates as expected for the most part. However, the page size is different than the page size I get when I just call PDF::Writer from the command line using an .rb file. I have a document laid out pretty exactly (it''s a legal document, so they''re picky), and the document when generated using the handler is .23 (8.27 inches wide) inches narrower than when generated directly from the command line with the same code. I originally laid out the document by repeatedly generating the pdf via the command line, so that''s my master. Since the .rpdf generated document is narrower, my text is wrapping in some unexpected places. I''ve tried setting the paper size to A4 and LETTER, both with the same behavior. The page is also .69 inches longer (11.69 inches) than expected. I can fiddle with the margins, but I just thought I must be doing something wrong. I could go back to calling the pdf generator as a library, but I love the handler approach. I''d love to keep it if I can. I''m instantiating the writer the same way in both places as well, so I''m pretty stumped. I just don''t see what''s different between the two locations, aside from something that''s deeper than my knowledge of Rails. Has anyone else done this and/or have any insight about what could be wrong? Thanks! Matt _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
More info. Looks like the size problem arises when the document is generated by calling pdf.render and sending the output directly to the browser instead of writing an intermediate file using save_as. I''d really hate to have to deal with temp files. I suppose it might be a bug. I guess I may just have to work around it for now. Matt _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
For what it's worth, if you didn't already know, 11.69x8.27 inches is the exact size of an A4 page. Have you checked your printer settings to see if it defaults to A4 paper? Maybe PDF:Writer is picking up its settings from a printer, for some reason... I'm probably going to start using PDF::Writer myself in the next day or so. Even though I want it to default to A4 page size, I'm curious about what you're seeing. Regards Dave M. On 11/27/05, Matt White <mwhite@page16.com> wrote:> > > > More info… Looks like the size problem arises when the document is generated > by calling pdf.render and sending the output directly to the browser instead > of writing an intermediate file using save_as. I'd really hate to have to > deal with temp files… > > > > I suppose it might be a bug… I guess I may just have to work around it for > now. > > > > Matt > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 11/28/05, David Mitchell <monch1962-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> For what it''s worth, if you didn''t already know, 11.69x8.27 inches is > the exact size of an A4 page. > > Have you checked your printer settings to see if it defaults to A4 > paper? Maybe PDF:Writer is picking up its settings from a printer, > for some reason...No, it won''t be doing that. PDF::Writer is written entirely in Ruby. My suspicion is that there''s something in Matt''s code which is creating the document with an A4 size, e.g.: pdf = PDF::Writer.new(:paper => "A4") PDF::Writer creates its pages from the exact number of *points* (about 1/72 of an inch) and the named paper sizes are merely for convenience. If PDF::Writer is not given a paper size as above, it will always asssume LETTER (U.S. Letter, 8.5" x 11"). -austin -- Austin Ziegler * halostatue-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org * Alternate: austin-/yODNl0JVVCozMbzO90S/Q@public.gmane.org
Hey Dave, Thanks for the info... I actually managed to figure it out! It seems that if you don''t ensure that the view renders without a layout, this problem can occur. Thanks to the Rails wiki for this handy piece of info. So, at the end of my generate method in my controller I just put: render :layout => false (previously called render_without_layout, but now deprecated) Everything snapped back into place in my layout, and the page size is as expected. Major props to Austin Ziegler for that template handler code... That''s hands-down the coolest means of handling pdf generation that I''ve seen in Rails. Matt>For what it''s worth, if you didn''t already know, 11.69x8.27 inches is>the exact size of an A4 page.>Have you checked your printer settings to see if it defaults to A4>paper? Maybe PDF:Writer is picking up its settings from a printer,>for some reason...>I''m probably going to start using PDF::Writer myself in the next day>or so. Even though I want it to default to A4 page size, I''m curious>about what you''re seeing.>Regards>Dave M.>On 11/27/05, Matt White <mwhite-kJFWvbxvH+bQT0dZR+AlfA@public.gmane.org> wrote:>>>>>>>> More info_ Looks like the size problem arises when the document isgenerated>> by calling pdf.render and sending the output directly to the browserinstead>> of writing an intermediate file using save_as. I''d really hate to have to>> deal with temp files_>>>>>>>> I suppose it might be a bug_ I guess I may just have to work around itfor>> now.>>>>>>>> Matt>> _______________________________________________>> Rails mailing list>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org>> http://lists.rubyonrails.org/mailman/listinfo/rails>>>>>>_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 11/28/05, Matt White <mwhite-kJFWvbxvH+bQT0dZR+AlfA@public.gmane.org> wrote:> Major props to Austin Ziegler for that template handler code... That''s > hands-down the coolest means of handling pdf generation that I''ve seen in > Rails.To be fair, I didn''t add that. Someone else did -- I don''t know whom. I don''t do any rails development myself, but I pay attention to the Rails list to try to help with problems like yours. -austin -- Austin Ziegler * halostatue-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org * Alternate: austin-/yODNl0JVVCozMbzO90S/Q@public.gmane.org