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:
我有一个需要将PDF转换为XOD的Web应用程序(PDFTron的格式在其WebViewer中显示文档)。我的Web应用程序托管在Azure上,PDF文件位于Azure存储上。我们希望通过PDFNet SDK进行内部部署转换(http://www.pdftron.com/webviewer/getstarted.html,请参阅“为转换选择部署模型”),到目前为止,我的代码如下:
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:
我的方法是从azure存储上的文件创建流并将该流转换为XOD。我仍然不知道是否应该调用“保存”,在那种情况下,文件将被保存。我的问题是:
- 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 (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?
由于一切都在云上运行,因此使用CloudAPI而不是自托管解决方案是否有意义,或者它没有任何区别?
在这两种情况下,转换后的文件存储在哪里(因为我是从Azure存储而不是从本地服务器获取的),因为我需要将其移动到我的azure存储帐户。文件是否在本地保存(意味着正在处理它的Web /辅助角色),因此需要将其移动到存储中?
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.
这里(http://www.pdftron.com/pdfnet/samplecode.html)有转换代码示例,但它们都使用本地计算机上的文件,这不是我的情况。
2 个解决方案
#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? In both cases, where is the converted file stored [...]
由于一切都在云上运行,因此使用CloudAPI而不是自托管解决方案是否有意义,或者它没有任何区别?在这两种情况下,转换后的文件存储在哪里[...]
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.
如果您使用云解决方案,则需要将文件传输到PDFTron的服务器,然后转换它们。然后你会下载转换后的文件。
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).
如果您使用本地解决方案,则需要在Azure实例上运行DocPub CLI(https://www.pdftron.com/docpub/downloads.html),并且它与PDFTron的唯一通信将是增加PWS帐户的结算计数器(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.
这里(http://www.pdftron.com/pdfnet/samplecode.html)有转换代码示例,但它们都使用本地计算机上的文件,这不是我的情况。
[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.]
[注意:这些示例显示了如何使用PDFNet SDK运行转换。要运行PDFNet,您需要额外的许可证。所以你可能想要使用DocPub CLI或云转换器。]
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.
这些示例显示了如何在本地转换文件,因为XOD转换需要在服务器端运行。大多数人这样做是通过设置一些Web服务来上传PDF(或其他格式)文件。然后,他们将文档转换为服务器端,并将转换后的XOD文件放置在WebViewer可以为其提供的位置。
#2
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
经过一些额外的研究后,我发现我可以直接在Azure上获取并设置源文件和目标文件的流(即使目标文件尚不存在),而无需下载文件。结果代码就像是
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);
});
});
#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? In both cases, where is the converted file stored [...]
由于一切都在云上运行,因此使用CloudAPI而不是自托管解决方案是否有意义,或者它没有任何区别?在这两种情况下,转换后的文件存储在哪里[...]
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.
如果您使用云解决方案,则需要将文件传输到PDFTron的服务器,然后转换它们。然后你会下载转换后的文件。
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).
如果您使用本地解决方案,则需要在Azure实例上运行DocPub CLI(https://www.pdftron.com/docpub/downloads.html),并且它与PDFTron的唯一通信将是增加PWS帐户的结算计数器(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.
这里(http://www.pdftron.com/pdfnet/samplecode.html)有转换代码示例,但它们都使用本地计算机上的文件,这不是我的情况。
[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.]
[注意:这些示例显示了如何使用PDFNet SDK运行转换。要运行PDFNet,您需要额外的许可证。所以你可能想要使用DocPub CLI或云转换器。]
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.
这些示例显示了如何在本地转换文件,因为XOD转换需要在服务器端运行。大多数人这样做是通过设置一些Web服务来上传PDF(或其他格式)文件。然后,他们将文档转换为服务器端,并将转换后的XOD文件放置在WebViewer可以为其提供的位置。
#2
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
经过一些额外的研究后,我发现我可以直接在Azure上获取并设置源文件和目标文件的流(即使目标文件尚不存在),而无需下载文件。结果代码就像是
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);
});
});