Issue in expert html2pdf - pdf-generation

I have used expert html2pdf for pdf genratiion
I have one table consisting the various row with background color
after converting the html table to pdf it display space between table rows,
when set zoom level of pdf to 100% .
If i reduced the zoom level below 75% it not display any space
Please check following screens
Screen 100%
http://prntscr.com/6o2019
Screen 75%
http://prntscr.com/6o20f2

I suspect that lack of margins is related with rendering of PDF file by Adobe Reader and what scale algorithms Adobe Reader uses and has nothing to do with html2pdf library (and any other as well). Suppose that this behavior may be different in other readers, e.g try to open in Firefox build-in reader (it written in JavaScript) or other reader, so margins may disappear with other zoom or not disappear at all.
If it is I'm afraid it is impossible to somehow fix this behavior of the particular reader program. Try to ask about this issue Adobe Reader developers.
Or try to reimplement design of your table - e.g. to increase margins, etc.

Related

How to export JPanel to pdf using iText7 with embedded font introduced in JPanel, asymmetric paper margins, and points positioning

I have no prior iText 5 experience but only started reading about iText 7 less than one month ago. I have a fairly complicated task of converting JPanel displays within a master JTabbedPane into pdf with several simultaneous requirements. I use Swing to specify font and need to embed the font in the pdf. I need to specify asymmetric pdf margins and distribute top versus bottom, as well as left versus right margins evenly that each JPanel dynamically left open on a landscape US paper. My generic Java program uses per pixel x and y positioning of all JComponents and the program dynamically knows the x and y extent of each completed JPanel display depending on data content of multiple stacked JTables on each JPanel. Using 100 pixels per inch, my JPanels will not need scaling to fit the landscape US letter size paper using my specified margins.
I made three separate searches on developers.itextpdf.com with queries of "export JTable to pdf", "export JPanel to pdf", and "export JFrame to pdf" but found no results whether I filter with iText 5 or 7. The same queries typed into the general internet browser search box turned up multiple results from Stack Overflow (such as How2: Add a JPanel to a Document then export to PDF) and miscellaneous sources. However, all the solutions are iText 5 dependent because they all use PdfTemplate and PdfContentByte which are absent from iText 7, and a different version of PdfWriter with getInstance method. However, iText7 export JPanel to pdf shows no result on Stackoverflow. Since I started after iText 7 has been introduced, I prefer to code my JPanel to pdf conversion with iText 7 if someone can point me how to do it.
Even with the iText 5 solution, how can I be sure that my single Java font specified in my JComponents get transferred into the intermediate Graphics2D (if iText 7 also uses it) and properly linked up with an iText font embedding call. Additional things I have to tinker with are converting 100 pixels per inch in JPanel to 72 pts per inch on pdf, and the placement of pdf media box for proper margins. I hope simple mathematics with some special rounding attentions are all that's needed for the tinkering part. Please allow me to thank in advance for any forth coming help.
I had a similar problem, but went for a much simpler solution. It is very easy to convert a Swing component into a Java Image, in much the same way you would take a screenshot of the running app. Once you have a big BufferedImage containing your JPanel contents, you can write it straight into a PDF Document. Then you don't need to mimic any of the Swing code being used to populate the JTabbedPane at all.
Here are some code fragments to help you out. Suppose your app creates a JPanel containing Swing elements like JLabel's and the like. To capture this as a Java image, you could do:
JPanel myPan = createPanelForTab1(); << your main app code does this
// Take a snapshot of myPan as a Java image
BufferedImg jImg = new BufferedImmage(myPan.getWidth(),
myPan.getHeight(),
BufferedImage.TYPE_INT_ARGB);
myPan.paint(jImg.createGraphics());
Then convert the Java Image to an iText Image (they are different things). You might also want to scale this image down a bit to fit on a page:
itextpdf.layout.element.Image itextImg = new Image(
ImageDataFactory.create(jImg, null));
itextImg.scaleToFit(400.0f, 9999.9f); // (if it's too big)
Adding this img to a PDF Document is as simple as:
itextImg.setHorizontalAlignment(HorizontalAlignment.CENTER);
document.add(new Paragraph(iTextImg));
Perhaps this is the way to go?
(Note: Since you are taking a screenshot, you don't need to worry about any font requirements in the PDF. On the downside, though, there is no text from the Java app in the PDF so you can't search it, for example.)

Document creation and editing online

What language or technology would I need to be able to create documents online? I want to be able to add text and images and move them into position, resize etc, similar to this.
And then when complete, create a PDF from them.
Sorry if this is a bit vague, I just need to know where to start researching.
You need to decide on your basic technology: Flash, Silverlight, Canvas, client-side SVG, server-side SVG or server-side bitmap. There are also commercial solutions that work with Adobe InDesign documents (and probably a host of other proprietary formats) but I'd expect those not to be cheap.
Flash/Silverlight require plugins, and are considered by some to be a dying technology - though I am sure that is disputed. Canvas is 'very HTML5' and is essentially a bitmap built/rendered on the client, but if you are ultimated rendering to PDF it may not provide the resolution you need. The same limitation affects building an image server-side too - you should probably be dealing with vector elements plus bitmaps, rather than rendering everything to pixels as you go.
That leaves SVG in my list, either on the client (see RaphaelJS) or on the server (see Inkscape). I'm doing some work with server-side SVG rendering at the moment, and it is promising; although subject to more scalability issues than client-side, it doesn't suffer from browser-compatibility issues or the limitations of browser rendering.
The biggest issue in browser SVG rendering is flowed paragraph text and text in/on a path - I am not sure how well these are implemented in modern browsers, or how much agreement there is between them. This is especially the case given that some of these require SVG1.2, and browsers (afaik) are only just settling on SVG1.1, after many years. But, if you just want to do standard blocks of text, bitmaps and vector elements, browser-based SVG should suit you fine.
The example you've given uses a server-side technology (SVG, or perhaps a commercial format) and renders to low-res PNG on the client.
In your case, once you've considered how to 'do the editing', you'll need to consider how to render to PDF, which will be done on the server. You could go low-level and use something like FPDF, use a report renderer like Jasper, or use a graphics system like GhostScript, Inkscape, Scribus, ps2pdf, svg2pdf etc.
Aside: I normally don't answer questions without obvious prior research. But, since you've indicated that you will indeed undertake this, I'm happy to help get you started.

image size for iPad

I'm creating a magazine to read on an iPad and am having problems with creating readable pages. What size (DPI and MB) should my files be? And I'm doing an export from InDesign, are there any suggested steps that should be taken here?
The iPad display is at 132 PPI.
The iPad display is 1024 x 768 - I'd recommend making your images that size.
That's right, the image size for iPad is by default 1024x768, but I recommend you to create your file in 1152x1536 px if you want to zoom-in in your image on iPad end keep a good quality of display.
Are you creating a pdf of the entire document or saving the pages as images? You may also want to consider the way users will be accessing the document (online, each page downloaded or as an application) If it is an application you will be able to have larger page sizes. If online, then download size will definitely become a factor in how it looks. If you shrink the quality too much, your rendered text will be the first thing on the page to suffer.
Have you done any research into what you find a comfortable to read text size (i.e., with popular science, wired, or project magazines? Another one to check is digital2.0 or the first of the RAW applications which was put out) These magazine apps use scrolling text regions in a lot of cases, but you can at least see how they use fonts and how comfortable they will be at different sizes.

Windows Phone 7 Image Looping

I would like to loop through a sequence of images. I have tried using a Pivot control, but I don't like the blank space in between image transitions. I would prefer to use something that will animate between images smoothly. I also looked at the LoopingSelector control, but I can't seem to set the orientation to horizontal.
I'm assuming you're interested in a kind of image viewer like iOS offers, swiping right or left to navigate through the photos. If that's the case, I hate to say it but i think you're looking at building your own control.
I think to implement it properly these are the essential things you need to think about and address:
For performance' sake, load all the images you have into memorystream objects and store the binary data (you can get creative with this and only store the first 10-15 images, depending on how large the images are, doing this would enable your control to support thousands of images and still perform like a champ).
Once an image is about to be on-screen set the source of the image to the saved memorystream object that has the bytes loaded into it (this will minimize the work that the UI thread does, keeping the control performant and responsive)
Use Manipulation events to track the delta x of the motion someone uses when swiping left to right in order to actually perform the moving of the items
Move the images by changing their Canvas.Left property (you can go negative I think, otherwise just make your canvas the width of all the images you have combined)
Look up some of the available libraries to support momentum so you can have a natural smooth transition between images

Increase page loading speed

In my app, I've a panorama-page which contains around 10 panorama items. Each panorama item has some path drawings, a list picker and few input fields.The problem i'm facing is that whenver i navigate to this page the navigation is very slow due to lot of content to initialize. If i comment the InitializeComponent(); the loading becomes fast.I thought of adding the XAML content in code, but the problem is that i've to access the input fields by their name in code, so it didn't worked.Any idea how i can speed up the navigation to the page.Thanks..
From the UI Guide:
Use either a single color background
or an image that spans the entire
panorama. If you decide to use an
image, any UI image type that is
supported by Silverlight is
acceptable, but JPEGs are recommended,
as they generally have smaller file
sizes than other formats.
You can use multiple images as a
background, but you should note that
only one image should be displayed at
any given time.
Background images should be between
480 x 800 pixels and 1024 x 800 pixels
(width x height) to ensure good
performance, minimal load time, and no scaling.
Consider hiding panorama sections
until they have content to display.
Also, 10 PanoramaItems seems like a lot since the recommended maximum is 4. You should either cut down on the number, or hide the content until it's required. Have a read of the best practice guide for Panoramas on MSDN.
I think you could improve page performance by creating usercontrols for the specific panorama items, add an empty panorama control to your page (with only the headers) and as picypg suggests load these usercontrols when they are needed.
Another way could be that you load the first page and show this one already to the user. In the background you could start loading the other panorama items.
My suggested approach would be for the first one. Using the lazyloading principle.
I woudl assume that your delays are due to the number of items on the page. This will lead to a very large object graph which will take a long time to create. I'd also expect it's using lots of memory and you have a very high fill rate which is slowing down the GPU.
Having input items/fields on PanoItems can cause UX issues if you're not careful.
That many panoItems could also cause potential navigation issues for the user.

Resources