Xamarin free HTML or DOC to PDF Conversion

前端 未结 4 1845
既然无缘
既然无缘 2021-02-06 15:49

I\'m currently searching for a library or a way to convert HTML OR DOCX files into PDF on the phone/tab, primarily I\'am searching for a way on Android or iOS idk if its a PCL o

4条回答
  •  攒了一身酷
    2021-02-06 16:13

    Yes, you can convert a Word document to PDF in Xamarin with a few lines of code easily. You need to refer Syncfusion.Xamarin.DocIORenderer from nuget.org

    Assembly assembly = typeof(App).GetTypeInfo().Assembly;
    // Retrieves the document stream from embedded Word document
    Stream inputStream = assembly.GetManifestResourceStream("WordToPDF.Assets.GettingStarted.docx");
    string fileName = "GettingStarted.pdf";
    // Creates new instance of WordDocument
    WordDocument wordDocument = new WordDocument(inputStream,Syncfusion.DocIO.FormatType.Automatic);
    inputStream.Dispose();
    // Creates new instance of DocIORenderer for Word to PDF conversion
    DocIORenderer render = new DocIORenderer();
    // Converts Word document into PDF document
    PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
    // Releases all resources used by the DocIORenderer and WordDocument instance
    render.Dispose();
    document.Close();
    // Saves the converted PDF file
    MemoryStream outputStream = new MemoryStream();
    pdfDocument.Save(outputStream);
    // Releases all resources used by the PdfDocument instance
    pdfDocument.Close();
    

    To know more about this, kindly refer here.

提交回复
热议问题