pdf links

PDF Rendering
Convert PDF to Image (.NET)
Convert PDF to image on Android (Xamarin)
Convert PDF to image on iOS (Xamarin)
Convert PDF to image in Windows Store apps (.NET)
Convert PDF to image in Windows Phone apps (.NET)
PDF to image in Universal Windows Store apps (.NET)
Free PDF Viewer control for Windows Forms (.NET)
How to integrate PDF Viewer control in WPF app (.NET)
Creating WPF PDF Viewer supporting bookmarks (.NET)
Cross-platform PDF Viewer using GTK# (MONO)
Silverlight PDF viewer control (Silverlight 5)
Multithreaded PDF rendering (.NET)
Convert pdf to image in Silverlight app (C# sample)
How to set fallback fonts for PDF rendering (C#)
Avoiding the out-of-memory exception on rendering (C#)
PDF viewer single page application (WebAPI, AngularJS)
PDF viewer control for Windows 10 universal applications
Use custom ICC profile for CMYK to RGB conversion
PDF layers - separate images, text, annotations, graphics

PDF Forms Creation PDF Security
Conversion to PDF/A
Other topics
PDF Document Manipulation
PDF Content Generation
Fixed and Flow layout document API (.NET)
Creation of grids and tables in PDF (C# sample)
How to create interactive documents using Actions (C# sample)
Text flow effects in PDF (C# sample)
How to generate ordered and bulleted lists in PDF (C# sample)
Convert HTML to PDF using flow layout API (C# sample)
How to use custom fonts for PDF generation (.NET)
Create document with differently sized pages (C#)
Create PDF documents using MONO (C#/MONO/Windows/OSX)
How to use background images for content elements (C#/PDF Kit/FlowLayout)
Add transparent images to PDF document (C#)
Draw round rect borders in PDF documents(C#)
ICC color profiles and and ICC based colors in PDF (C#)
How to use bidirectional and right to left text in PDF (C#)
Create PDF documents from XML templates (C# sample)
How to resize PDF pages and use custom stamps (C#)
Add header and footer to PDF page (.NET sample)
How to use clipping mask for drawing on PDF page
Fill graphics path with gradient brushes in PDF (Shadings)
Apitron PDF Kit and Rasterizer engine settings
Add layers to PDF page (optional content, C# sample)
How to create free text annotation with custom appearance

PDF Content Extraction
PDF Navigation

PDF to TIFF conversion
Contact us if you have a PDF related question and we'll cover it in our blog.

2014-01-20

Send file via Bluetooth on Windows Phone (C# sample)

While working on our PDF viewer for Windows Phone 8 we stumbled on the pretty simple task, 
that however became not that simple as it seemed from the first glance.

We needed to send a file via Bluetooth, and didn't want to spend much time for it, just call some 
Windows Phone API and get things done. But it wasn't the case.

Apparently MS didn't make this API publicly available (if it exists), and developers are left on their own here. They have created a sample demonstrating how to enumerate paired Bluetooth devices or find devices by services supported using Service Discovery Protocol (SDP). It was quite useful but didn't demonstrate how to send a file, so we decided to go further and solve the puzzle.

MSDN sample says that profiles supported by Windows Phone 8 are:
  • Advanced Audio Distribution Profile (A2DP 1.2)
  • Audio/Video Remote Control Profile (AVRCP 1.4
  • Hands Free Profile (HFP 1.5)
  • Phone Book Access Profile (PBAP 1.1)
  • Object Push Profile (OPP 1.1)
  • Out of Band (OOB) and Near Field Communications (NFC)

Object Push Profile exists for a while and can be used for data exchange, it's based on OBEX protocol and many devices support it (for sure there're exclusions e.g. iPhone).
In order to send the file to other Bluetooth-enabled devices we would need to implement an OBEX OPP client, so we did.

Our implementation is based on IrOBEX spec v.1.3, that can be found by googling around. Other docs can be read as well, like Bluetooth spec (for OBEX FTP details)and various articles on the net.

So the code. We've implemented a simple class called BluetoothManager in C# that handles the sending task.Your app will need ID_CAP_PROXIMITY and ID_CAP_NETWORKING capabilities set.

I. Enumerating Bluetooth devices on Windows Phone

try
{    // look for paired devices and update our listbox
    PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";
    IReadOnlyList<PeerInformation> result = await PeerFinder.FindAllPeersAsync();

    for (int i=0;i<result.Count;++i)
    {
       bluetoothDevices.Insert(i, result[i]);
    }
}

catch (Exception ex)
{
    // suggested by MS sample, handles BT radio off case
    if ((uint)ex.HResult == 0x8007048F)
    {
       MessageBox.Show(AppResources.BluetoothIsOffMessageText,       AppResources.AppMessageErrorCaption, MessageBoxButton.OK);
    }
}
   

II. Connecting and sending

using (BluetoothManager manager = new BluetoothManager(item))

{                       

    StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets//hello.txt"));
    if (!await manager.SendFile(file,"hello.txt",BluetoothProfile.OBEXOPP, OnTransferProgress))

    {

        MessageBox.Show(AppResources.BluetoothSendFailed, AppResources.AppMessageErrorCaption, MessageBoxButton.OK);

    }
}
 
One interesting thing regarding the OBEX OPP support by various devices is that we were able to get proper response packet from other Windows Phone devices, while not all Android devices responded properly.So we created a workaround for this behavior.

The complete code sample that includes OBEX OPP implementation needed for outgoing transfer is available for download, it's a Windows Phone App that enumerates paired devices and sends a simple file from its Assets. Here are a few screenshots.

   



We hope someone will find this code useful and we would appreciate your comments and suggestions.