private static void extendedTest(IDocumentProvider msGraph, Microsoft.Graph.User serviceUser) { var documents = msGraph.GetDocuments(serviceUser.Id); //var folders = msGraph.GetFolders(); /*var htmlLargeInputBytes = File.ReadAllBytes("..\\..\\resources\\source\\large-file.pptx"); * byte[] pdfHTMLLargeDocBytes = msGraph.ConvertDocumentToPDF(htmlLargeInputBytes, $"Temp/{Guid.NewGuid()}.pptx", serviceUser.Id); * File.WriteAllBytes($"..\\..\\resources\\target\\large-file-pptx.pdf", pdfHTMLLargeDocBytes);*/ var htmlSimpleInputBytes = File.ReadAllBytes("..\\..\\resources\\source\\simple-html.html"); byte[] pdfHTMLSimpleDocBytes = msGraph.ConvertDocumentToPDF(htmlSimpleInputBytes, $"Temp/{Guid.NewGuid()}.html", serviceUser.Id); File.WriteAllBytes($"..\\..\\resources\\target\\simple-html.pdf", pdfHTMLSimpleDocBytes); /*var csvSimpleInputBytes = File.ReadAllBytes("..\\..\\resources\\source\\simple.csv"); * byte[] pdfCSVSimpleDocBytes = msGraph.ConvertDocumentToPDF(csvSimpleInputBytes, $"Temp/{Guid.NewGuid()}.csv", serviceUser.Id); * File.WriteAllBytes($"..\\..\\resources\\target\\csv-simple.pdf", pdfCSVSimpleDocBytes);*/ var inputBytes = File.ReadAllBytes("..\\..\\resources\\source\\doc.docx"); byte[] pdfDocBytes = msGraph.ConvertDocumentToPDF(inputBytes, $"Temp/{Guid.NewGuid()}.docx", serviceUser.Id); File.WriteAllBytes($"..\\..\\resources\\target\\doc.pdf", pdfDocBytes); var invoiceInputBytes = File.ReadAllBytes("..\\..\\resources\\source\\invoice.xlsx"); byte[] pdfInvoiceDocBytes = msGraph.ConvertDocumentToPDF(invoiceInputBytes, $"Temp/{Guid.NewGuid()}.xlsx", serviceUser.Id); File.WriteAllBytes($"..\\..\\resources\\target\\invoice.pdf", pdfInvoiceDocBytes); /*var csvInvoiceInputBytes = File.ReadAllBytes("..\\..\\resources\\source\\invoice.csv"); * byte[] pdfCSVInvoiceDocBytes = msGraph.ConvertDocumentToPDF(csvInvoiceInputBytes, $"Temp/{Guid.NewGuid()}.csv", serviceUser.Id); * File.WriteAllBytes($"..\\..\\resources\\target\\csv-invoice.pdf", pdfCSVInvoiceDocBytes);*/ var rootDocs = msGraph.GetRootDocuments(serviceUser.Id); var doc1 = msGraph.GetDocumentByPath(serviceUser.Id, "dummy.txt"); //var doc2 = msGraph.GetDocumentById(serviceUser.Id, "01IKWSDM5REL3VRV2EFNHZ6DCBXVN46JCV"); // 01IKWSDMZZH4XLSPOKLNA33GWZD6XF7MC5 //var doc3 = msGraph.GetDocumentByPath(serviceUser.Id, "7Digital"); //var childDocuments = msGraph.GetChildDocumentsById(serviceUser.Id, "01IKWSDM5REL3VRV2EFNHZ6DCBXVN46JCV"); var smallBuffer = System.Text.Encoding.UTF8.GetBytes("Empty"); var smallDocName = Guid.NewGuid().ToString(); var smallDoc = msGraph.UploadSmallDocument(smallBuffer, $"Temp/{smallDocName}.txt", serviceUser.Id); msGraph.DeleteDocumentById(serviceUser.Id, smallDoc.id); var largeBuffer = System.IO.File.ReadAllBytes("..\\..\\resources\\source\\doc.docx"); var largeDocName = Guid.NewGuid().ToString(); var largeDoc = msGraph.UploadLargeDocument(largeBuffer, $"Temp/{largeDocName}.txt", serviceUser.Id); msGraph.DeleteDocumentById(serviceUser.Id, largeDoc.id); }
public string modify([FromBody] DocumentHeader documentHeader) { IBlobService blobService = new AzureBlobService(); var blobContents = blobService.getBlobContents(blobContainerConnString, blobContainerName, documentHeader.BlobItemName); var tempGUID = Guid.NewGuid().ToString(); var tempDocPath = $"./local/{tempGUID}"; System.IO.Directory.CreateDirectory(tempDocPath); System.IO.File.WriteAllBytes($"{tempDocPath}.docx", blobContents); var bookmarkReplacements = new Dictionary <string, string>(); bookmarkReplacements.Add("Commentor_adresse", "Andevej 14"); bookmarkReplacements.Add("Commentor_navn_header", "Anders And"); bookmarkReplacements.Add("Commentor_navn_body", "Anders And"); bookmarkReplacements.Add("Commentor_registreringsnummer", "1234 1234512345"); bookmarkReplacements.Add("Commentor_dato", DateTime.Now.ToString("dd.MM.yyyy")); bookmarkReplacements.Add("Commentor_bodytext", documentHeader.BodyText); openDocument.ReplaceBookmarks($"{tempDocPath}.docx", $"{tempDocPath} - REPLACED.docx", bookmarkReplacements); var htmlSimpleInputBytes = System.IO.File.ReadAllBytes($"{tempDocPath} - REPLACED.docx"); var serviceUser = docProvider.GetUser("*****@*****.**"); byte[] pdfHTMLSimpleDocBytes = docProvider.ConvertDocumentToPDF(htmlSimpleInputBytes, $"Temp/{Guid.NewGuid()}.docx", serviceUser.Id); System.IO.File.WriteAllBytes($"{tempDocPath} - REPLACED.pdf", pdfHTMLSimpleDocBytes); return(tempGUID); }
private static void ConvertWordToPDF(IDocumentProvider documentProvider, string serviceUserId) { var inputBytes = File.ReadAllBytes("..\\..\\resources\\source\\doc.docx"); var guid = Guid.NewGuid(); byte[] pdfDocBytes = documentProvider.ConvertDocumentToPDF(inputBytes, $"Temp/{guid}.docx", serviceUserId); File.WriteAllBytes($"..\\..\\resources\\target\\{guid}.pdf", pdfDocBytes); }