Documentation for creating files in PDF format

5

I have been analyzing free libraries for the creation of PDFs for use in commercial applications on Android, and so far I have not found any that meet all my expectations, features and licenses. As can be seen this and in this question right here in SOpt.

The best library I've found so far has been Android PDF Writer , which has the ability to create basic PDF and has a license ( BSD) appropriate for my project, as per in this great software license post .

Although doing a lot of things related to PDF, it was designed only for simple PDF creation, with texts and images.

So I would like to know / find some logic documentation to create a PDF, so I can add resources to the library?

As an example of the code of the cited library, to add text to the PDF is implemented in this way:

public void addText(int leftPosition, int topPositionFromBottom, int fontSize, String text, String transformation) {
    addContent(
        "BT\n" +
        transformation + " " + Integer.toString(leftPosition) + " " + Integer.toString(topPositionFromBottom) + " Tm\n" +
        "/F" + Integer.toString(mPageFonts.size()) + " " + Integer.toString(fontSize) + " Tf\n" +
        "(" + text + ") Tj\n" +
        "ET\n"
    );
}

The first implementation I'm intending is to create tables where the only documentation I've found so far has been this , which I could not understand completely, and would like something more detailed, for example: table structure, structure of the columns, structure of the columns, structure of the lines, structure of the items. To understand and be able to implement each part of the table as a module.

    
asked by anonymous 27.08.2015 / 16:52

1 answer

-1

Good friend, check if this might help you:
one method is for you to create and another is for you to open. follow the link too. link


 public void createPDF()
 {
  Document doc = new Document();

  try {
   String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/PDF";

   File dir = new File(path);
   if(!dir.exists())
    dir.mkdirs();

   Log.d("PDFCreator", "PDF Path: " + path);

   File file = new File(dir, "demo.pdf");
   FileOutputStream fOut = new FileOutputStream(file);

   PdfWriter.getInstance(doc, fOut);

   //open the document
   doc.open();

   /* Create Paragraph and Set Font */
   Paragraph p1 = new Paragraph("Hi! I am Generating my first PDF using DroidText");

   /* Create Set Font and its Size */
   Font paraFont= new Font(Font.HELVETICA);
   paraFont.setSize(16);
   p1.setAlignment(Paragraph.ALIGN_CENTER);
   p1.setFont(paraFont);

   //add paragraph to document    
   doc.add(p1);


   Paragraph p2 = new Paragraph("This is an example of a simple paragraph");

  /* You can also SET FONT and SIZE like this */
   Font paraFont2= new Font(Font.COURIER,14.0f,Color.GREEN);
   p2.setAlignment(Paragraph.ALIGN_CENTER);
   p2.setFont(paraFont2);

   doc.add(p2);

   /* Inserting Image in PDF */
   ByteArrayOutputStream stream = new ByteArrayOutputStream();
   Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.android);
   bitmap.compress(Bitmap.CompressFormat.JPEG, 100 , stream);
   Image myImg = Image.getInstance(stream.toByteArray());
   myImg.setAlignment(Image.MIDDLE);

   //add image to document
   doc.add(myImg);

   //set footer
   Phrase footerText = new Phrase("This is an example of a footer");
   HeaderFooter pdfFooter = new HeaderFooter(footerText, false);
   doc.setFooter(pdfFooter);

   Toast.makeText(getApplicationContext(), "Created...", Toast.LENGTH_LONG).show();

  } catch (DocumentException de) {
   Log.e("PDFCreator", "DocumentException:" + de);
  } catch (IOException e) {
   Log.e("PDFCreator", "ioException:" + e);
  } 
  finally
  {
   doc.close();
  }
 }      

 void openPdf()
 {
  Intent intent = new Intent(Intent.ACTION_VIEW);
  String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/PDF";

  File file = new File(path, "demo.pdf");

  intent.setDataAndType( Uri.fromFile( file ), "application/pdf" );
     startActivity(intent);
 }

    
27.08.2015 / 19:54