You can use a specially-encoded PDF file for an invoice (through the Invoice object's Body field). Once you add the invoice in the system, you can query on that field. This use case provides information about this procedure.
The body of an invoice is a PDF file encoded using Base64 encoding. Once the body is queried, you need to unencode it using a standard Base64 utility.
To query an Invoice object's Body field,
The following is an example of querying Body from the Invoice object:
SELECT Id, AccountId, Amount, Balance, DueDate, InvoiceDate, InvoiceNumber, Status, TargetDate, Body FROM Invoice WHERE id='someInvoiceId'
The query will work only if a single row is returned. If more than one row matches the WHERE clause, the system will generate an error.
Invoice in = query("select Id, AccountId, Amount, Balance, DueDate, InvoiceDate, InvoiceNumber, Status, TargetDate, Body from Invoice where id='someInvoiceId'"); String str = in.getBody(); byte b = Base64.decodeBase64(str.getBytes()); File file = new File(in.getInvoiceNumber()+".pdf"); if (!file.exists()) file.createNewFile(); FileOutputStream out = new FileOutputStream(file); out.write(b);