iText - generate PDF for Store Ticket Machine - pdf

I'm using iText 5.4.4 and I want to generate a PDF for a continuous paper ticket printer. My doubt is how to set the new Document to avoid splitting the pdf in several pages:
Rectangle pagesize = new Rectangle(360f, 720f);
Document document = new Document(pagesize, 36f, 72f, 108f, 180f);
There is any posibility to do this ?

PDF is not HTML. PDF is a Page Description Language. At the root of a PDF file, you have an object named the Catalog dictionary. In this Catalog dictionary, there is a reference to a page tree. This page tree is a structure that contains references to every page in the file. A page is an autonomous element in the PDF. Suppose that you have a PDF with 10,000 pages and you only need page 10,000, then you can fetch that page directly without having to render the 9,999 preceding pages. This is a "raison-d'ĂȘtre" of PDF. Hence your question sounds very strange: it is inherent to PDF to have pages.
It seems as if you want to create a PDF with a single page, containing a number of tickets each measuring 10 inches in height. In that case, you have to create a large page on which you print all these tickets (note that this is a bad idea, but I'm merely answering your question).
You need to take into account, that there's a maximum size for a PDF page. This maximum is 14,400 for the width and 14,400 for the height. So if you want to create a single page for a large number of tickets each having a height of 10 inch, you can create a page like this:
Rectangle pagesize = new Rectangle(360f, 14400f);
You will be able to fit 20 tickets with height 10 inch (720 user units) on this page, not more.

Related

Dynamic DOMPDF custom fonts issue and page break functionality

I have a quiz built on WordPress. After a user takes the quiz the results will be mailed to the user's email address as a PDF. So the PDF is not supporting the custom fonts (II Voorkurs). We have used all options such as #fontface etc.. but still not working.
The second issue is that the content on the PDF is dynamic (text length varies as per the user test score). So this makes some elements break when there is a page break in PDF.
Cann anyone help me out?

Render images in phantom-pdf

I'm using phantom-pdf recipe to render template content. So far so good I could able to generate PDF document successfully but we have new requirement now i.e adding one or more images at the end of the document. Each image should render on its own page. Page size should be the Image size no header/footer needed.
Images can be of various sizes.
To render the image I'm using HTML tag as part of Template Content
<img id="bg" src="#this.Context.Request.Scheme://#this.Context.Request.Host#this.Context.Request.PathBase/Assets/Screenshot.png" /><div style='page-break-before: always;'></div><img id="bg" src="#this.Context.Request.Scheme://#this.Context.Request.Host#this.Context.Request.PathBase/Assets/Untitled.png" />
I can see the rendered Image in the PDF document but I see empty white space at the bottom of the page (After rendered image there is white space) Rendered PDF document
Is there any way using Phantom PDF my Page size will be image size (Header/Footer is not required)??
Currently, the business is using PPT document where each slide is an Image and transform the PPT to PDF.The generated PDF document consists one or more image and each image on its own page. (No white space/No header & footer).
You can scale image size to the full page using css. However you can't adapt your page size based on the image. phantomjs doesn't support each page in the pdf document having a different size. You would need to generate each pdf separately and then use another software to merge them together.

iText 5 resizes the page when I add a Table spanning across pages

I have set the document size to A4 with the following code initially document.setPageSize(PageSize.A4) but when I try to add a table spanning across multiple pages it resizes the page size to 8.2x11.69. Is this the correct reason why the page is automatically resizes or am I missing something? I can provide any section of the code if someone can take a look.
updated with the suggestion.(table.setWidthPercentage(100);)
You are not using the most recent version of iText (which is iText 7), but one of the previous versions (iText 5) that sets the default width of a table to 80% of the available width of the page.
You should add the following line (assuming that table is an instance of PdfPTable):
table.setWidthPercentage(100);
Please go to the official web site for more examples, for instance to the Cell and Table Widths page.

Combining a page map with a PDF so that annotations move with pages in updated PDFs

Has anyone managed to provide an end-user with an updated PDF, allowing that user to transfer his local annotations to the new PDF and keeping the annotations on the correct page, even when there are pages inserted into the update PDF at a point earlier in the PDF than the annotations.
I thought there might be a page map or page guid approach that someone has used.
Sorry - I hope that is clear.
Instead of using the page index as ID of the page, you can use the page content stream instead (after decoding/decompression). Most PDF libraries will give you access to that, so you could compute an MD5 hash from the page content and search for that instead on your "updated" file in order to know where to transfer your annotations.
This is assuming that the page content will be indeed identical, which is not a common scenario.

PDF Generation: fit table to page

I have to export a table with dynamic count of rows to a PDF that must fit on one page.
Currently, I'm generating an HTML document, wrapping the table within a <div> and then using CSS zoom to zoom out; the percentage is calculated with the count of rows. This HTML is then converted to PDF via wkhtmltopdf.
I need a better solution because the zoom calculation is not very reliable. Some rows are displayed higher than others and also wkhtmltopdf has some rendering troubles when using zoom.
I looked in the docs of FOP, iText and some other libraries/tools but couldn't find a solution.
Only requirement: It has to run on a Linux machine.
Thanks!