Mirko Lugano
Mirko Lugano

Reputation: 985

PDFNet SDK Convert files on Azure storage

I have a web app that needs to convert PDFs to XODs (PDFTron’s format to display documents in their WebViewer). My Web App is hosted on Azure, the PDFs are on Azure Storage. We would like to go along with the on-premises conversion via PDFNet SDK (http://www.pdftron.com/webviewer/getstarted.html, see “Choosing a deployment model for conversions), my code so far is the following:

WebRequest req = HttpWebRequest.Create("url of PDF on Azure Storage here");                         
using (Stream stream = req.GetResponse().GetResponseStream())
{
    PDFDoc pdfdoc = new PDFDoc(stream);
    var converted = pdftron.PDF.Convert.ToXod(pdfdoc);
    //pdfdoc.Save(stream, pdftron.SDF.SDFDoc.SaveOptions.e_linearized); //not clear to me
}

My approach here is to create a stream from the file on azure storage and convert that stream to XOD. I still don’t know if I should call “Save” and in that case where the file would be saved. My questions are:

  1. Since everything runs on the cloud does it make sense to use the CloudAPI instead of the self-hosted solution or does it not make any difference?
  2. In both cases, where is the converted file stored (since I am getting it from the Azure storage and not from a local server), since I would then need to move it to my azure storage account. Does the file get saved locally (meaning on the web/worker role which is processing it) and therefore needs to be moved to the storage?

Here (http://www.pdftron.com/pdfnet/samplecode.html) there are conversion code samples but they all use files on local machine, which would not be my case.

Upvotes: 0

Views: 660

Answers (2)

Mirko Lugano
Mirko Lugano

Reputation: 985

After some extra research I found out I can get and set the Stream of the source and destination files (even if the destination file does not exist yet) directly on Azure without downloading the file. The resulting code is then something like

using (var sourceStream = sourceBlob.OpenRead())
{
    var destinationContainer = BlobClient.GetContainerReference(projectKey);
    var destinationBlob = destinationContainer.GetBlockBlobReference(xodName);
    using (var destinationStream = destinationBlob.OpenWrite())
    {
        var pdfDoc = new PDFDoc(sourceStream);
        pdftron.PDF.Convert.ToXod(pdfDoc);
        pdfDoc.Save(destinationStream, pdftron.SDF.SDFDoc.SaveOptions.e_linearized);
    });
});

Upvotes: 0

user3609640
user3609640

Reputation: 66

Since everything runs on the cloud does it make sense to use the CloudAPI instead of the self-hosted solution or does it not make any difference? In both cases, where is the converted file stored [...]

If you were to go with the cloud solution, you would transfer your files to PDFTron's servers, where they will be converted. Then you would download the converted files.

If you were to go with the on-premises solution, you would need to run DocPub CLI (https://www.pdftron.com/docpub/downloads.html) on your Azure instance, and its only communication with PDFTron would be to increment the billing counter for your PWS account (https://www.pdftron.com/pws/index.html).

You'd have to decide for yourself which solution works best for you.

Here (http://www.pdftron.com/pdfnet/samplecode.html) there are conversion code samples but they all use files on local machine, which would not be my case.

[Note: these samples show how to use the PDFNet SDK to run conversions. To run PDFNet you would need an additional license. So you probably want to use DocPub CLI or the cloud converter instead.]

The samples show how to convert the files locally, since XOD conversion would need to be run server-side. How most people do so is by setting up some web service to upload PDF (or other format) files. Then they convert the documents server-side, and place the converted XOD files someplace where the WebViewer can serve them.

Upvotes: 1

Related Questions