/// <summary> /// Converts given HTML string to PDF. /// </summary> /// <param name="configuration"></param> /// <returns>PDF as byte array.</returns> public static byte[] ConvertHtmlToPdf(PdfConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } var bytes = ConvertByHtml(configuration.WkhtmlPath, configuration.GetConvertOptions(), configuration.Content, WkhtmlPdfExe); Store(configuration.OutputPath, bytes); return(bytes); }
protected override void OnElementChanged(ElementChangedEventArgs <Page> e) { base.OnElementChanged(e); if (e.OldElement != null || Element == null) { return; } activity = Context as MainActivity; view = activity.LayoutInflater.Inflate(Resource.Layout.ActivityCustomFragment, this, false); // Get the Uri provided when launching the activity. var documentUri = Utils.ExtractAsset(Context, MainActivity.sampleDoc); // Create a new (plain) configuration. configuration = new PdfConfiguration.Builder().Build(); fragment = PdfFragment.NewInstance(documentUri, configuration); activity.SupportFragmentManager .BeginTransaction() .Replace(Resource.Id.fragmentContainer, fragment) .Commit(); InitModularSearchViewAndButton(); InitOutlineViewAndButton(); InitThumbnailBar(); InitThumbnailGridAndButton(); // Register the activity to be notified when the document is loaded. fragment.AddDocumentListener(this); fragment.AddDocumentListener(modularSearchView?.JavaCast <IDocumentListener> ()); fragment.AddDocumentListener(thumbnailBar.DocumentListener); fragment.AddDocumentListener(thumbnailGrid); fragment.SetOnDocumentLongPressListener(this); (this.Element as PdfViewerPage).OnBackPressed = OnBackPressed; AddView(view); }
protected override void OnAppearing() { base.OnAppearing(); if (this.configPDF == null) { configPDF = new PdfConfiguration(); } Team equipe = KTContext.Db.Teams .Where(e => e.Id == equipeId) .Include(e => e.Members) .ThenInclude(m => m.Specialist) .Include(e => e.Members) .ThenInclude(m => m.ModelProfile) .Include(e => e.Faction).First(); Title = equipe.Name + " (" + equipe.Cost + ")"; BindingContext = configPDF; BusyIndicator.IsVisible = false; PDFButton.IsVisible = true; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.ActivityCustomFragment); // Get the Uri provided when launching the activity. var documentUri = Intent.GetParcelableExtra(ExtraUri)?.JavaCast <Android.Net.Uri> (); // Create a new (plain) configuration. configuration = new PdfConfiguration.Builder().Build(); // Extract the existing fragment from the layout. The fragment only exist if it has been created // previously (like if the activity is recreated). If no fragment was found, create a new one // providing it with the configuration and document Uri. fragment = SupportFragmentManager.FindFragmentById(Resource.Id.fragmentContainer)?.JavaCast <PdfFragment> (); if (fragment == null) { fragment = PdfFragment.NewInstance(documentUri, configuration); SupportFragmentManager .BeginTransaction() .Replace(Resource.Id.fragmentContainer, fragment) .Commit(); } InitModularSearchViewAndButton(); InitOutlineViewAndButton(); InitThumbnailBar(); InitThumbnailGridAndButton(); // Register the activity to be notified when the document is loaded. fragment.AddDocumentListener(this); fragment.AddDocumentListener(modularSearchView?.JavaCast <IDocumentListener> ()); fragment.AddDocumentListener(thumbnailBar.DocumentListener); fragment.AddDocumentListener(thumbnailGrid); fragment.SetOnDocumentLongPressListener(this); }
/// <summary> /// Converts given HTML string to PDF. /// </summary> /// <param name="html">String containing HTML code that should be converted to PDF.</param> /// <param name="configuration"></param> /// <returns>PDF as byte array.</returns> public static byte[] ConvertHtmlToPdf(string html, PdfConfiguration configuration) { return(Convert(configuration.WkhtmlPath, configuration.GetConvertOptions(), html, WkhtmlPdfExe)); }