Barcode

The feature lets you create and read the most common standard barcode types.

FeatureParameterResponseActionDescriptionLinks
readBarcodesReadBarcodesReadBarcodesResReadBarcodeAction Reads barcode and decrypts data.swagger
sample
readBarcodesByTypesfile[file stream]
Reads barcode by the types supported
swagger
sample
createBarcodesByTypesfile [file stream] Creates barcodes in supported types
swagger
sample
splitByBarcode string, file [file stream] SplitByBarcodeAction Splits pages of a document based on the text inside barcodeswagger
sample

Samples

ReadBarcodes

  • curl
  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
curl No Sample
// create readbarcodes object
var req = new ReadBarcodes()
    {
        // document
        Document = new Document()
        {
            DocData = File.ReadAllBytes("myPdf.pdf")
        },
        // action
        ReadBarcodeAction = new ReadBarcodeAction()
        {
        },
    };
    
// reading barcode from PDF
var res = Pdf4me.Instance.PdfAClient.ProtectAsync(req).GetAwaiter().GetResult();
            
// extracting the text and writing it to disk
string barcodeString = res.Barcodes.FirstOrDefault().BarcodeData;
File.WriteAllBytes("barcodeString.txt", barcodeString);
 // create readbarcodes object
 $create_barcode = [
    // document
    "document"=> [
        "name"=> "myPdf.pdf",
        "docData" => $pdf4meclient->getFileData('myPdf.pdf')
    ],
    // action
    "readBarcodesAction" => [
    ]
];

// create the barcode object
$res = $client->pdf4me()->readBarcodes($create_barcode);

// extracting the barcode text
$barcode_text = base64_decode($res->barcodes[0]->barcodeData);
// and writing it to file
file_put_contents('barcodeString.txt', $barcode_text);
# setup the barcode_client
barcode_client = BarcodeClient(pdf4me_client)

# create the barcode object
read_barcodes = ReadBarcodes(
    # document
    document=Document(
        doc_data=FileReader().get_file_data('mypdf.pdf')
    ),
    # action
    read_barcode_action=ReadBarcodeAction(
    )
)

# reading barcode from PDF
res = barcode_client.read_barcodes(read_barcodes=read_barcodes)

# extract the text and writing it to disk
barcode_text = base64.b64decode(res['barcodes'][0]['barcode_data'])
with open('barcodeString.txt', 'wb') as f:
    f.write(barcode_text)

ReadBarcodesByTypes

  • curl
  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
curl No Sample
// reading barcode
var res = Pdf4me.Instance.BarcodeClient.ReadBarcodesByTypeAsync(File.ReadAllBytes("myPdf.pdf"), BarcodeType.All).ConfigureAwait(false).GetAwaiter().GetResult();

// extract the text and writing it to disk
string barcodeData = res.Barcodes.FirstOrDefault().BarcodeData;
File.WriteAllBytes("barcodeString.txt", barcodeData);
// reading barcode
$res = $client->pdf4me()->readBarcodesByType(
        [
            "barcodeType" => "all",
            "file" => 'myPdf.pdf'
        ]);
        
//writing it to file
$barcodeData = base64_decode($res['barcodes'][0]['barcodeData']);
file_put_contents('barcodeString.txt', $barcodeData);
# setup the barcode_client
barcode_client = BarcodeClient(pdf4me_client)

# reading the PDF
res = barcode_client.read_barcodes_by_type(
        barcode_type='all',
        file=FileReader().get_file_handler(path='myPdf.pdf')
    )
    
# extract the text
barcodeData = base64.b64decode(res['barcodes'][0]['barcode_data']);
# writing the generated text to disk
with open('barcodeString.txt', 'wb') as f:
    f.write(barcodeData)

CreateBarcodesByTypes

  • curl
  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
curl https://api.pdf4me.com/Barcode/CreateBarcodeByType ^
-H "Authorization: Basic DEV-KEY" ^
-F barcodType=qrcode ^
-F content=example_text ^
-o ./createBarcode.jpg
// creating barcode from text
var res = Pdf4me.Instance.BarcodeClient.CreateBarcodeByTypeAsync(BarcodType.QrCode, "example text", null).ConfigureAwait(false).GetAwaiter().GetResult();

// writing generated image to disk
using (var resfile = System.IO.File.OpenWrite('createBarcode.jpg'))
{
    res.Stream.CopyTo(resfile);
}
// creating barcode from text
$res = $client->pdf4me()->createBarcodeByType([
        "barcodType" => "qrCode",
        "content" => 'example text'
    ]);

// writing generated image to disk    
file_put_contents('createBarcode.jpg', $res);
# setup the barcode_client
barcode_client = BarcodeClient(pdf4me_client)

# reading the PDF
res = barcode_client.create_barcode_by_type(
        barcode_type='qrcode',
        content='example text'
    )

# writing the generated PDF to disk
with open('createBarcode.jpg', 'wb') as f:
    f.write(res)

SplitByBarcode

  • curl
  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
curl 
var splitByBarcodeReq = new SplitByBarcodeReq()
{
    Document = new Document
    {
        DocData = File.ReadAllBytes("mypdf.pdf")
    },
    SplitByBarcodeAction = new SplitByBarcodeAction
    {
        BarcodeString = "ara",
        BarcodeFilter = SplitByBarcodeActionBarcodeFilter.StartsWith,
        BarcodeType = SplitByBarcodeActionBarcodeType.Any,
        SplitBarcodePage = SplitByBarcodeActionSplitBarcodePage.Before
    }
};

var res = await Pdf4me.Instance.BarcodeClient.SplitByBarcodeAsync(splitByBarcodeReq).ConfigureAwait(false);

int i = 0;
foreach (var doc in res.SplittedDocuments)
    File.WriteAllBytes("pdf_" + i + ".pdf", doc.DocData);

Models

ReadBarcodes

Name Type Description Notes
document Document
readBarcodesAction ReadBarcodeAction
jobId String [optional]
jobIdExtern String [optional]
integrations [String] [optional]

ReadBarcodesRes

Name Type Description Notes
barcodes [ScanBarcode] Barcode data
inDocMetadata [DocMetadata] Document data.

ReadBarcodeAction

Name Type Description Notes
barcodeTypes Enum Types of Barcode. Supported Values:
all, unknown, code11, code39, code93, code128, codabar, inter2of5, patchCode, ean8, upce, ean13, upca, plus2, plus5, pdf417, dataMatrix, qrCode, postnet, planet, rm4SCC, australiaPost, intelligentMail, code39Extended, microQRCode, all_2D, pharmaCode, ucc128, rss14, rssLimited, rssExpanded, all_1
[Optional]
barcodeOrientation Enum Supported Values:
unknown, leftToRight, rightToLeft, topToBottom, bottomToTop, all
[Optional]
barcodesToRead Integer [Optional]
scanInterval Integer [Optional]
quietZoneSize Enum Supported Values
extraSmall, small, normal, large
[Optional]
pdfReadingType Enum Supported Values
render, images
[Optional]
pdfRenderDPI Integer [Optional]
thresholdMode Enum Supported Values
automatic, fixed, multiple, adaptive
[Optional]
thresholdCount Integer [Optional]
thresholdStep Integer [Optional]
scanPage Integer [Optional]
i2of5Checksum boolean [Optional]
code11Checksum boolean [Optional]
code39Checksum boolean [Optional]
code93Checksum boolean [Optional]
imageDespeckle Integer [Optional]
imageErode Integer [Optional]
imageDilate Integer [Optional]
imageSharp Integer [Optional]
imageInvert Integer [Optional]

SplitByBarcode

Name Type Description Notes
document Document
splitByBarcodeAction SplitByBarcodeAction
ipAddress String [optional]
jobId String [optional]
jobIdExt String [optional]
integrations [String] [optional]

SplitByBarcodeAction

Name Type Description Notes
barcodeString string Text to search inside barcode [Optional]
barcodeFilter Enum [startsWith, endsWith, contains, exact]
barcodeType Enum Barcode type [ any, datamatrix, qrcode ]
splitBarcodePage Enum Specify page order to split [ before, after, remove ]
actionId string

Document

Name Type Description Notes
jobId String JobId of Documents WorkingSet.
documentId String Document Id
name String Filename inlcuding filetype.
docStatus String Status of the Document, e.g. Stamped.
pages Page Description of pages.
docData [byte] Document bytes.
docMetadata DocMetadata Document metadata such as title, pageCount et al.
docLogs DocLog Logging information about the request, e.g. timestamp.

Page

Name Type Description Notes
documentId String Globally unique Id.
pageId String Globally unique Id.
pageNumber Integer PageNumber, starting with 1.
rotate double By how much the page was rotated from its original orientation.
thumbnail byte Thumbnail representing this particular page.
sourceDocumentId String Id of the document it was created from, e.g. in case of an extraction, the result's sourceDocumentId is the Id of the PDF the pages have been extracted from.
sourcePageNumber Integer Page number of the original page in the original document, e.g. let's assume document B consists of page number 4 of document A (extraction).
Thus, document B's only page's sourcePageNumber is number 4.

DocMetadata

Name Type Description Notes
title String Title of document.
subject String Subject of document.
pageCount long Number of pages.
size long Number bytes of the document.
isEncrypted boolean If the document is Encrypted
pdfCompliance String Pdf Compliance, e.g. PDF/A.
isSigned boolean If the document is Encrypted
uploadedMimeType String Uploaded MimeType, e.g. application/bson.
uploadedFileSize long Uploaded file size.

DocLog

Name Type Description Notes
messageType String MessageType, e.g. PdfALog.
message String Message itself, e.g. a warning.
timestamp dateTime Timestamp.
docLogLevel String Type of message. Supported Values :
"verbose", "info", "warning", "error", "timing"
durationMilliseconds long Timing for requested log information [ms].

ScanBarcode

Name Type Description Notes
barcodeDataType String [Optional]
barcodeType Enum Types of Barcode. Supported Values:
all, unknown, code11, code39, code93, code128, codabar, inter2of5, patchCode, ean8, upce, ean13, upca, plus2, plus5, pdf417, dataMatrix, qrCode, postnet, planet, rm4SCC, australiaPost, intelligentMail, code39Extended, microQRCode, all_2D, pharmaCode, ucc128, rss14, rssLimited, rssExpanded, all_1
[Optional]
barcodeDataLen Integer [Optional]
angle String [Optional]
borderEndX1 Integer [Optional]
borderEndX2 Integer [Optional]
borderEndY1 Integer [Optional]
borderEndY2 Integer [Optional]
borderStartX1 Integer [Optional]
borderStartX2 Integer [Optional]
borderStartY1 Integer [Optional]
borderStartY2 Integer [Optional]
top Integer [Optional]
left Integer [Optional]
bottom Integer [Optional]
boundingRectangle ValueType [Optional]
checksum Integer [Optional]
rssExpandedStacked Integer [Optional]
type Enum Supported Values:
all, unknown, code11, code39, code93, code128, codabar, inter2of5, patchCode, ean8, upce, ean13, upca, plus2, plus5, pdf417, dataMatrix, qrCode, postnet, planet, rm4SCC, australiaPost, intelligentMail, code39Extended, microQRCode, all_2D, pharmaCode, ucc128, rss14, rssLimited, rssExpanded, all_1
[Optional]
threshold Integer [Optional]
page Integer [Optional]
orientationString String [Optional]
orientation Enum Supported Values:
unknown, leftToRight, rightToLeft, topToBottom, bottomToTop, all
[Optional]
barcodeInfoString String [Optional]
barcodeData String [Optional]
qrVersion Integer [Optional]
numErrorsCorrected Integer [Optional]
dim2 Integer [Optional]
dim1 Integer [Optional]
dataMatrix_NumErrorsCorrected Integer [Optional]
dataMatrix_Dim2 Integer [Optional]
dataMatrix_Dim1 Integer [Optional]
errorCorrectionLevel Integer [Optional]
barcodeString String [Optional]

DocMetadata

Name Type Description Notes
title String Title of document.
subject String Subject of document.
pageCount long Number of pages.
size long Number bytes of the document.
isEncrypted boolean If the document is Encrypted
pdfCompliance String Pdf Compliance, e.g. PDF/A.
isSigned boolean If the document is Encrypted
uploadedMimeType String Uploaded MimeType, e.g. application/bson.
uploadedFileSize long Uploaded file size.

ValueType

Name Type Description Notes

How can we help?