I am reading file docx from azure blob and then with below code converting it to pdf:, pdf is created but not opening.
error while opening pdf file:
We can’t open this file
Something went wrong.
var convertRequest = new ConvertDocumentRequest(_documentOperationService.GetFileByUrl(outputfilepath), “pdf”);
var pdffile= wordsApi.ConvertDocument(convertRequest).Result;
IFormFile pdfile = new FormFile(pdffile, 0, a.Document.First().Value.Length, “name”, newFileName.Replace(“docx”,“pdf”));
_documentOperationService.Upload(libraryName, pdfile);
I am afraid it is difficult to comment on the issue without reproducing it at our end. You may please double check that the input document is a valid DOCX and save the output PDF to your local drive. Hopefully, it will help you identify the issue.
var requestDocument = File.OpenRead(localFile);
var convertRequest = new ConvertDocumentRequest(requestDocument, "pdf");
var actual = await wordsApi.ConvertDocument(convertRequest);
var fileStream = System.IO.File.Create(@"C:\Temp\Output.pdf");
actual.CopyTo(fileStream);
fileStream.Close();
Fist I used merge method of aspose to merge the document and then upload it to blob. tilll here its working fine, merged word file is also created .
No with url of blob I am reading the word file and getting stream with below method;
public Stream GetFileByUrl(string url)
{
BlobContainerClient blobContainerClient = new BlobContainerClient(_storageconnectionstring, _blobName);
url = Bloburl;
BlobClient blobClientsourcePath = blobContainerClient.GetBlobClient(url);
var stream = blobClientsourcePath.OpenRead();
return stream;
}
now this stream i am passing to create pdf::
var convertRequest = new ConvertDocumentRequest(stream, “pdf”);
var pdffile= wordsApi.ConvertDocument(convertRequest).Result;
IFormFile pdfile = new FormFile(pdffile, 0, a.Document.First().Value.Length, “name”,
then upoading again to blob:
_documentOperationService.Upload(libraryName, pdfile);
If i try converting same merged file from any other online word to pdf converter it working fine. so the merged word file is good. please check my code for converting to pdf or reading word file into stream before converting has any issue.
I am afraid I cannot test your code. However, can you please share your workflow and which API methods you are using for mail merge? I will guide you accordingly.
public Stream GetFileByUrl(string url)
{
BlobContainerClient blobContainerClient = new BlobContainerClient(_storageconnectionstring, _blobName);
url = url.Replace(“https://***.blob.core.windows.net/root/”, String.Empty);
BlobClient blobClientsourcePath = blobContainerClient.GetBlobClient(url);
var stream = blobClientsourcePath.OpenRead();
return stream;
}
code to convert to pdf:
WordsApi wordsApi = new WordsApi("**-b3ac", "");
var ob = _documentOperationService.GetFileByUrl(filepath);–as above method code
var convertRequest = new ConvertDocumentRequest(ob, “pdf”);–aspose api for convert
var pdffile= wordsApi.ConvertDocument(convertRequest).Result;–aspose api method
IFormFile pdfile = new FormFile(pdffile, 0, ob.Length, "name", newFileName.Replace("docx","pdf")); --convert doc to formfile and upload to azure
_documentOperationService.Upload(libraryName, pdfile);
As suggested above, please save your resultant PDF to your local drive before uploading to Azure to double check that the output is not corrupt.
var actual = await wordsApi.ConvertDocument(convertRequest);
var fileStream = System.IO.File.Create(@"C:\Temp\Output.pdf");
actual.CopyTo(fileStream);
fileStream.Close();