I'm trying to create a PDF using iText library. The PDF has to embed an animation, which is a set of bitmaps. And there are buttons to control the animation. To understand it, see the following file:
http://www.texample.net/media/tikz/examples/PDF/wankel-motor.pdf
How can I create such a file from iText?
I know that I can embed a video file with this code:
http://itextpdf.com/examples/iia.php?id=188
But here I don't want to embed a video file, but a set of bitmaps and to add the control buttons.
Thanks in advance,
V. Henley
The document doesn't have any images. Instead it has a large series of Widget annotations inside a rectangle of which the lower-left and upper-right corners have the following coordinates:
llx = 4.981
lly = 287.238
urx = 322.053
ury = 542.754
These widget annotations are buttons that overlap each other and of which the appearance is defined using PDF syntax (paths consisting of straight lines and Bézier curves).
There are also a number of smaller buttons with arrows and other symbols. When clicking them, some JavaScript is executed:
The animations is actually JavaScript alternating the visibility of the different buttons. If you want to know more about the JavaScript that is used, you have to dig into the document using iText RUPS (which is what I did to create the above screen shot).
The principle that is used to create this PDF is identical to the principle that was used in the Calculator example, which is an example that was distributed with the same book you refer to.
Finally, I've been able to create such a PDF using latex code:
This is the latex code:
\documentclass[10pt]{article}
\usepackage{animate}
\usepackage{graphicx}
\usepackage{media9}
\pagestyle{empty}
\begin{document}
\AtEndDocument{%
\label{lastpage}%
}
\animategraphics[width=9.54cm,height=6.36cm,controls]{2}{C:/Users/casa/Documents/programacion/tex/construc_}{0}{3}
\end{document}
So after compiling such code with a latex compiler, it produces a pdf similar to the one I posted.
Kind Regards
Related
I got a peculiar problem. I am business analyst working on a dash-boarding product based on java applet. I don't have access to any elements in the java applet it's like a black box.
I am looking to print a section of page without using html elements (since I don't have access to code). Ideal case would be using something like window.print() that takes Start (X,Y) and End (X,Y) coordinates .Then in the dialog I can select pdf995 option to print as pdf.
For e.g. (23,45) to (93,100) pixels should print the area within that range. Instead of pixels, percentage should be good as well.
Any help is greatly appreciated. Thanks guys.
Maybe this will help. How to get the X,Y coordinates of a point in a PDF
On that question you should have everything you need.
You can use java.awt.Robot ; java.awt.Image to take the ScreenShot and write a Image File (bmp or jpeg, or what you like); next, you can use Jasper Report to create a PDF and view the file report. Jasper its a powerfull library to create reports, website here
You can find some details to how take screen shots here. Its also possible to take screen shots with cordinates. You can see some examples here
Is there a way to draw lines on a graph for an existing PDF? I have a custom graph that I need to plot the lines for and I wanted to see if there was anyway to do it with itext or any other open source PDF software. Thank you for your consideration of this matter.
First take a look at the StampText example. It shows you how to create a PdfStamper and how to obtain a PdfContentByte object. In this example, we stamp text on the existing PDF.
You want to draw lines, which also requires a PdfContentByte because that class has an abundance of methods to draw paths and shapes. These methods are all explained in chapter 14 of my book. See for instance paths.pdf and the code that was used to draw these paths, PathConstructionAndPainting.
I would like to convert a string of text into an image. The issue is, I want the text to wrap if it is wider than the length of the image, and the height of the image to be dynamically sized to perfectly fit the text, so that I know how much space the text takes up.
I'm working in Java and there are several things I have tried:
Rendering HTML in a JPanel and saving as a BufferedImage. The problem here was that most of the css I used was ignored by the JPanel and the image was unusable.
Using ImageMagick and img4Java. The two big failures with this solution was that I needed the command-line tool installed, which I can't do on our server. The second was that I couldn't easily convert the image to buffered image for use in the rest of the app.
Does anyone know a way to do this in Java?
Thanks!
In this example, an arbitrary panel is rendered into a BufferedImage and displayed in an adjacent panel at half-scale. The example uses a grid of labels, but you can use the wrap feature of JTextArea or the geometry supplied by TextLayout, examined here.
You might use a label containing HTML for the line-wrap, as shown here.
To get an image of that, see LabelRenderTest.
Looking for tips/tools to make this happen (using PDF/Velocity Templates/Java):
I have an image that has large dimension (4000 x 2000) and that image is obviously not viewable in a PDF. I can modify the size of the image to fit into the PDF.
But what I want to do is to view the actual size of the image in the PDF. I want to be able to scroll the image from left to right.
How can I keep the true size of the image, without destroying the set container size of the PDF?
That's not quite a basic PDF feature, but it might be implementable using some embedded scripts inside the PDF, assuming that the user has a PDF viewer capable of running scripts.
Now, a PDF is not supposed to be used as a dynamic document where you can scroll. How would that work on paper after printing? If you want scrollable documents, then you should stick to HTML. I strongly advise you not to try to do this.
If, however, you still want to go down this route, then here are a couple of suggestions:
As I said, you could do it with embedded JavaScript, but then it depends on how you're generating the PDF: FOP, iText, another PDF writer library, or just plain println concatenation, since few libraries support embedding JavaScript.
You could just make the image fit into the page, but keep its original resolution, so that you end up with a high resolution page that the user can zoom in and scroll. This way you leave the scrolling to the PDF viewer itself, you'll just have to let the user know that the image has a higher resolution and should be magnified. And frankly 4000px isn't that large, it's not even enough to keep up with today's standard printer DPIs.
I'm working on application in Java that will maintain database of song lyrics in plain text and print out some songbooks/chordbooks(that is create PDF file from selected songs). I was planing that the Java application will generate source code for pdflatex and after compiling this source user will get PDF file.
Lately I've run into a lot of problems because of latex limitation: fixed memory size (some pictures will also be drawn to PDF) - error when exceeded, no way to query end of line or and of page dynamically, it's very hard to override latex placement algorithm in a complex way,... see also some my other questions regarding latex. I come to conclusion that latex is not good option for automated PDF generation.
So I need replacement. I need to be able to typeset:
Chords over lyrics when the lyrics are in variable char width so I need to be able to measure text width
Chord diagrams that means I'll have to draw quite complex pictures
Each song on separate double page
Different fonts etc.
Thanks for all answers
Here are some PDF open source APIs
http://java-source.net/open-source/pdf-libraries
This has been asked many time, You might want to look at this post
IText is a free library which offers lots of capabilities for creating PDFs programmatically.
Rather than try to manage/calculate the complexities of the desired layout, you could try Docmosis. It will let you layout a document as a template using doc or odt formats. This means if you could make a doc or odt look like you want, you can turn it into a template and get Docmosis to render it as a PDF. Text and images can be placed inside or outside tables which makes layout fairly easy to manage.
ConTeXt is another TeX system, but it is easier to control the layout than with LaTeX. For drawing you could use PGF/TikZ or MetaPost. Support for both is available in ConTeXt. With ConTeXt's built in Lua scripting you could draw the chords automatically, assuming you have them stored in some sort of data structure.
why not just use lilypond with latex? it's meant for typesetting music.