Adding Image to new PDF - RadaeePDF.com
Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
13 Jul 2017
Microsoft has ended support for Windows Phone 8.1
Read More...
Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC: Adding Image to new PDF

Adding Image to new PDF 1 year 8 months ago #12074

  • TeleSon
  • TeleSon's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 0
Hi, I need to save some pictures to new PDF. This script bellow create new PDF file, but without images. I have seen your example here in docs. it the same code, what i do wrong? or is it a bug. I use the radaee version 3.11 for android.
Thanks for answer.
B.r. Tom
Document pdf_doc = new Document();
pdf_doc.Create(Environment.getExternalStorageDirectory() + getString(R.string.teli_dir) + "/test.pdf");
int page_no = 1;
for (File f: allFiles) {
if (f.getName().contains("jpg")){
Page page = pdf_doc.NewPage(page_no++,210,297);

BitmapFactory.Options bmpOptions = new BitmapFactory.Options();
bmpOptions.inJustDecodeBounds = true;
bmp = BitmapFactory.decodeFile(f.getAbsolutePath(), bmpOptions);
PageContent pageContent = new PageContent();
pageContent.Create();
pageContent.GSSave();
com.radaee.pdf.Matrix mat = new com.radaee.pdf.Matrix(250, 250, 0, 0);
pageContent.GSSave();
pageContent.GSSetMatrix(mat);
Document.DocImage docimage = pdf_doc.NewImage(bmp, true);
ResImage rimage = page.AddResImage(docimage);
pageContent.GSSave();
mat.Destroy();
pageContent.DrawImage(rimage);
pageContent.GSRestore();
page.AddContent(pageContent, false);
pageContent.Destroy();
page.Close();
}
}
pdf_doc.Save();
pdf_doc.Close();

Please Log in or Create an account to join the conversation.

Adding Image to new PDF 1 year 8 months ago #12075

  • nermeen
  • nermeen's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 865
  • Karma: 23
  • Thank you received: 70
Dear Tom,
Make sure to call SetCache after Create:
pdf_doc.Create(Environment.getExternalStorageDirectory() + getString(R.string.teli_dir) + "/test.pdf");
pdf_doc.SetCache( Global.tmp_path + "/temp.dat" );//set temporary cache for editing.

For a working example, please check PDFTestAct

Please Log in or Create an account to join the conversation.

Adding Image to new PDF 1 year 8 months ago #12076

  • TeleSon
  • TeleSon's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 0
I tried it now, but it's not working too.

Please Log in or Create an account to join the conversation.

Last edit: by TeleSon.

Adding Image to new PDF 1 year 8 months ago #12081

  • nermeen
  • nermeen's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 865
  • Karma: 23
  • Thank you received: 70
Dear Tom,

We have tested your code, after substituting the bitmap with one of ours and it's working.

So make sure that your bmp is not null and is created correctly. (below the code we used for testing)
Document pdf_doc = new Document();
pdf_doc.Create(Environment.getExternalStorageDirectory() + getString(R.string.teli_dir) + "/test.pdf");
pdf_doc.SetCache( Global.tmp_path + "/temp.dat" );//set temporary cache for editing.
int page_no = 1;
//for (File f: allFiles) {
//if (f.getName().contains("jpg")){
Page page = pdf_doc.NewPage(page_no++,210,297);

//BitmapFactory.Options bmpOptions = new BitmapFactory.Options();
//bmpOptions.inJustDecodeBounds = true;
//bmp = BitmapFactory.decodeFile(f.getAbsolutePath(), bmpOptions);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pdf_custom_stamp);
PageContent pageContent = new PageContent();
pageContent.Create();
pageContent.GSSave();
com.radaee.pdf.Matrix mat = new com.radaee.pdf.Matrix(250, 250, 0, 0);
//pageContent.GSSave();
pageContent.GSSetMatrix(mat);
Document.DocImage docimage = pdf_doc.NewImage(bmp, true);
ResImage rimage = page.AddResImage(docimage);
//pageContent.GSSave();
mat.Destroy();
pageContent.DrawImage(rimage);
pageContent.GSRestore();
page.AddContent(pageContent, false);
pageContent.Destroy();
page.Close();
//}
//}
pdf_doc.Save();
pdf_doc.Close();
The following user(s) said Thank You: TeleSon

Please Log in or Create an account to join the conversation.

Adding Image to new PDF 1 year 7 months ago #12092

  • TeleSon
  • TeleSon's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 0
Dear nermeen,
i made a preview of pictures in the view, then taken the same picture load function from files for add to PDF, but the bmp was null.
Thank you :)

Please Log in or Create an account to join the conversation.

Adding Image to new PDF 1 year 7 months ago #12207

  • TeleSon
  • TeleSon's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 0
hi, i have now a problem, that the pdf with f.e. 4 images have 27MB, how can i reduce the size? :) i have try it some experiments with com.radaee.pdf.Matrix, but without success.
Could me someone help? Thanks

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Powered by Kunena Forum