---
schema_version: "1"
id: e0dab39698610cd6ed4c3d1190c7ac22e53bdd0cc5a34d9f3fcdf8188c1f9764
title: Blob Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_methods_system_blob.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_blob.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: e9f71c8b4edcd8689477fa8d71036d26acd43be1f362a69d1a0ae01dba38dc3a
description: Contains methods for the Blob primitive data type.Returns the number of bytes in the Blob.Creates a binary object out of the given string, encoding it as a PDF file. Casts the Blob into a String.Casts the specified String to a Blob.
---
# Blob Class

Contains methods for the Blob primitive data type.

## Namespace

[System](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_System.htm "The System namespace provides classes and methods for core Apex functionality.")

## Usage

Salesforce supports Blob manipulation only with Apex class methods that are supplied by Salesforce. For more information on Blobs, see [Primitive Data Types](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/langCon_apex_primitives.htm).

## Blob Methods

The following are methods for Blob.

- **[size()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_blob.htm#apex_System_Blob_size)**  
    Returns the number of bytes in the Blob.
- **[toPdf(stringToConvert)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_blob.htm#apex_System_Blob_toPdf)**  
    Creates a binary object out of the given string, encoding it as a PDF file.
- **[toString()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_blob.htm#apex_System_Blob_toString)**  
    Casts the Blob into a String.
- **[valueOf(stringToBlob)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_blob.htm#apex_System_Blob_valueOf)**  
    Casts the specified String to a Blob.

### size()

Returns the number of bytes in the Blob.

#### Signature

public Integer size()

#### Return Value

Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")

#### Example

String myString = 'StringToBlob';
Blob myBlob = Blob.valueof(myString);
Integer size = myBlob.size();

### toPdf(stringToConvert)

Creates a binary object out of the given string, encoding it as a PDF file.

#### Signature

public static Blob toPdf(String stringToConvert)

#### Parameters

- **stringToConvert**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

#### Return Value

Type: [Blob](#apex_methods_system_blob "Contains methods for the Blob primitive data type.")

#### 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](https://developer.salesforce.com/docs/atlas.en-us.264.0.pages.meta/pages/pages_output_pdf_renderas.htm "html (New Window)") 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](https://developer.salesforce.com/docs/atlas.en-us.264.0.pages.meta/pages/pages_output_pdf_supported_fonts.htm).

#### 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()

Casts the Blob into a String.

#### Signature

public String toString()

#### Return Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

#### Example

String myString = 'StringToBlob';
Blob myBlob = Blob.valueof(myString);
Assert.areEqual('StringToBlob', myBlob.toString());

### valueOf(stringToBlob)

Casts the specified String to a Blob.

#### Signature

public static Blob valueOf(String stringToBlob)

#### Parameters

- **stringToBlob**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

#### Return Value

Type: [Blob](#apex_methods_system_blob "Contains methods for the Blob primitive data type.")

#### Example

String myString = 'StringToBlob';
Blob myBlob = Blob.valueof(myString);