PDFNet SDK 转换 Azure 存储上的文件
PDFNet SDK Convert files on Azure storage
我有一个网络应用程序需要将 PDF 转换为 XOD(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
}
我的方法是从 Azure 存储上的文件创建流并将该流转换为 XOD。我仍然不知道我是否应该调用“保存”以及在那种情况下文件将保存在哪里。
我的问题是:
- 既然一切都在云上运行,那么使用 CloudAPI 而不是自托管解决方案是否有意义,还是没有任何区别?
- 在这两种情况下,转换后的文件存储在哪里(因为我是从 Azure 存储而不是从本地服务器获取它),因为我需要将它移动到我的 azure 存储帐户。文件是否保存在本地(意味着正在处理它的 web/worker 角色)因此需要移动到存储?
这里 (http://www.pdftron.com/pdfnet/samplecode.html) 有转换代码示例,但它们都使用本地计算机上的文件,这不是我的情况。
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 [...]
如果您要使用云解决方案,您可以将文件传输到 PDFTron 的服务器,在那里它们将被转换。然后你会下载转换后的文件。
如果您要使用本地解决方案,则需要 运行 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)。
您必须自己决定哪种解决方案最适合您。
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.
[注意:这些示例展示了如何使用 PDFNet SDK 进行 运行 转换。要 运行 PDFNet,您需要额外的许可证。所以您可能想改用 DocPub CLI 或云转换器。]
示例显示了如何在本地转换文件,因为 XOD 转换需要在 运行 服务器端进行。大多数人这样做的方式是设置一些网络服务来上传 PDF(或其他格式)文件。然后他们在服务器端转换文档,并将转换后的 XOD 文件放在 WebViewer 可以提供它们的地方。
经过一些额外的研究,我发现我可以直接在 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);
});
});
我有一个网络应用程序需要将 PDF 转换为 XOD(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
}
我的方法是从 Azure 存储上的文件创建流并将该流转换为 XOD。我仍然不知道我是否应该调用“保存”以及在那种情况下文件将保存在哪里。 我的问题是:
- 既然一切都在云上运行,那么使用 CloudAPI 而不是自托管解决方案是否有意义,还是没有任何区别?
- 在这两种情况下,转换后的文件存储在哪里(因为我是从 Azure 存储而不是从本地服务器获取它),因为我需要将它移动到我的 azure 存储帐户。文件是否保存在本地(意味着正在处理它的 web/worker 角色)因此需要移动到存储?
这里 (http://www.pdftron.com/pdfnet/samplecode.html) 有转换代码示例,但它们都使用本地计算机上的文件,这不是我的情况。
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 [...]
如果您要使用云解决方案,您可以将文件传输到 PDFTron 的服务器,在那里它们将被转换。然后你会下载转换后的文件。
如果您要使用本地解决方案,则需要 运行 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)。
您必须自己决定哪种解决方案最适合您。
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.
[注意:这些示例展示了如何使用 PDFNet SDK 进行 运行 转换。要 运行 PDFNet,您需要额外的许可证。所以您可能想改用 DocPub CLI 或云转换器。]
示例显示了如何在本地转换文件,因为 XOD 转换需要在 运行 服务器端进行。大多数人这样做的方式是设置一些网络服务来上传 PDF(或其他格式)文件。然后他们在服务器端转换文档,并将转换后的 XOD 文件放在 WebViewer 可以提供它们的地方。
经过一些额外的研究,我发现我可以直接在 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);
});
});