I am using the ruby on rails axlsx gem to render my excel.
Now I want to style the text so that it shows up diagonally as shown in the sample image attached.
I am not sure where or how to set this alignment feature in the code.
Any help is appreciated!
alignment: {:textRotation => 60}
That did it for me.
I managed to find a similar issue from the axlsx github page:
https://github.com/randym/axlsx/issues/110
I wasn't able to locate it in the docs.
The complete code can be implemented as follows:
my_style {
alignment: {:textRotation => 60, horizontal: :center, vertical: :center, wrap_text: true},
}
sheet.add_row(headers, style: styles[:my_style], height: height)
Related
(Rails 6.0.2.2, ruby 2.7.1, combine_pdf 1.0.18)
I'm currently trying to write some text to an existing PDF with the CombinePDF gem. Unfortunately I'm running in some encoding problems.
I'm loading the existing PDF:
pdf = CombinePDF.load "#{Rails.root}/public/pdf/base.pdf"
Then I'm adding text to it:
pdf.pages[0].textbox "Straße", height: 20, width: 160, y: 527, x: 215, font_size: 12, box_color: nil, text_align: :left, text_padding: 0
When generating a new pdf out of it:
send_data pdf.to_pdf, filename: "output.pdf", type: "application/pdf"
the string gets displayed as StraˆŸe, so the ß isn't displayed correctly.
I also tried to replace it with unicode literals (\xc3\x9f) without any effect.
Anybody has an idea what else to try?
If you use HexaPDF you could do something like this:
require 'hexapdf'
require 'stringio'
doc = HexaPDF::Document.open("#{Rails.root}/public/pdf/base.pdf")
doc.pages[0].canvas.font("Helvetica", size: 12).text("Straße", at: [215, 527])
outio = StringIO.new(''.b)
doc.write(outio)
Just make sure that you use a font that contains glyphs for all characters you want to use. So better use a TrueType font instead of the builtin Helvetica (you can just provide the path to a TrueType font to the #font method).
When I try to create a pdf in Arabic Language, I'm getting the letters in reverse order.
I use the following code to generate a pdf file.
note_section = {content: "#{order_item.try(:notes).try(:connect_arabic_letters)}" ,
size: 8,
font: "app/assets/fonts/ufonts.com_arial-unicode-ms.ttf",
text_color: "313131"}
Expected text is:
In prawn it looks like:
Gem version => Prawn version:2.2.2 Rails version:5.1.6
Any help is highly appreciated, thanks!
i've got trouble for croping a picture with Rmagick and then display with Prawn
Here is the code :
First a method to instantiate the image with RMagick :
def build_magick_image(path)
if path.instance_of?(StringIO)
Magick::Image.from_blob(path.read)
else
Magick::Image.read(path)
end.first
end
In my case i have an instance of StringIO.
Then i crop the picture :
img = build_magick_image(picture_path)
cropped_img = img.resize_to_fill(1735, 1560)
But now i can't find how to display it in my Prawn pdf.
My last try is :
pdf.image cropped_img, at: [image_x, image_y], height: image_height.mm , width: inner_page_width.mm
But obviously it doesn't work.
Can someone help me?
Thanks :)
I found your question when I was trying to figure out the same thing 😬 Here's the solution I came up with:
Wrap your image blob in a StringIO object, which will give Prawn the interface it needs. In your specific case:
cropped_img_sio = StringIO.open(cropped_img.to_blob)
pdf.image cropped_img_sio, at: [image_x, image_y], height: image_height.mm, width: inner_page_width.mm
For this moment, I generate a svg file and then I read it and I display it in my pdf:
qr = Barby::QrCode.new('test')
outputter = Barby::CairoOutputter.new(qr).to_svg
File.open('myfile.svg', 'wb'){|f| f.write outputter }
pdf.svg IO.read('myfile.svg'), width: 50, height: 50
My question is: how can I display my svg without saving a .svg file before. I know there is a css property that allow that but I can't use css with prawn...
Any ideas?
It's working like that:
pdf.svg outputter, width: 50, height: 50
thanks #Mark Thomas
Please help me to make validation for maximum width and height of image.
I have tried like this.
validates :picture, dimensions: { width: 612, height: 792 }
But I got Unknown validator: 'DimensionsValidator' message.
Kind Regards.
Ensure you have added gem 'paperclip-dimension-validator' to your Gemfile