hi Paulo,

Let me be clearer on this. I need to create a PDF file, which could contain
word documents as attachments. I can embed both an image and make it
clickable AND attach a word document in the pdf file. However, the
requirement is that when i click on the embedded image, the corresponding
attachment opens up, so that the user does not have to go to the attachments
icon to see what all attachments are associated with the pdf (it might be
confusing for them). So, my query is that is it possible to have some sort
of link between the embedded image and the attachment in the PDF file, so
that clicking image 1 opens up attachment 1, clicking image 2 opens up
attachment 2 and so on? 
There can be more than 1 attachments in the pdf and hence more than 1 images
embedded. 

Here's what i did earlier:-
I associated the word document not as an attachment to the pdf but as a byte
array to the image embedded. Now, when the user clicks on the image, the
byte array associated with the image actually was saved as a file in the
temporary folder of the machine. I was then using the MS Word to open it.
The problem with this approach was that since the byte array was getting
associated with my temporary folder (or my C:/ folder), when i was sending
this PDF file in an email, it was not opening the word document, as it was
expecting the temporary folder of my machine. In nutshell, the embedded
image became as good as a hyperlink (pointing to my temporary folder), which
was not the requirement, as the pdf then became system dependent. 
The following is my code snippet, if that may help:-

------------------------------------- start of code
---------------------------------------------------
                                      // get the byte array for the word
document to be attached
                        byte[] b = getBytesFromFile("C:/Test.doc");
                        
                        docWriter.addFileAttachment("This is Test.doc", b, 
null, "Test.doc");
                        
                        Paragraph imageParagraph = new Paragraph("Testing this 
image");
                        doc.add(imageParagraph);
                        String name = "MyWordFile";
                        Image testImage = Image.getInstance("C:/word.jpg");
                        testImage.scaleToFit(50, 50);
                        testImage.setAlignment(1);
                        
testImage.setAdditional(PdfFileSpecification.fileEmbedded(docWriter, "",
"This is test", b, true, "application/msword", null));
                        File tempFile = getPathInLocalMachine(b, name);
                        testImage.setAnnotation(new Annotation(0, 0, 0, 0, "",
"application/msword", "", ""));
                        testImage.setOriginalData(b);
                        doc.add(testImage);

-------------------------------------- end of code
---------------------------------------------------



No problem with that, just make the activation area the size of the
image. See
http://article.gmane.org/gmane.comp.java.lib.itext.general/19141.

Paulo 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of [EMAIL PROTECTED]
> Sent: Tuesday, June 03, 2008 12:44 PM
> To: itext-questions@lists.sourceforge.net
> Subject: [iText-questions] click on image and open the attachment
> 
> Hi,
> 
> I have a requirement where i need to embed a word document 
> image file in a PDF document generated by iText. So far so 
> good. However, i need to ensure that when i click on the 
> image, the attached word document actually opens up. 
> In nutshell, the image in the PDF file should actually link 
> to the attachment in the pdf document.
> 
> Any pointers will be greatly appreciated.
> 
> Thanks. 
-- 
View this message in context: 
http://www.nabble.com/click-on-image-and-open-the-attachment-tp17623373p17638626.html
Sent from the iText - General mailing list archive at Nabble.com.


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar

Reply via email to