@Andrew any chance you could share your solution ? the solution from support is horrible ( literally converting into Jpeg images then word document then pdf documents again)
I ended up doing some really gross client-side conversion of the documents to get the password prompts to go away:
var docStream = new MemoryStream(response.RawBytes); Stream outputStream = new MemoryStream(); switch (response.ContentType) { case "application/pdf": PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(docStream); pdfLoadedDocument.Save(outputStream); break; case "text/plain": // We need to construct a temporary PDF document from plaintext PdfDocument tempDoc = new PdfDocument(); var page = tempDoc.Pages.Add(); var pageGfx = page.Graphics; PdfTextElement contents = new PdfTextElement(response.Content, new PdfStandardFont(PdfFontFamily.Helvetica, 12)); contents.Draw( page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), new PdfLayoutFormat { Layout = PdfLayoutType.Paginate, Break = PdfLayoutBreakType.FitPage }); tempDoc.Save(outputStream); tempDoc.Close(); break; case "application/msword": case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": WordDocument wordDocument = new WordDocument(docStream, Syncfusion.DocIO.FormatType.Automatic); DocIORenderer render = new DocIORenderer(); render.Settings.ChartRenderingOptions.ImageFormat = ExportImageFormat.Jpeg; PdfDocument pdfDocument = render.ConvertToPDF(wordDocument); render.Dispose(); wordDocument.Dispose(); MemoryStream tempStream = new MemoryStream(); pdfDocument.Save(tempStream); PdfLoadedDocument pdfReloadedDocument = new PdfLoadedDocument(tempStream); pdfReloadedDocument.Save(outputStream); break; default: break; }
Note: I am using RestSharp in my app. You can replace the assignment of "docStream" with the method of accessing the raw bytes of the document that is relev
Thanks for the quick reply!!!!!!!!!!!!!!!!!!!!!!!!! :)
after spending a whole nighter on this I figured out that its our client api's that affect the bytes. I'm using refit and had the exact same password issue as you. I switched to HttpClient and some how it worked.
` public MainPage()
{
InitializeComponent();
LoadDocumentFromInternet();
}
public async Task LoadDocumentFromInternet()
{
pdfViewerControl.LoadDocument(await DownloadPdfStream("http://www.africau.edu/images/default/sample.pdf"));
}
private async Task<Stream> DownloadPdfStream(string URL)
{
HttpClient httpClient = new HttpClient();
HttpResponseMessage response = await httpClient.GetAsync(URL);
//Check whether redirection is needed
if ((int)response.StatusCode == 302)
{
//The URL to redirect is in the header location of the response message
HttpResponseMessage redirectedResponse = await httpClient.GetAsync(response.Headers.Location.AbsoluteUri);
return await redirectedResponse.Content.ReadAsStreamAsync();
}
return await response.Content.ReadAsStreamAsync();
}
`