PrawnPDF Flip Entire PDF - ruby-on-rails

I'm using Prawn PDF to create a label that I send to a label printer, but the label prints upside down. This is important as the shipping labels we use come with some print already on it. The setup I'm using (an iPad through a Lantronix xPrintServer to a Zebra Printer) won't allow me to flip it using the drivers.
So I'm wanting to know if there is a way using Prawn (or even just Rails) to flip the entire document (which contains 2+ pages) so it prints out correctly on the labels. The order of the pages isn't essential.

I haven't used Prawn lately, but I'm pretty sure using the rotate method at the top of your code will work. You'll just need to either set the origin to the center of the page, or use translate to reposition the content after rotation. Page 29 in the manual (PDF) has some example code.

You could save the pdf to a file and then use the awesome pdftk to rotate the saved pdf, then send the amended version.
https://www.pdflabs.com/docs/pdftk-cli-examples/
EDIT - pdftk is not a library/plugin/gem, or any kind of Ruby for that matter. It's a command line tool which you would use like this, in your controller, replacing your current "generate and send pdf" code.
#instead of sending the pdf straight to the user, save it to a file
#i'm not sure how to do this in prawn but it can't be difficult
#rotate the original to a new file
`pdftk /path/to/original.pdf cat 1-endsouth output /path/to/rotated.pdf`
#you could test whether the rotated file exists here as an error-check
#then use send_file to send the rotated one as the response.
send_file "/path/to/rotated.pdf", :type => "application/pdf"

Related

Fill PDF form with data and images

My goal is to fill the existing PDF interactive form with user data.
Requirements for this are:
it should be able to insert data into text fields;
it should be able to insert an image on the XY position.
I found FillablePDF gem for inserting data into interactive PDF forms. But, can't find if I could insert an image.
For inserting an image I found Prawn gem.
Is there better way or solution for this with only FillablePDF gem?
You can do both tasks with the latest version of HexaPDF which has gained support for AcroForm interactive forms. HexaPDF is a pure Ruby PDF manipulation and creation library, so you wouldn't need to rely on iText and Java like with FillablePDF.
The code for your task would be something like this:
require 'hexapdf'
doc = HexaPDF::Document.open(input_pdf_file)
doc.acro_form.field_by_name('Name of text field').field_value = 'New value'
doc.pages[0].canvas(type: :overlay).image(image_file, at: [x, y])
doc.write('output.pdf')
Note that if this is for a commercial project you will most likely need the commercial license of HexaPDF.
Alternatively, using Prawn with the prawn-blank gem should also work.
(Nota bene: I'm the author of HexaPDF.)

Excel to pdf conversion in rails4 with libreoffice

In a rails 4 application, how can I convert an excel spreadsheet file into pdf.
When I am trying to implement Excel to pdf the contents are listed in different pages if excel column size is large.
How to generate the pdf without moving data to next pages in pdf.
Please help,
Thanks
So you basically have two options you can either implement this yourself and use a CSV gem/library (default CSV, faster CSV, or smarter CSV) assuming that by "excel" a CSV is acceptable. If a CSV is not acceptible you can use the axlsx gem instead. Then for pdf conversion you can use something like prawn. If you decide to build this yourself follow these steps.
Create a controller that will handle Reports, I suggest using the rails g controller report upload generate_table show generate_pdf generator to create a controller and a view for the upload process
Create a file upload form in the upload view.
On submit you will send the file to the generate action processing with one of the CSV or excel gems
Once processed your end product should be an array or hash (as an instance variable) and you can send that to the show action
In the show view you will iterate of that hash/array and incapsulate the contents in a html table.
On the show view you should have a button that will send that same hash/array to the generate_pdf controller action where you will use prawn to create a pdf, you can use something like send_data to the send the completed pdf file back to the user.
This is roughly how you could go about it less the low level details. Now if you wanted to use an out of the box solution you could use something like Ruport. Ruport will handle most of the heavy lifting for you the only thing is you need to have your models and associations set up to use it the way it is designed, and that may not be an option for you.

XPages form in A4 format

I would like to create a XPages form to print it out. I am not sure which is the best way to do this. I mean I need to create a panel or table or any other design elements then put all my staff in it?
I need advise:)
Regards
Cumhur Ata
Speak after me: browsers don't print.
If you need precision layout a browser is your worst enemy. Each one renders slightly different, so don't bother.
Your best bet is to create a PDF file for printing. There you have pixel-perfect rendering as you deem fit.
You can use iText, PDFBox or XSL:FO to generate PDF. There are code samples on OpenNTF or you read my blog entries about it.

Create pdf inapp iOS [duplicate]

How to generate a PDF file on a user action?
See "Drawing with Quartz" to see how to create a PDF Graphics Context.
Some notes:
"iPhoneOSNote: If you want to create a PDF graphics context in an iPhone application, make sure you also read “Drawing to a Graphics Context in iPhone OS” (page 27)."
"You can write any content to a PDF that’s appropriate for your application—images, text, path drawing—and you can add links and encryption. For more information see “PDF Document Creation, Viewing, and Transforming” (page 177)."
As an example of creating a PDF from the contents of a CALayer, you can refer to the -dataForPDFRepresentationOfLayer method within the CPLayer class in the Core Plot framework. You can do something similar to extract the content from a CALayer-backed UIView, although we had to subclass CALayer in order to get vector elements to render to a PDF properly.
Use this library to generate pdf file by programmatically.
SJ_PDFCreator
Use a web service on a server back end to post the data to - then generate the PDF and return it to the browser/app with the correct mime type to open as a PDF.
ColdFusion could easily do this for you in just a few lines of code.

How can I create a PDF file programmatically in an iOS application?

How to generate a PDF file on a user action?
See "Drawing with Quartz" to see how to create a PDF Graphics Context.
Some notes:
"iPhoneOSNote: If you want to create a PDF graphics context in an iPhone application, make sure you also read “Drawing to a Graphics Context in iPhone OS” (page 27)."
"You can write any content to a PDF that’s appropriate for your application—images, text, path drawing—and you can add links and encryption. For more information see “PDF Document Creation, Viewing, and Transforming” (page 177)."
As an example of creating a PDF from the contents of a CALayer, you can refer to the -dataForPDFRepresentationOfLayer method within the CPLayer class in the Core Plot framework. You can do something similar to extract the content from a CALayer-backed UIView, although we had to subclass CALayer in order to get vector elements to render to a PDF properly.
Use this library to generate pdf file by programmatically.
SJ_PDFCreator
Use a web service on a server back end to post the data to - then generate the PDF and return it to the browser/app with the correct mime type to open as a PDF.
ColdFusion could easily do this for you in just a few lines of code.

Resources