How can we add header and footer same for all pages through out pdf using jsPDF. And apart from this please let me know that what are all ways to create pdf using jspdf like using HTML content or a string or some HTML template so please help me out on both query
Although jsPDF does not have a dedicated header or footer functions, you may use
var doc = new jsPDF();
doc.text("Header or footer text", x, y);
Where x is margin from left of the page and y is from the top.
You may have to position it as per your page dimensions require.
And about your second query, jsPDF has addHTML and addImage (Older versions of jsPDF) functions to help you generate PDF.
addHTML take in raw HTML code as input while addImage takes image as input which can be positioned on the PDF page.
addImage requires additional libraries such as html2canvas for image generation.
Related
I use pdf The print function in js, but unfortunately, the printed paper has a print time in the upper left corner and words such as "PDF. js viewer" on the top, which causes the overall content to be lower. Please ask me how to set the pdf. js file to avoid this problem?
I hope you can give me an answer to this question
In my HTML page, 2 diff chart is available that's the way I convert full page as an image and after it saves as pdf using jspdf.
I need set header or footer before it update in html2Canvas and jspdf.
but how can I add header and footer in pdf?
You don't add headers and footers in PDF. Read more about PDF, it is a low level standardized format, where the primitive operations are something like move to coordinate x=340, y=450 (in some unit, perhaps tenth of millimeters or typographical points) and change font to Helvetica 10 and show the a letter. Read the PDF standard.
You may generate PDF from some higher level text format. I recommend reading about LaTeX and Lout and many other such document processors. You could consider generating some LaTeX or Lout file, then converting it to PDF (by running some pdflatex or lout process).
You could use a PDF generating library such as JagPDF and many others.
You might find HTML to PDF converters. Most web browsers have one. Look also into pandoc.
I started using html2Canvas. I'm trying to convert the below donut chart into a pdf using html2canvas and jspdf.
The result is as follows:
We can make out that text gets cropped.
Then I tried to change the text next to donut chart to this :
The result is so peculiar:
Why do only specific text nodes getting converted by html2Canvas? Why is the rest of it cropped? What is the programmatic workaround. Any help would be appreciated.
I want to convert entire html page to pdf. Thanks to stackoverflow, i got idea, but i want to convert both divs and ng-grids.
Try1: While including both in specialElementHandlers, data and column headers in grid are not displayed properly in pdf. [column headers are displayed as individual rows and unwanted ng-grid code snippets are captured (Total Items: 0
(Showing Items: 0)
Selected Items: 0
Page Size:
/ 1)]
Try2: After converting all my divs to tables, some data are not properly displayed in pdf. Data are not properly placed in table structure.
Kindly let me know, if this is due to html design issue or jspdf property setups.
You can convert it to an image and insert your image in a html document. Or you put this document in a ftp server and load this.
I have a pdf which I would like to use as a template to create a new pdf. The goal is to place an image inside a particular placeholder rectangle in the original pdf. The creation of the original pdf is under my control but the placeholder rectangle/bounds might be anywhere in the pdf. I am thinking of using a dummy image(of same dimensions) as the placeholder rectangle in the original pdf.
The Prawn gem supports placing an image at a given absolute/relative position within a page.
The trouble is that since the rectangle or dummy-image could be anywhere in the original pdf, I don't know what values to use for the following
pdf.image "/path/to/image", :at => [x,y] prawn call
Is there a way to get the coordinates of an image in the original pdf. My primitive understanding tells me that one would have to render the entire pdf to know this. Is that right ? If yes, what would be a good way to render pdf in memory (headless) and get the co-ordinates of various pdf objects(like bounding rectangles, images, etc).
I am not limited by language/runtime here as long as I can trigger it programmatically.
What could be other approaches to this problem ?
Not an answer (e.g. I don't know the Ruby language), but in lieu of any others, and because I can't post a comment yet, here's what I think.
If conditions stated above are true (placeholder and replacement images are exactly same size + same color model e.g. RGB 24 bps) and you control template creation (therefore you can store placeholder inside PDF uncompressed), it can be as quick and dirty as raw replacement in a file treated as byte string. E.g. placeholder filled with red, then you search for pattern (0xFF0000) x W*H and replace it with raw image data. Which, of course, you can get any way you like, e.g.:
convert my_image.jpg RGB:- | ...
If this solution is too dirty or conditions not exact, then parse page content stream for construct like
width 0 0 height x y cm
/name Do
It's not cleanest, either, but for vast number of simple page descriptions x and y are the coordinates you are looking for.
Further, if you control template creation, why don't you store additional information inside pdf as e.g. custom keys in Info dictionary, and then read them back when using the template.