Generate PDF with images Prawn PDF Rails - ruby-on-rails

I have a rails app using Prawn to generate a PDF and I need to set the PDF to a vertical orientation with an 8.5 x 11 png image on each page (there will be 3).
What would be the best way to make sure these images fit the constraints of the PDF? I beleive I can use a bounding box to control the position but I'm having a hard time wrapping my mind around the code behind it. I'll keep pouring over the docs but if anyone has a suggestion on to get 3 8.5x11 images to display on each page that'd be great.

I was able to figure this out by calling arguments in a hash inside of the initialize method for my pdf
def initialize
super(:page_size=> "A4",:top_margin => 80,:bottom_margin => 40,:template => 'public/template.pdf')
#your pdf code goes here
end

Related

html2canvas not working for large HTML content

I am trying to use html2canvas library, to save html that's dynamically generated and output to the page as image. If the HTML generated isn't too much, then the html2canvas would work just fine, however, if the html generated is really too big (when I try to print it, it's 70 pages), then the html2canvas will return a canvas object where canvas.toDataURL('image/png') returns data:; and that's it.
I found a post online suggesting to change the maxInt in the html2canvas.js file to be Number.MAX_VALUE, but that didn't work as well.
Is there a way to workaround this issue? I will need this image to eventually pass it to jspdf library to generate a pdf document.
First things first. If you are getting clipping it could be because you are trying to capture an image that is too large for the browser. See the FAQ on limits of canvas sizes:
https://html2canvas.hertzen.com/faq
If that's the case then you'll need to break up the image into smaller sub-images and write those out as separate pages to your PDF. You can't combine them into a single image because the browser won't let you.
If you are under that size then it could be because of a defect that affects alpha.12 where capturing document.body can clip content if you are using passing the option windowWidth. The workaround to that defect is just to capture something other than document.body and it'll work.

Does jsPDF allow for custom document sizes such as single labels?

I am trying to create pdf with a single label to print to a Brother PL-7 label printer.
I found jsPDF that is able to generate a PDF, however two problems.
I can't seem to specify the document to a custom size.
I am unsure of how to put the bar code I have in a canvas generated by jsBarcode into the PDF.
How can I create a single label size PDF document with a bar code included on it?
I had the same issue and found this fix on their github issues page in regards to the first problem:
https://github.com/MrRio/jsPDF/issues/372
worked for me perfectly once the that code was altered.
I know a lot less about how what exactly jsBarcode generates, but if it is generating a canvas file as you mentioned in your question, it can be converted into a png/jpeg and then be fed into jsPDF. See HTML5 canvas, convert canvas to PDF with jspdf.js.

iOS - How to add text on top of PDF Document?

I've loaded a PDF Document into a UIView Class, and displayed it on screen using CGDrawRect. So Now I can visually see the PDF: What I want to do is have the user click certain points of the file, which will bring up the key board, allowing the user to directly add text to the PDF, which will later need to be rendered - some direction or guide would be very helpful ?
I understand its a lot simpler to draw a PDF from scratch then to manipulate it
I also understand Quartz 2d may be the way to go, but a bit confused with the samples
There are two possible scenarios here:
Editing existing PDF text is very difficult, even with something like PSPDFKit. It is no accident that there are no PDF-based word processors.
Annotating PDF content is more straightforward:
Add any additional content as subviews to the UIView that contains the PDF document. Additional content can be in the form of text, vectors or images - anything that can be added to a UIView. At this point you do not need to worry whether the added content is "part of" the PDF.
When you want to render the added content to the PDF, simply render the container view (which contains both the original document and annotations) to a PDF Context using UIGraphicsBeginPDFContextToFile and UIGraphicsBeginPDFPage.
Check this question and answer for a simple example and a method for ensuring that the PDF is rendered as vectors, not as a bitmap: Rendering a UIView into a PDF as vectors on an iPad - Sometimes renders as bitmap, sometimes as vectors

Rendering a Rails partial to an image

So, I have a problem and my initial question is: Is this possible?
I'm allowing people to customize the appearance of something using css, and then once they save it I want to turn it into thumbnails to use to display it in various other places (in other sizes maintaining that same aspect ratio).
So the question is, is it possible to do something where I render that partial, then it's saved to an image that I can upload to aws in various sizes etc. using paperclip? Once I get the image I can do the paperclip part, but it's getting that partial to render the html/css and save that to an image... Thoughts?
Just know, any help and/or thoughts at all would be great!
Thanks,
Mike
This might help you:
rails convert html to image

Programmatically rotate tiff image (or pdf)

Does anyone know a way of rotating an image (jpg or gif) in a TWebBrowser control (using Delphi)
Update
The file would be local.
Update 2
So I guess the question should be how do I rotate an image or pdf.
If you have control over the content return in the TWebBrowser it can be done via JavaScript.
Here is an example on JavaScript Image Rotation.
If you want to do it with a TImage there are several options listed in this Q/A.
I guess that you already use this approach to show the HTML content in your TWebBrowser.
Now, instead of JavaScript (as suggested by Robert), you use CSS in the generated HTML document.
I haven't tested this, but you should be able to rotate the image (and other HTML-elements) by using this CSS code (for IE-based browsers):
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
See details at MSDN
Well if it's on a website (in the TWebBrowser) then you can't rotate it. The best you can do is if the image is on your website you can use PHP/ASP/etc. to load the image, and produce a rotated version of it.

Resources