vCard, also known as VCF (Virtual Contact File), is a file format standard for electronic business cards. vCards are often attached to e-mail messages, but can be exchanged in other ways. They can contain name and address information, telephone numbers, e-mail addresses, URLs, logos, photographs, and even audio clips.
To access Metadata in a vCard, GroupDocs.Metadata API provides the VCardRootPackage.getVCardPackagemethod which contains the information extracted from a file. The following are the steps to access metadata in a vCard:
try(Metadatametadata=newMetadata(Constants.InputVcf)){VCardRootPackageroot=metadata.getRootPackageGeneric();for(VCardCardvCard:root.getVCardPackage().getCards()){if(vCard.getIdentificationRecordset().getPhotoUriRecords()!=null){// Iterate all photos represented by URIsfor(VCardTextRecordphotoUriRecord:vCard.getIdentificationRecordset().getPhotoUriRecords()){// Print the property valueSystem.out.println(photoUriRecord.getValue());// Print some additional parameters of the propertySystem.out.println(photoUriRecord.getContentType());System.out.println(photoUriRecord.getMediaTypeParameter());if(photoUriRecord.getTypeParameters()!=null){for(Stringparameter:photoUriRecord.getTypeParameters()){System.out.println(parameter);}}System.out.println(photoUriRecord.getPrefParameter());}}}}
Filtering vCard properties
The GroupDocs.Metadata API provides the ability to filter vCard properties in order to make finding desired information easier. The code sample below demonstrates how to use the filtering feature.
publicstaticvoidrun(){try(Metadatametadata=newMetadata(Constants.InputVcf)){VCardRootPackageroot=metadata.getRootPackageGeneric();for(VCardCardvCard:root.getVCardPackage().getCards()){// Print most preferred work phone numbers and work emailsVCardCardfiltered=vCard.filterWorkTags().filterPreferred();PrintArray(filtered.getCommunicationRecordset().getTelephones());PrintArray(filtered.getCommunicationRecordset().getEmails());}}}privatestaticvoidPrintArray(String[]values){if(values!=null){for(Stringvalue:values){System.out.println(value);}}}
More resources
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples: