i use RQRCode to create qr code and want after that insert my svg( not one a few ) in a pdf.
Can i do it with nokogiri? or how to do it? Should i convert qr to xml and next insert this xml(qr) to xml(pdf-file) and after that convert xml to pdf?
You can use prawn-svg to directly embed the SVG into a PDF document generated by Prawn.
If that doesn't work for you, convert the SVG to an image format like PNG and then include that image.
Related
I am creating a one page PDF with PrawnPDF in ruby (Rails). I want to insert and existing PDF in the top of the pdf at certain position in the PDF I am creating with PrawnPDF.
This is dooable with an Image but would be good if possible with PDF.
Anyone know if this is possible ?
I don't think you can do this with Prawn, but the combine_pdf gem allows you to merge pdf documents and if you really need to sandwich something in the middle, you could create partial files and merge them in the order you need.
From the doc of https://github.com/boazsegev/combine_pdf:
pdf = CombinePDF.new
pdf << CombinePDF.load("file1.pdf") # one way to combine, very fast.
pdf << CombinePDF.load("file2.pdf")
pdf.save "combined.pdf"
Part 1: I have PDFs, Docs,Docx stored in my S3. When I download them I want them to first be converted to images (png or jpg) and then only download (as images or a thumbnail of images).
How to achieve this ?
Part 2: I have used mini-magick to convert pdf to image and its somewhat working like this:
require "mini_magick"
im=MiniMagick::Image.open("path/to_my_pdf.pdf")
im.format("png", 0)
im.write("some_thumbnail.png")
The problem here is a pdf can have multiple pages and I need each and every page to be converted into image format (may be an array of images) and I am not able to achieve it. I am only able to convert any one of the page of the pdf. Stuck here. Kindly help.
Answer any part of the question as you like. !!
You can do that using RMagick gem as following.
require 'RMagick'
pdf = Magick::ImageList.new("path/to_my_pdf.pdf")
pdf.each_with_index do |page, i|
page.write "#{i}_thumbnail.png"
end
pdf = Magick::ImageList.new(self.checklist_question.resource_file.service_url) do
self.quality = 100
end
This converts the pdf to images but does not get the point on how to save and merge them in pdf again and then upload to active storage.
You could use a different gem like carrier_wave and write the data as explained here: https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Upload-from-a-string-in-Rails-3
fellow programmers!I extract a ppt file with using tika,which has only plain text.However,the result that tika give a content type is a jpg format!So my question is how to deal with it for I only want that case to be detected as a plain text type.
I change some source code in the tika,so I can get what content I want.In this way,I extract the ppt file and get the right result.
I have uploaded 1 PDF then convert it to xlsx file. I have tried different ways but not getting actual output.pdf2xls only displays single line format not whole file data. I want whole PDF file data to display on xlsx file.
i have one method convert PDF to xlsx but not display proper format.
def do_excel_to_pdf
#user=User.create!(pdf: params[:pdf])
#path_in = #user.pdf.path
temp1 = #user.pdf.path
#path_out = #user.pdf.path.slice(0..#user.pdf.path.rindex(/\//))
query = "libreoffice --headless --invisible --convert-to pdf " + #path_in + " --outdir " + #path_out
system(query)
file = #path_out+#user.pdf.original_filename.slice(0..#user.pdf.original_filename.rindex('.')-1)+".pdf"
send_file file, :type=>"application/msexcel", :x_sendfile=>true
end
if any one use please help me, any gem any script.
I would start with reading from the PDF, inserting the data in the XLSX is easy, if you have problems with that ask another question and specify which gem you use and what you tried for that part.
You use libreoffice to read the PDF but according to the FAQ your PDF needs to be hybrid, perhaps that is the problem.
As an alternative you could try to use some conversion tool for ebooks like the one in Calibre but I'm afraid you will lose too much formatting to recover the data you need.
All depends on how the data in your PDF is structured, if regular text without much formatting and positioning it can be as easy as using the gem pdf-reader
I used it in the past and my data had a lot of formatting - you would be surprised to know how complicated the PDF structure is - so I had to specify for each field at which location exactly which data had to be read, not for the faint of heart.
Here a simple example.
require 'pdf/reader' # gem install pdf-reader
reader = PDF::Reader.new("my.pdf")
reader.pages.each do |page|
# puts page.text
page.page_object.each do |e|
p e.first.contents
end
end
not able to find options to convert from PDF to xsls but API Options available for converting PDF to Image and PDF to powerpoint(Link Given Below)
Not sure u can change the requirement to show results in other formats!!
http://www.convertapi.com/