rails gem prawn, image and anchor - ruby-on-rails

Can you tell me how to insert image which will be a link to for example page 20? I know how to make with normal text:
text "<link anchor='page20'>Go to page 20</link>", :inline_format=>true
and then on page 20 I have
add_dest('page20', dest_fit(page.dictionary))
but how to do this with image ?

Partly thanks to lightswitch05 for some prodding in the right direction, I've found a way to get the effect I want through this inelegant way:
Insert an image in a bounding_box (the page cursor is at this point at the bottom of the image)
Move the cursor back up to the top of the image
Insert a text link over the image (in my case I just used however many vertical bars '|' were needed to cover the image)
Confirm visually that the clickable link area is about the same as the boundaries of the image
Make the text link transparent, and voilĂ , it looks like you're clicking the image.
Here's some example code (measurements not exact; there was a lot of tweaking involved):
bounding_box([0, cursor], width: 35) do
image open("http://mysite.com/remote_image.jpg"),
fit: [35, 35],
align: :center
move_up 35
transparent(0) do
formatted_text([{
text: "|||", # placeholder
size: 40,
link: "http://example.com/"
}], align: :center)
end
# stroke_bounds
end
Needless to say, this experience has got me looking a bit more at Wicked PDF in order to do what I think I want to do with PDFs.
I'm sure a better/more elegant solution exists, so I'm not planning on considering this my final answer.

Prawn does not support this functionality. In fact, even if you placed a formatted_text_box over an image and fill it with white space, it still will not work. An anchor has to include text to work. If you don't mind having text over your image, then that might be a solution.
Prawn's own readme states:
One thing Prawn is not, and will never be, is an HTML to PDF generator.
After dealing with many of Prawn's shortcomings, I've switched to using wicked_pdf for my Ruby on Rails PDF generation and have been very happy with it. If you can do it in html & css, it can be done with wicked_pdf.

Related

google spreadsheets(google excel) Why is my picture being displayed incorrectly in Html View?

Whenever I add a picture to google spreadsheets in editor mode It always appears lower when viewed in Html Mode. Is their a fix for this?
You can instruct Google Spreadsheet engine with ease how you want the images to render by using this syntax:
To retain aspect ratio while increasing / decreasing the cell size:
=IMAGE("URL")
To make the image stretch and fit all edges of the cell:
=IMAGE("URL",2)
To make the image keep its original size:
=IMAGE("URL",3)
To manually set the image size (replace 50,50 with desired dimensions):
=IMAGE("URL",4,50,50)
Now to answer your question more directly. There are several reasons why this can happen. This comes to how Google are actually translating the spreadsheet and rendering it as HTML.
With that said, it is hard to answer your question with the correct answer while not being able to look at the spreadsheet and the output of the html.
Update
Looking at your source:
The problem is that the CSS that is outputted generates topÄ and left values that makes the image be off by the y axiz.
Here is a method to edit the CSS in Google Spreadsheet if you are familiar with it: http://lifehacker.com/387849/style-your-google-docs-with-css
If you are not familiar with it its probably not much help, but anyway!
If you find this answer helpful please tick accept and up it, i need it :-)

Prawn: Formatting a bounding box

I am a programming and Ruby novice, trying to use Prawn to generate a PDF. I am following the Prawn manual but am having problems with putting text in a bounding box. Here is my code, which mostly comes from the Prawn manual... :
pdf.bounding_box([200, pdf.cursor - 100], :width => 200, :height => 100) do
pdf.text "Just your regular bounding box"
pdf.transparent(0.5) { pdf.stroke_bounds }
end
If I remove this line: pdf.transparent(0.5) { stroke_bounds },
The code will work but I can't see the text box. What do I need to change?
I'm not sure I fully understand your issue. When you say
the code will work, but I can't see the text box
do you mean that you can't see the box's borders, but you can still see the text? Or that you can't see the text either?
I would expect the former, since it is the stroke_bounds that causes the borders to be drawn.
So to answer your "what do I need to change", it depends on what you're trying to accomplish:
if you need the text but don't need the box borders, you can remove the `pdf.transparent(0.5) { pdf.stroke_bounds }, whose only job is to draw a semi-transparent (i.e. gray) border around the bounding box
if you want the border, leave that line in
if you want the border, but want the height of the box to conform to the height of the text, then remove the :height => 100 from the first line. The bounding_box height will then adjust to fit the text.

Core Text: Drop caps + paragraph styles: Incompatible?

I'm attempting to draw a richly laid out text view on iPhone that features:
Custom paragraph spacing (kCTParagraphStyleSpecifierParagraphSpacing)
Custom paragraph first-line indentation (kCTParagraphStyleSpecifierFirstLineHeadIndent)
Justified alignment (kCTParagraphStyleSpecifierAlignment)
Finally, a drop cap on my first paragraph
I'm using OHAttributedLabel. The first three points I achieved without much trouble by just setting some paragraph style attributes on my NSAttributedString.
The drop cap I managed to implement by hacking OHAttributedLabel:
Cut out a rectangular region out of the main paragraph's CGMutablePathRef the size of the drop cap by adding an extra CGPathAddRect, as detailed in this excellent blog post.
Drawing the large character in this region with an extra CTFrameDraw call.
My problem: The paragraph styles and the custom text path are incompatible. When I cut a rectangular chunk out of the main text's path, all the paragraph styles seem to get thrown away.
Does anyone know a way to make them work together? Or can anyone think of another way to implement drop caps? (Short of using a UIWebView + CSS, which I'd rather not have the overhead of!)
Thanks!
You can use straight Core Text to achieve this, in the following post I explain the use of 2 framesetters to lay out text with drop caps in a UIView. In the code example (there's also a link to a github repo) you'll be able to see where the paragraph styles are created and applied to the main text view.
https://stackoverflow.com/a/14639864/1218605

CSS sprite position problem

I trying to create a fixed border to the site that dynamically change size with the browser window from this sprite (it isn't perfect I know.): http://fc07.deviantart.net/fs70/f/2011/269/7/0/bordersprite_by_nakos-d4ayzne.png
DEMO on jSFiddle
My problem as you can see is the vertical wall part. As the #falJ and #falB are height:100% they include the bottom wall's end too with the space between the two wall sprites. Is there a way to force backround-position to only use vertical wall part without bottom wall's end?
Thanks in advance.
Solution: http://jsfiddle.net/vonkly/Ld43B/
It's not the prettiest thing in the world, but it achieves what you want. Check out the source code & direct link for the background images to see what you'll need to do. It's currently set at 299px wide; I imagine you'll be using something wider.
I'd also suggest adding some padding around your content (either with a p tag, span, another div, etc.) - the way it is currently set up isn't what I'd recommend for readability.
EDIT
The only way I can imagine achieving a fluid width + height box with the borders that you have in the way that you want is to use a second image for the west and east containing divs. This should work with your current method.

Latex color box inline with text

I'm trying to put together a LaTeX color box. The xcolor package \fcolorbox seem to be what I want, but I can't get the rendering quite correct. When I use
\fcolorbox{black}{red}{}
it renders a small box sunken to the bottom of the text line. The best I've managed to do is to fake it with a similar text color:
\fcolorbox{black}{red}{\textcolor{red}{--}}
However, I'm worried that this won't render correctly in all situations with defined colors. Is there a way I can declare an empty text box with full in-line text height? Is there another solution?
I'm basically looking for the code that produces the color boxes all through the document at ftp://ftp.dante.de/pub/tex/macros/latex/contrib/xcolor/xcolor.pdf. The boxes I'm referring to are used throughout, but the first instance is on page 4. Thanks.
The xcolor.dtx file in the same directory as the pdf contains the source for the package and the source for the documentation. The relevant bits from the source for the documentation:
\def\testclr#1#{\#testclr{#1}}
\def\#testclr#1#2{{\fboxsep\z#\fbox{\colorbox#1{#2}{\phantom{XX}}}}}
...
(Answer: 40\% \testclr{green} $+$ 60\% \testclr{yellow} $=$ \testclr{green!40!yellow}, e.g., |\color{green!40!yellow}|)
Basically, use \phantom{} on the contents of your color box, and make sure that at least one of the phantom characters is full-height.
Also, https://tex.stackexchange.com/

Resources