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

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;}

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 Convert HTML Table to PDF and Save as PDF along with CSS - Client Side?

My requirement is Save HTML Table to PDF with CSS. And download as PDF file. I used jsPDF but not working in IE to convert HTML to PDF along with CSS. If any paid version or free version both will be fine for me.
Canvas approach will create the image of HTML Table and I want to use as original Table.
Appreciate reply!!!

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.

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.

Delaying the pdf generation when using ExpertPdf converter

I am using ExpertPdf html to pdf converter to convert a web page to pdf. It works fine with most pages, but when I try to convert a page with HighCharts javascript charts on it, only part of the charts are rendered.
My guess is that rendering those charts take longer. Is there a way to delay the pdf generation and allow the full page to load?
You need to set the ConversionDelay property of the PdfConverter object to a few seconds. Also make sure that javascript is enabled.
PdfConverter converter = new PdfConverter();
converter.ConversionDelay = 2;
converter.ScriptsEnabled = true;
byte[] pdf = converter.GetPdfBytesFromUrl(url);
You can find support resources for ExpertPdf here:
http://www.html-to-pdf.net/Support.aspx