Is this possible?
I am getting the directory and filename of a existing PDF document.
C:\temp\FileName.pdf
Use PDF Renderer to either view the document or print the document
I have PDF Renderer included in my Eclipse Project, just not sure how to use it
Then use PrintDialog to print out the PDF Document.
I think that PDF Renderer has to do something to make the PDF document printable
I want have 2 buttons on my form
View PDF -> opens the pdf document in read only
Print PDF -> gets the pdf document ready to print then calls PrintDialog to select a local printer and then prints
I am not having much luck finding any PDFRenderer sample code that shows how to open the PDF document in view mode.
I haven't seen code on how to send the PDF Renderer result to a PrintDialog to print.
You certainly can implement PDF rendering in your application. The question is, if it is really necessary or not. Since you dindn't specify which library you want to include, I can't help you with the PDFRenderer.
However, for purpose of launching an external PDF viewer and how to implement a print button, those API classes are useful:
org.eclipse.swt.program.Program
org.eclipse.swt.printing.PrintDialog
At least it'll help to (partially) solve your problem.
Related
I want to use pdfBox to extract test from Persian pdf files, but it returns "?" for all the Persian characters (it returns correctly the Latin words in the same document).
How can I fix it? Any advice?
Sadly, the provided file has the persian text as vector graphics, not as text from fonts, so it cannot be extracted. You'll have to use OCR for it.
See also the text extraction FAQ:
How come I am not getting any text from the PDF document?
Text extraction from a pdf document is a complicated task and there
are many factors involved that effect the possibility and accuracy of
text extraction. It would be helpful to the PDFBox team if you could
try a couple things.
Open the PDF in Acrobat and try to extract text from there. If Acrobat
can extract text then PDFBox should be able to as well and it is a bug
if it cannot. If Acrobat cannot extract text then PDFBox ‘probably’
cannot either.
It might really be an image instead of text. Some PDF documents are
just images that have been scanned in. You can tell by using the
selection tool in Acrobat, if you can’t select any text then it is
probably an image.
I print documents (pdf, doc, docx...) via javax.print and it works fine, but I need to add a custom overlay text on any place at document; the text is necessary to insert a printed reference from my code to the document.
How do I do this?
I do not believe adding text (watermarking) is an aspect of javax.print.
You can pre-process each page of each document via Graphics2d and add in the text/graphic individually based on that document's type, then send that document to the printer.
There are several threads here and elsewhere on "watermarking", which is essentially what you're looking to do. The process is different based on the type of document you're working with. Single-page images, multi-page images, PDFs, DOCs, and DOCXs all require different ways to be processed.
Here are some threads to get you started:
GIF/JPEG/TIFF: How can I watermark an image in Java?
GIF/JPEG/TIFF: Adding a watermark over an image programmatically using Java
DOCX: Creating watermark programmatically
PDF: Watermarking PDFs via iText
The Usecase is to sign a given pdf document. I have already done the signing part, which places a visible image somewhere inside the pdf.
Now i have to let the user decide where to place the visible part of the signature.
I want to present the pdf document to the user and let him place a (draggable) rectangle somewhere inside the document.
In the end i want to get out the coordinates and the page of this rectangle.
I do not want to manipulate the pdf, just get out the coordinates and page.
I can also guarantee that adobe pdf reader is installed on the machine (windows) of the user.
Do i have to use a pdf renderer library (which?) or could i use the existing adobe pdf reader?
I decided to use jPedal and draw a rectangle onto it by extending the PdfDecoder and overwriting the paintComponent method.
I have a library which generates pdf document with images.
I want to be able to add text after each image. What is the syntax for that? How to insert text into pdf documents?
I have to use the library I have, not another one.
First of all, mkl is correct, have a look at the specification for all of the details. PDF is an exact language, if you make mistakes they will routinely be punished severely once you open the PDF in viewers.
Secondly, when you think about putting text on the page, don't forget that besides the text operators to draw the text on the page, you'll also have to specify the font to use to draw this text. Which will include making sure there is a font resource included in the PDF file if your library doesn't automatically handle all of that for you.
If you want to cut corners (I shiver while writing this) and perhaps don't read the specification as thoroughly, try this.
1) Create a PDF file that looks more or less like what you want.
2) Use a tool such as pdfToolbox from callas (http://www.callassoftware.com/callas/doku.php/en:download) or Browser from Enfocus (http://www.enfocus.com/en/products/browser). Both of these tools allow you to investigate the low-level structure of a PDF file, including looking at the actual page description code. This will show you how fonts are embedded (if you have to do it yourself that could be very handy) and how text is rendered on the page (and how you set the font, size, color etc... to use).
I have a program. It outputs to pdf, but that is close to impossible to read from again. So i need a additional file attached to my PDF in order to be able to make it editable in my program. Attaching a file to PDF is a good idea, but that is visible to the user, which i don't wan't it to be.
An alternative is to hide my readable file format inside an image which would be added to the PDF somewhere to the top of the first page, before everything else... Even to metadata if that's possible...
That way I can extract image from pdf using a PDF library (iText), and read from it.
My question is how to add image to PDF to be as well hidden as it could be (visually and by accesibility). And it has to be in a place which would be same for any created document (somewhere on the top, or on the very bottom of the document, or to the part of the document which isn't displayed at all... I'm really guessing here, I'm not really familliar with PDF file format)...
Any ideas?
P.S. It's not really important which image is it, I could be a e.g. completly transparent image, 1x1 pixels.
I'm not sure what you mean by Image, but you can "extend" the PDF reference.
A PDF consists of objects: PDF numbers, PDF names, PDF strings, PDF arrays, PDF dictionaries, PDF streams. What you probably want, is to add an entry to a dictionary (pick one: the root dictionary, the info dictionary, the root of the page tree,...) that isn't defined in the PDF reference, so that it isn't rendered in a PDF viewer.
The key of such an entry must be a PDF name. To avoid clashes with existing names (names that are part of a current PDF spec, or will be part of a future spec), it is advised to register a four-letter key with ISO. For instance, Adobe registered adbe, iText registered ITXT and use that name with an underscore. For instance, ITXT_OriginalData would be a good name if we needed the functionality you describe.
The value of such an entry will be a PDF stream. In iText, you need the PdfStream class for this.