コード例 #1
0
        public FileStreamResult Get()
        {
            AuthenticationHeaderValue.TryParse(Request.Headers["Authorization"], out AuthenticationHeaderValue authorizationHeader);
            if (authorizationHeader == null)
            {
                throw new ApiException(401, "Unauthorized");
            }

            PdfApi api = new PdfApi(new Configuration(null, null, BaseProductUri));

            api.ApiClient.AccessToken = authorizationHeader.Parameter;
            //PdfApi api = new PdfApi(authorizationHeader.Parameter);

            string name = "test.pdf";

            using (Stream stream = System.IO.File.OpenRead(Path.Combine(TestDataFolder, name)))
            {
                string resFileName = "result.doc";

                var    response = api.PutPdfInRequestToDoc(resFileName, file: stream);
                Stream sr       = api.DownloadFile(resFileName);
                api.DeleteFile(resFileName);
                return(new FileStreamResult(sr, "application/msword"));
            }
        }
コード例 #2
0
        public void DownloadFileTest()
        {
            string name = "4pages.pdf";

            UploadFile(name, name);

            var response = PdfApi.DownloadFile(Path.Combine(TempFolder, name));

            Assert.That(response.Length, Is.GreaterThan(0));
        }
コード例 #3
0
        public void GetDownloadExample()
        {
            //ExStart: GetDownloadExample
            string name = "4pages.pdf";

            UploadFile(name, name);

            var response = api.DownloadFile(Path.Combine(FolderName, name));

            Console.WriteLine(response);
            //ExEnd: GetDownloadExample
        }
コード例 #4
0
        public ActionResult GenerateTicket(string TicketNo, string FlightNo, string Name, DateTime FlightDate,
                                           string From, string To, string Class, string Seat, string Age, string Phone, string Gender)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(TicketNo).AppendLine(FlightNo).AppendLine(Name).AppendLine(FlightDate.ToString())
                .AppendLine(From).AppendLine(To).AppendLine(Class).AppendLine(Seat).AppendLine(Age).AppendLine(Phone).AppendLine(Gender);
                string fileName    = Guid.NewGuid().ToString();
                string pdfFileName = fileName + ".pdf";
                using (var file = System.IO.File.OpenRead(Path.Combine(_hostingEnvironment.WebRootPath, "ticket_template.pdf")))
                {
                    var response = _pdfApi.UploadFile(pdfFileName, file);
                }
                using (Stream barcodeResponse = _barCodeApi.BarCodeGetBarCodeGenerate(new BarCodeGetBarCodeGenerateRequest(Crc32.ComputeChecksum(Encoding.UTF8.GetBytes(sb.ToString())).ToString(), "Code128", "png")))
                {
                    _pdfApi.PostInsertImage(pdfFileName, 1, 350, 600, 450, 700, image: barcodeResponse);
                }
                Fields fields = new Fields(List: new List <Field>()
                {
                    new Field(Name: "TicketNumber", Values: new List <string> {
                        TicketNo
                    }),
                    new Field(Name: "FlightNumber", Values: new List <string> {
                        FlightNo
                    }),
                    new Field(Name: "Date", Values: new List <string> {
                        FlightDate.ToShortDateString()
                    }),
                    new Field(Name: "Time", Values: new List <string> {
                        FlightDate.ToShortTimeString()
                    }),
                    new Field(Name: "From", Values: new List <string> {
                        From
                    }),
                    new Field(Name: "To", Values: new List <string> {
                        To
                    }),
                    new Field(Name: "Class", Values: new List <string> {
                        Class
                    }),
                    new Field(Name: "Seat", Values: new List <string> {
                        Seat
                    }),
                    new Field(Name: "Name", Values: new List <string> {
                        Name
                    }),
                    new Field(Name: "Age", Values: new List <string> {
                        Age
                    }),
                    new Field(Name: "Phone", Values: new List <string> {
                        Phone
                    }),
                    new Field(Name: "Gender", Values: new List <string> {
                        Gender
                    }),
                });
                _pdfApi.PutUpdateFields(pdfFileName, fields);

                /*
                 * string pdfFileNamePage2 = fileName + "_Page2.pdf";
                 * using (var file = System.IO.File.OpenRead(Path.Combine(_hostingEnvironment.WebRootPath, "second_page.html")))
                 * {
                 *  _htmlApi.PostConvertDocumentToPdf(file, pdfFileNamePage2);
                 * }
                 * _pdfApi.PostAppendDocument(pdfFileName, pdfFileNamePage2);
                 */
                MemoryStream ms = new MemoryStream();
                using (Stream response = _pdfApi.DownloadFile(pdfFileName))
                {
                    response.CopyTo(ms);
                    ms.Position = 0;
                    return(new FileStreamResult(ms, "application/pdf"));
                }
            }
            catch (ApiException ex)
            {
                return(new StatusCodeResult(ex.ErrorCode));
            }
        }
コード例 #5
0
        /// <summary>
        /// Sends back specified file from specified folder inside OutputDirectory.
        /// </summary>
        /// <param name="folder">Folder inside OutputDirectory.</param>
        /// <param name="file">File.</param>
        /// <returns>HTTP response with file.</returns>


        public FileResult DownloadFile(string file)
        {
            PdfApi pdfApi = new PdfApi(Config.Configuration.AppKey, Config.Configuration.AppSID);

            return(File(pdfApi.DownloadFile(file), "application/octet-stream", file));
        }