question

APIPointNewbie-3149 avatar image
0 Votes"
APIPointNewbie-3149 asked saldana-msft edited

How to convert (doc -> pdf) a large number of files efficiently ?

Hello Community,

I would like to convert a large number of files (+40) as efficiently as possible with the MS Graph SDK. So far I iterate through the file ids and pass them to the necessary methods:


     private async Task<Stream> ConvertFiles(GraphServiceClient graphClient, string id)
     {
         var queryOptions = new List<QueryOption>()
     {
         new QueryOption("format", "pdf")
     };
         var stream = await graphClient.Drives[DriveId]
                                       .Items[id]
                                       .Content
                                       .Request(queryOptions)
                                       .GetAsync();

         return stream;
     }

     private async Task SaveFilesInOneDrive(GraphServiceClient graphClient, Stream stream, string fileName)
     {
         await graphClient.Drives[DriveId]
                          .Items[PdfItemId].ItemWithPath(StringUtils.BuildNameForAPdfFile(fileName))
                          .Content
                          .Request()
                          .PutAsync<DriveItem>(stream);
     }

But my approach does not seem so efficient, is there anything to speed up the process ?


I would be very pleased to receive feedback.

Greetings :-)

dotnet-csharpmicrosoft-graph-sdkmicrosoft-graph-files
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CarlZhao-MSFT avatar image
0 Votes"
CarlZhao-MSFT answered APIPointNewbie-3149 commented

As an idea, you can try to use batch processing to convert multiple doc files to pdf files in a single call request.

============
Update on 10.19

Added a doc reference about using Microsoft Graph to batch requests, you can have a try.
https://docs.microsoft.com/en-us/graph/sdks/batch-requests?tabs=csharp


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello, thanks for the answer,

but I can't find anything about batching from doc to pdf in the Microsoft documentation.

Greetings :-)

0 Votes 0 ·

I am discussing this issue with my colleagues and will update you once we have any updates.

1 Vote 1 ·

Hello, that would be really nice of you :-)

0 Votes 0 ·
Show more comments
David-9140 avatar image
0 Votes"
David-9140 Suspended answered APIPointNewbie-3149 commented

Hi, you may try Spire.Doc for .NET, which is a good alternative when doing the file format conversion.

 using System;
 using Spire.Doc;
 using Spire.Doc.Documents;
    
 namespace DoctoPDF
 {
     class toPDF
     {
         static void Main(string[] args)
         {
             //Load Document
             Document document = new Document();
             document.LoadFromFile(@"E:\work\documents\TestSample.docx");
    
             //Convert Word to PDF
             document.SaveToFile("toPDF.PDF", FileFormat.PDF);
    
         }
     }
 }


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello thank you very much for your advice,

but I generate the steam from the file that is in the one drive. And for this I am looking for an more efficient way in MS Graph.

Greetings :-)

0 Votes 0 ·