Render images in phantom-pdf - phantomjs

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.

Related

Fit PDF page in container using ngf-thumbnail

I have the following line of code to embed pdf in HTML
<embed ngf-thumbnail="factura.picFile" id="factura_prev_pdf" ng-show="factura.preimageext=='pdf'" class="view_complete_image" type='application/pdf'>
As you can see I'm using ngf-thumbnail to show the pdf.
Javascript attached to the id just get the extension, not important here.
ng-show say true if extension id pdf and the css class adapt the pdf to the container size.
The thing is that the pdf preview is adapted to the width and height but the page is not visualized entirely.
Any idea ?
I saw things like Zoom to fit: PDF Embedded in HTML
But it doesn't work to me since I'm not using
EDIT what I see now is that you can modify a pdf url like http.thingthing.pdf#view=fit to make page fit but my files are loaded from local so it creates a blob:url where I cannot put this view=fit.
It's possible to convert this blob url to a normal url with the pdf extension?
Finally I achieved the following:
<img ngf-thumbnail="factura.picFile" id="factura_prev_image" class="view_complete_image">
<embed ngf-thumbnail="factura.picFile" id="factura_prev_pdf" ng-show="factura.preimageext=='pdf'" class="view_complete_image" type='application/pdf'>
<img src="{{ factura.image.url }}" ng-show="factura.preimage && factura.preimageext=='jpg'" id="factura_image" class="view_complete_image">
<embed src="{{ factura.image.url }}#view=fit" ng-show="factura.preimage && factura.preimageext=='pdf'" class="view_complete_image" type='application/pdf'>
As you can see, in the first 2 lines I'm using ngf-thumbnail... This two fields contains local files so to visualize it we get a Blob Url, in this way I couldn't add the #view=fit that allows me to visualize the entire pdf page.
In the last 2 lines we get pdf's that are uploaded to a server so we get a normal url.
In this way I can add the #view=fit so the page fits.
Hope it helps to someone.
This answer is to know how to fit a pdf page, but I'm not answering to fit the page when we get a Blob Url.

How to show external link in PDF rendered by pdfjs

Is the only proper way to add a text layer? Can I only render text layer specifically for links in the pdf?

Utilities for exporting/printing graphs?

given that the functionality for exporting graphs to SVG or PNG in the Neo4j server page is broken (see SO article), are there any utilities out there that can export a graph from Neo? something that would produce a PDF perhaps?
With not many changes, you could make it work with http://www.cloudformatter.com/CSS2Pdf to format the SVGs in browser to PDF. That set of pages has some d3 samples like this: http://www.cloudformatter.com/CSS2Pdf.SVGCharts.d3Charts
I took one of the sample charts and rendered to PDF through the Javascript and the remote formatter. The page I selected was here and I took one of those charts:
http://graphgist.neo4j.com/#!/gists/1428842b2170702400451777c2bc813f
The code needs some minor change to ensure that Neo4j puts the svg namespace on the element. The samples on that page do not. But the rendering is near perfect. See the web page on the right and PDF result on the left. I only formatted the SVG and not the whole page (where the silver background exists) and that seems to be the only difference.

iText - generate PDF for Store Ticket Machine

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.

How to generate a Pdf in Land Scape orientation from a html string using Itext 2

I am using this code to generate a PDF from HTML String.
ITextRenderer renderer = new ITextRenderer();
renderer.setDocumentFromString(new String(htmlString.getBytes("UTF-8")));
In table some row contains data of a very large length.Due to which the text is overflowing the PDF.I have used Word Wrap in HTML.But this is not working in PDF generated by the code.
I want to know if there is any alternative in IText 2 to Word Wrap?
Or can i generate my PDF in Landscape Mode so that i could display the whole data in PDF.
Any suggestion is welcomed.
I have attached one image at following URL.
http://www.mediafire.com/download/l19qa33myluaqj4/pw-4_(2).jpg
You can set your page in landscape mode using CSS, using:
#page { size: A4 landscape;}
The page size is part of CSS 3 specification, and is supported by flying saucer.
I got the answer as suggested by #Bruno Lowagie
We can set our page in landscape mode using CSS, using:
#page { size: A4 landscape;}