Current Cursor Position when Using the Prawn Ruby Library - ruby

I'm using the Prawn Ruby library (http://prawn.majesticseacreature.com/) to generate some pdf documents. I draw a table without any problem. Next, I want to insert some lines after the table for various people's signatures. Before I draw the lines, I would like to see if there is enough remaining room on the page to fit all the signatures. If not, I will start a new page and put the signature lines there. However, in order to determine if enough room remains on the page, I need to know what the current cursor position is after drawing the table. I can't for the life of me figure out how to do this. Any ideas?

Of course, after entering the question, I immediately figure it out. The 'y' and 'y=' methods in the Document class allow you to get and set the current y position, which is all that is necessary.

Related

Google Sheets: How do I format a range to color a row if every cell in that row has matching data?

I want to make it so if all of the cells in a row has data that matches, it will automatically change the row's fill color to green.
Example of the desired visual effect, including my conditional formatting work-around to achieve the look
As you can see in the image, the rows that have empty cells are not colored green.
Some other functionality I would also appreciate:
Make a row recolor to red if it contains cells that have mismatching data. (such as someone putting their name in someone else's row)
If data is added to a previously empty row, expand the Protected Range by 1 row after 30 minutes.
If a row within a Protected Range becomes empty, the Protected Range automatically sorts itself from A-Z by Column A and reduces its size by 1 row.
Context:
I've recently made a spreadsheet on Google Sheets for my guild in an MMO to track what professions and recipes everyone has, people with the link can perform edits on the sheet, but I do have protected ranges that cover older entries which have their editor access restricted to a small team so random people don't just delete all the data. None of the other officers that regularly maintain the spreadsheets we use have much experience with spreadsheets, which are pretty basic with little automation. It takes three to four of them to do my job when I'm on vacation despite teaching each of them how to maintain the spreadsheets. More automation would be nice for when I go on vacation and eventually retire from that MMO.
This is my first post on this site, I don't know computer programming, not that well-versed with spreadsheets, and trying to google this didn't help since everything I found talked about conditional formatting based on the columns, not the rows.
For now my temporary work-around is to manually add conditional formatting to a range each time I see a row has filled up to change the fill color to green if the cell contains exactly that person's name. Based on prior experience with my guild's other spreadsheets, I know the other officers would not do this themselves.
I'm not sure where to look for help with Google Sheets, but I have a family member that is a developer and I vaguely remember him mentioning this site which is why I'm giving it a shot.
try:
=SUMPRODUCT($A2:$K2<>"")=11
on range A2:K
update:
=(SUMPRODUCT($A2:$R2=$A2)=18)*(A2<>"")
on range A2:R

How to insert my 1:100 draw from Autocad into a Word document

I must to insert an 1:100 image I did in Autocad inside a Word document. I just printed in PDF format and it fits a A4. I could do a print screen, paste it on the Word page and crop the boundaries, but it need some very sketchy adjusts to put it back into the correct scale. Also the lines does not render very well. I believe there is a better and correct way to do.
I guess my first question would be, "Why do you need to insert the file into a word document?"
If you must insert it into a word document, you should use the Insert Object process described here -->PDF into Word Doc.
This would never be my preferred method though. I would rather convert the word document to PDF and then insert my scaled PDF drawing into the exported word doc PDF. This would keep the integrity of your drawing scale intact.
Just my two cents, which won't get you much.

Clear the current path in Cairo

In some Ruby code which uses Cairo, I need to draw a number of fills over a single path. This is part of a graphics application, where multiple fills may be stacked on top of each other using different blend modes.
Each fill is drawn using fill_preserve to preserve the path so that the next fill can occur over the same path without retracing it. This is done somewhat like so:
rectangle_data.each do |rectangle_datum|
context.rectangle(*rectangle_datum.rectangle)
fill_data.each do |fill_datum|
context.set_source_rgba(*fill_datum.color)
context.fill_preserve
end
end
The problem is that this leaves the path even after all fills have taken place, which means that individual shapes are just drawn as one huge filled shape.
To solve this, I'd simply need to clear the current path manually, but I can't figure out how to do this. I've had a look through the documentation for Cairo::Context through Google Translate but I can't find it. (The docs are in Japanese!)
How can I manually clear a Cairo context's current path?
I had a look over Cairo::Context#methods and found #new_path, which does just what I'm after. So you can do:
rectangle_data.each do |rectangle_datum|
context.rectangle(*rectangle_datum.rectangle)
fill_data.each do |fill_datum|
context.set_source_rgba(*fill_datum.color)
context.fill_preserve
end
context.new_path
end

What is the best way to convert PDF pairs into single pages?

I need to take an existing PDF (created with Prawn), and combine pairs after page 1 (the cover) into single pages. I would also like to add a vertical line in the center of the joined pages. The pages are to be printed in books, and the goal is to make single PDF pages that are similar to the side by side view in Acrobat. I know I can convert them to images, do what I need to with ImageMagick, then put them back into a PDF format, but I am trying to minimize the number of conversions so I can save as much quality as possible.
I also realize I can do this from the start with Prawn, but I am trying to avoid that as it would require a very large change to our application.
It is possible to do this with Ghostscript and the pdfwrite device, but its by no means simple. You need to write some PostScript to do the job.
You would need to add BeginPage and EndPage procedures, the BeginPage would need to check the current page number (and you would need to track this yourself). If its page 1, process normally. If its an even page, throw away the current PageSize and replace it with one which covers a pair of pages. Process the even page. Do not transmit the content.
If the page is odd (and not 1) then translate the origin so that its offset to the right by the width of the page. Process the odd page. use moveto, lineto and stroke to draw the required line between the two pages. Transmit the page.
This assumes that all the pages are the same size and orientation, or least that the sizes of each page are known in advance. It would be possible to retrieve those programmatically as well, but more complex.
Its definitely non-trivial, but if you rummage through my answers in the PostScript tags and look for anything with the word 'imposition' you'll probably find program outlines to do the job.
I did a quick look and here's an answer I wrote some time back. It uses a different approach to that outlined above, it copies some of the guts of the PDF interpreter and repurposes them. It does a chunk of what you want though.

Printing Reports and invoices with Ruby?

I just learn Ruby, and I wonder how to generate Reports and Invoices (with Logo, adressfield, footer, variable number of invoice-items (sometimes resulting in more than one page), carry over of the amount to pay from one page to the next, free-floating 2-column text (left-and-right-justified) below the resulting cash-informations).
Currently I get a canvas to print and draw on from the OperatingSystem (matching the printer specifications) and use some draw-, move-, line-, text- and formfeed-API-Functions and do some heavy calculations for textblock-moving (a bit TeX-like).
How will this be done in Ruby?
Building an .odt and throw it to OpenOffice or a .tex and throw it to LaTeX?
Or are there any free Libraries, thet do all this kind of things for me, so I only have to feed the relevant parts, and let Ruby do the Text-Formatting thing?
EDIT:
To be more specific: I want to put a corporation logo on the first page (DIN-A4-format, but may also be letter) on a specific position, also the footer on every page and the adress-box on the first page. all the rest should be free floating text blocks with left-right-justification, bold words in the middle of texts.
something like
pdf.column.blocktext("Hello Mr. P\nwe have [b]good news[/b] for you. bla bla bla and so on. Please keep this text together (no page break)...");
pdf.column.floatingblock("This is another block, that should be printed, and can be broken over more than one column...");
which should render the text in the corporate font on the paper, justified, and wrapping neatly to the next column/page if it reaches the bottom of the page.
Thinking about it, this is exactly, what LaTeX is for.
I suggest you consider PDF generation. In Rails, it's pretty simple with the Prawn library.
There is also a fresh new Railcast about that.
Official web site.
You could also check out HtmlDoc for generating PDFs, it just takes in HTML and generates a PDF from it. This approach is nice because it lets you very easily reuse a partial for an on-screen and hard copy invoice.
http://blog.adsdevshop.com/2007/11/20/easy-pdf-generation-with-ruby-rails-and-htmldoc/
The Ruport library (Ruby Reports) makes it pretty easy to spit report tables out in multiple formats, including PDF. There's also a ActiveRecord hook acts_as_reportable that gives your models a reporting interface.

Resources