Namespace
Usage
Salesforce supports Blob manipulation only with Apex class methods that are supplied by Salesforce. For more information on Blobs, see Primitive Data Types.
Blob Methods
The following are methods for Blob.
size()
Signature
public Integer size()
Return Value
Type: Integer
Example
String myString = 'StringToBlob'; Blob myBlob = Blob.valueof(myString); Integer size = myBlob.size();
toPdf(stringToConvert)
Signature
public static Blob toPdf(String stringToConvert)
Parameters
-
stringToConvert:
Type: String
Return Value
Type: Blob
Usage
Blob.toPDF(stringToConvert) works with any string value. Since the Spring ’26 release, Blob.toPDF() uses the same PDF rendering service as Visualforce.
See Render a Visualforce Page as a PDF File for details of the improved PDF rendering service, including considerations and limitations for rendering PDF files.
The Visualforce PDF rendering service expands the range of fonts available, and includes a multibyte-capable font. The default font is serif, which is a change from the default sans-serif used by Blob.toPDF(). See Fonts Available When Using Visualforce PDF Rendering.
Example
String pdfContent = 'This is a test string'; Account a = new account(name = 'test'); insert as user a; Attachment attachmentPDF = new Attachment(); attachmentPdf.parentId = a.id; attachmentPdf.name = a.name + '.pdf'; attachmentPdf.body = Blob.toPDF(pdfContent); insert as user attachmentPDF;
toString()
Signature
public String toString()
Return Value
Type: String
Example
String myString = 'StringToBlob'; Blob myBlob = Blob.valueof(myString); Assert.areEqual('StringToBlob', myBlob.toString());