FillForms.cs
  1. //
  2. // This code is part of Document Solutions for PDF demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using GrapeCity.Documents.Pdf;
  11. using GrapeCity.Documents.Text;
  12.  
  13. namespace DsPdfWeb.Demos
  14. {
  15. // This sample provides a number of forms that can be filled
  16. // and saved or printed right in the sample browser
  17. // using the 'save' or 'print' buttons in DsPdfViewer.
  18. //
  19. // Note that if you print the filled form, everything is done
  20. // in the client browser, no data is sent to our demo server.
  21. // But if you click the 'save' button, the entered data along with
  22. // the original form are sent to the demo server. The server uses DsPdf
  23. // to insert the data into the PDF, and sends the filled PDF form
  24. // back to the client. The demo server neither stores nor analyzes
  25. // the data.
  26. //
  27. // Note also that the viewer's 'download' button will only download
  28. // the original form without the data. Unlike the 'save' button, 'download'
  29. // does not access the server, it only gets the original PDF that was loaded
  30. // into the viewer.
  31. public class FillForms
  32. {
  33. // By default, generate the first form:
  34. public void CreatePDF(Stream stream, int paramsIdx = 0)
  35. {
  36. CreatePDF(stream, GetSampleParamsList()[paramsIdx]);
  37. }
  38.  
  39. public void CreatePDF(Stream stream, string[] sampleParams)
  40. {
  41. var fn = sampleParams[3];
  42. var pn = Path.Combine("Resources", "PDFs", "Forms", "misc", fn);
  43. using (var fs = File.OpenRead(pn))
  44. fs.CopyTo(stream);
  45. }
  46.  
  47. public static List<string[]> GetSampleParamsList()
  48. {
  49. // Strings are name, description, info, rest are arbitrary strings:
  50. return new List<string[]>()
  51. {
  52. new string[] { "@us-tax-forms/Form W-7", "Application for IRS Individual Taxpayer Identification Number", "", "fw7-demo.pdf" },
  53. new string[] { "@us-tax-forms/Form SS-4", "Application for Employer Identification Number", null, "fss4-demo.pdf" },
  54. new string[] { "@e-com-forms/Goods Return", "Goods Return and Exchange Form", null, "goods-return-form.pdf" },
  55. new string[] { "@hr-forms/Time Sheet", "Time Sheet Form", null, "time-sheet-form.pdf" },
  56. new string[] { "@hr-forms/Trip Permission", "Offsite field trip permission slip", null, "offsite-field-trip-form.pdf" },
  57. new string[] { "@member-forms/Health Info", "Health Info Intake Form", null, "health-intake-form.pdf" },
  58. new string[] { "@event-forms/Event Feedback", "Event Feedback Form", null, "event-feedback-form.pdf" },
  59. };
  60. }
  61.  
  62. // Used by SupportApiDemo to initialize DsPdfViewer.
  63. public static GcPdfViewerSupportApiDemo.Models.PdfViewerOptions PdfViewerOptions
  64. {
  65. get => new GcPdfViewerSupportApiDemo.Models.PdfViewerOptions(
  66. GcPdfViewerSupportApiDemo.Models.PdfViewerOptions.Options.FormEditorPanel);
  67. }
  68. }
  69. }
  70.