Microsoft Windows Phone 8.1 support ends (13 Jul 2017)

Microsoft has ended support for Windows Phone 8.1

Questions about Android development and PDF

Adding Image to new PDF

More
IP: 192.168.0.71 9 years 3 weeks ago #12074 by TeleSon
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
Code:
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();
More
IP: 192.168.0.71 9 years 3 weeks ago #12075 by nermeen
Replied by nermeen on topic Adding Image to new PDF
Dear Tom,
Make sure to call SetCache after Create:
Code:
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
More
IP: 192.168.0.71 9 years 3 weeks ago - 9 years 3 weeks ago #12076 by TeleSon
Replied by TeleSon on topic Adding Image to new PDF
I tried it now, but it's not working too.
Last edit: 9 years 3 weeks ago by TeleSon.
More
IP: 192.168.0.71 9 years 3 weeks ago #12081 by nermeen
Replied by nermeen on topic Adding Image to new PDF
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)
Code:
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();
More
IP: 192.168.0.71 9 years 2 weeks ago #12092 by TeleSon
Replied by TeleSon on topic Adding Image to new PDF
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 :)
More
IP: 192.168.0.71 8 years 11 months ago #12207 by TeleSon
Replied by TeleSon on topic Adding Image to new PDF
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
Time to create page: 0.423 seconds
Powered by Kunena Forum