images padding when converting html to pdf using itextpdf and XMLWorker - itextpdf

I am using XMLWorker 5.5.3 and itextpdf 5.5.3 to convert html to pdf.
my html contain table with cells that conatin images.
i.e. part of my code :
my problem is that some cells add padding > 0 so the td that contain the image is bigger than it should be.
Is there a way to define style for images so the will not have padding and margin ?
I am looking at css Demo of Itextpdf and not finding a solution , any help/trick /ideas will help .
thanks
Tami

I found a solution:
when I create the table I define columns width :
PdfPTable table = new PdfPTable(vColWidth.length);
table.setWidthPercentage(100);
table.setWidths(vColWidth);
when creating the Image object I define :
RegularImg = Image.getInstance(imgsrc);
RegularImg.setSpacingAfter(0);
RegularImg.setSpacingBefore(0);
when defining the td :
cell = new PdfPCell(RegularImg);
if(colSpan!="")
cell.setColspan(Integer.parseInt(colSpan));
if(rowSpan!= "")
cell.setRowspan(Integer.parseInt(rowSpan));
if(cellHight!="")
cell.setFixedHeight(Float.parseFloat(cellHight));
table.addCell(cell);
this solutions works o.k. if the table is not so big or complicated with the colSpan , rowSpan .
In complicated cases I advise people to convert the table of pictures as a Canvas , not using a table. just place each Image in the specific place in the doc . (the performance are much faster.

Related

How to convert html contents including divs and ng-grids/tables to pdf using jspdf

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.

iOS UITextView attributedText <img> position

I have this RTF in my UITextView object:
"Test text <img src='http://icons.kdaweb.com/commerce/png/50x30/payment_types-american_express.png'> test text.
And result is here
I need to move image for few pixels under baseline, but <img style=...> doesn't work.
What can i do with image without using UIWebView ?
SOLUTION:
One style attribute works for me:
img {vertical-align:-5px;}
I really suggest you to use the UIWebView. Writing the img tag don't let you many choices. Using this class will help to well structure your code, avoiding any non maintainable code.
Then you'll be able to play with a CSS sheet, I really prefere the UIWebView solution.
Edit
A way I don't recommend but could be a (bad) solution: make bigger the text and change img height to the text height. But you'll need to have a better image (SVG ?).

How to create table in Pdf with functionality of rowspan and colspan in IOS

Want to create complete report in pdf. i successfully draw text and images in PDF by using Apple documentation but i am unable to find any solution to create table in PDF with rowspan and colspan functionality, also if table size greater than pdf page size then it displays remaining table to the next page. Any solution,API or library which helped me for this Problem?
PDF has no builtin notion of tables. In fact, the only PDF primitives are Glyphs, Shapes and Images. If you want to generate a table, you have to stroke all the lines of the table yourself, using, for example, CGContextStrokePath (after you have built a path with the lines in the table).

Prawn - Zoom out contents so that it fits in one page

I have a dynamic PDF report which gives monthly report of our database. I am using Prawn to generate the PDF report.
The monthly report can contain maximum of 90 rows (maximum 3 per day). There can also be days with no record. So, the number of rows in a monthly report is highly dynamic.
The client needs the report in a single page PDF. They dont care if the font size becomes very small or the row height is really small. But the contents should fit in a single page.
They have shown examples of PDF that are generated using their previous application. In those, it seems that they are creating the table with a fixed font size and row height etc. and they are somehow zooming out so that the PDF has some whitespace in the right side of the page, but it fits in a single page.
Something like this:
Is there a way to achieve this in Prawn?
The needed page layout can be easily achieved with PD4ML's fitPageVertically() API call - but PD4ML approach differs from Prawn quite significantly.
With PD4ML you have to generate an HTML document with report data/table (not that tricky to do) and after that pass it to PD4ML for a converting to PDF.
PD4ML in Ruby scenario can be launched as a standalone converter application.
You can build a fixed size table for print with option:
overflow: :shrink_to_fit
in table cells. That will shrink to a smaller font automatically.
given the number of rows to be print, you can dynamically adjust tables row heights
see: http://prawnpdf.org/prawn-table-manual.pdf

Finding coordinates of an image in a pdf to replace it with another one

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.

Resources