Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Vijay_YD
Posts: 23
Registered: ‎10-20-2011
My Device: Blackberry Z10
Accepted Solution

Save set of images to pdf file from Java App

[ Edited ]

Hi ,

 

 is there any feasability of saving images which have been loaded from res folder to screen to the PDF file.

 

Scenario goes like , there will be set of images in the Horizontalmanager and while clicking on particular image need to save it to PDF file and then to Sdcard .

 

Thanks in Advance.

Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: Save set of images to pdf file from Java App

It's feasable. But it probably won't be simple.

It also depends on what the resulting PDF should be like.

If it's a simple "each page is a image" then it shouldn't be too bad.

If it should be formatted in a certain way, be in a certain format, be encrypted/compressed, have bookmarks, etc. Then it will be much harder.

JPedal is the only real one I know who has an editor AND J2ME experience. Nearly every PDF creator I know of is J2SE. I don't know if JPedal mas a J2ME version of their dev. library, and I also don't expect it to be free.

If this is a must have feature for your program, you might want to look into creating it yourself. That could be a big endevour, but the sheer lack of anything for J2ME makes it tough.

One other option that I have recommended to others (for reading PDFs) is to have a server do the heavy work. Take the image, get the data as a byte array, send to server. Server makes PDF, sends back. This gives you access to the large array of J2SE (or non-Java based) PDF creators and gives you a lot more flexibility of creating this.
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Contributor
Vijay_YD
Posts: 23
Registered: ‎10-20-2011
My Device: Blackberry Z10

Re: Save set of images to pdf file from Java App

Thanks rcmaniac25 !!! will look into it.

Contributor
Vijay_YD
Posts: 23
Registered: ‎10-20-2011
My Device: Blackberry Z10

Re: Save set of images to pdf file from Java App

@peter_strange is your thought is as same as rcmaniac25  as mentioned yesterday ???

 

pls reply 

 

Thanks in Advance

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Save set of images to pdf file from Java App

yes (I predict it)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Save set of images to pdf file from Java App

Simon you know me so well!

 

Actually the response you got was better than I would have given!  

Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: Save set of images to pdf file from Java App

[ Edited ]

After making my post, I wanted to see if I could create a basic application that did this. It took me a little while, but I finally got time to work on it.

 

Go to the following site (it's one of my libraries):

http://bbx.codeplex.com/

 

Choose "source code", then "browse".

 

There is a directory called BBX_PDF. This is a small library for making PDFs. It's very raw. Both in use and in code. There are no real optimizations for speed or memory. To use it, you would pass in specific Hashtable, arrays, and Objects. Then call the write function and it would write the PDF.

 

For the specific thing that you wanted, I made a "builder" class that is avaliable in the "Other" folder within BBX_PDF.

 

It links in with one of my other libraries (BBX), but you can simply remove the preprocessor components to get the generic version of the code.

 

Edit: There is a bug in the Image2PDFBuilder class. When an image is added, it is really small. I am still trying to figure this out myself, but if you happen to figure it out, please post what you fixed so I can update the code.

 

Hope that helps.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Contributor
Vijay_YD
Posts: 23
Registered: ‎10-20-2011
My Device: Blackberry Z10

Re: Save set of images to pdf file from Java App

hi rcmaniac25 ,

 

Ive done the changes mentioned in the document but my question is wer am i getting the pdf file .

 

1) Made changes to code (removed pre-processor components)

2) Added one Bitmap image to res folder and used addimage as

 

Bitmap img = Bitmap.getBitmapResource("img.png");
ipdf.addImage(img);

 

3) if i try to create a file and writes all os stuff from PDF class am able to see all the logs which were added to StringBuffer 

 

and if i try to save os object to file.pdf its showing error "cannot display file" ..

 ill be glad if you help me for further steps.

 

 

Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: Save set of images to pdf file from Java App

I'm not sure I understand #3. You get an image, add it, and tell it to build correct? Do you get an exception or just nothing happens? Is a file produced?
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Contributor
Vijay_YD
Posts: 23
Registered: ‎10-20-2011
My Device: Blackberry Z10

Re: Save set of images to pdf file from Java App

[ Edited ]

these are the steps ive follwed (correct me if am wrong)

 

OutputStream outStream = null;
Image2PDFBuilder ipdf = new Image2PDFBuilder();
Bitmap img = Bitmap.getBitmapResource("img.png");
ipdf.addImage(img);
try
{
FileConnection fc = (FileConnection)Connector.open("file:///store/home/user/newfile.pdf");
// If no exception is thrown, then the URI is valid, but the file may or may not exist.
if (!fc.exists())
{
fc.create(); // create the file if it doesn't exist
}
outStream = fc.openOutputStream();
try {
ipdf.build(outStream);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
outStream.close();
fc.close();
}
catch (IOException ioe)
{
System.out.println(ioe.getMessage() );
}

 

if i create a file newfile.txt then it prints all the Logs which are written but if i create with newfile.pdf then its displaying message after clicking on that file "Unable to Display file ".