static void Main(string[] args)
        {
            // Resizing an image

            Cloudmersive.APIClient.NETCore.ImageRecognition.Client.Configuration.Default.AddApiKey("Apikey", "YOUR-API-KEY");



            var apiInstance1 = new ResizeApi();
            var maxWidth     = 56;                                                                       // int? | Maximum width of the output image - final image will be as large as possible while less than or equial to this width
            var maxHeight    = 56;                                                                       // int? | Maximum height of the output image - final image will be as large as possible while less than or equial to this height
            var imageFile    = new System.IO.FileStream("C:\\temp\\input.jpg", System.IO.FileMode.Open); // System.IO.Stream | Image file to perform the operation on.  Common file formats such as PNG, JPEG are supported.

            try
            {
                // Resize an image with parameters
                byte[] result = apiInstance1.ResizePost(maxWidth, maxHeight, imageFile);
                Debug.WriteLine("Completed 1");

                File.WriteAllBytes("C:\\temp\\output.png", result);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling ResizeApi.ResizePost: " + e.Message);
            }

            // Converting a Word Document (DOCX) to PDF

            Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Client.Configuration.Default.AddApiKey("Apikey", "YOUR-API-KEY");

            var apiInstance2 = new ConvertDocumentApi();
            var inputFile    = new System.IO.FileStream("C:\\temp\\input.docx", System.IO.FileMode.Open); // System.IO.Stream | Input file to perform the operation on.

            try
            {
                // Word DOCX to PDF
                byte[] result = apiInstance2.ConvertDocumentDocxToPdf(inputFile);
                Debug.WriteLine("Completed 2");

                File.WriteAllBytes("C:\\temp\\output.pdf", result);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentDocxToPdf: " + e.Message);
            }
        }
        public FileResult ViewPdf(int?id)
        {
            var archivo = db.planillascontratos.Where(dp => dp.PC_Id == id).FirstOrDefault();

            // Configure API key authorization: Apikey
            Configuration.Default.AddApiKey("Apikey", "768fa287-07a9-41f9-962d-d1b9356a6b04");
            ConvertDocumentApi apiInstance = new ConvertDocumentApi();
            //convertir un binario a system.io.stream
            MemoryStream stream = new MemoryStream(archivo.PC_Binario);

            // convertir
            byte[] result = apiInstance.ConvertDocumentDocxToPdf(stream);

            //return File(result, "document/pdf", archivo.PC_Nom + ".pdf");

            ViewBag.nombre = archivo.PC_Nom + "" + archivo.PC_Ext;
            return(File(result, "application/pdf"));
        }
        public ActionResult DescargarPdf(int?id)
        {
            var archivo = db.planillascontratos.Where(dp => dp.PC_Id == id).FirstOrDefault();

            // Configure API key authorization: Apikey
            Configuration.Default.AddApiKey("Apikey", "768fa287-07a9-41f9-962d-d1b9356a6b04");
            ConvertDocumentApi apiInstance = new ConvertDocumentApi();
            //convertir un binario a system.io.stream
            MemoryStream stream = new MemoryStream(archivo.PC_Binario);

            try
            {
                // convertir
                byte[] result = apiInstance.ConvertDocumentDocxToPdf(stream);
                return(File(result, "document/pdf", archivo.PC_Nom + ".pdf"));
            }
            catch (Exception e)
            {
                Debug.Print("Error al convertir : " + e.Message);
            }
            return(View());
        }
예제 #4
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            // Configure API key authorization: Apikey
            Configuration.Default.AddApiKey("Apikey", "71b067cf-1d07-474d-9403-1d0e53ca3da4");



            var apiInstance = new EditDocumentApi();
            var inputFile   = new MemoryStream(fileDocumentEditing.FileBytes); // System.IO.Stream | Input file to perform the operation on.

            // Begin editing a document
            string result = apiInstance.EditDocumentBeginEditing(inputFile);

            // Add a header

            var reqConfig = new DocxSetFooterRequest(); // DocxSetHeaderRequest |

            reqConfig.InputFileUrl = result.Replace("\"", "");

            DocxParagraph p    = new DocxParagraph();
            DocxRun       run  = new DocxRun();
            DocxText      text = new DocxText();

            text.TextContent = "Hello, World!";
            run.TextItems    = new List <DocxText> {
                text
            };

            DocxRun  run2  = new DocxRun();
            DocxText text2 = new DocxText();

            text2.TextContent = "- From Cloudmersive";
            run2.Bold         = true;
            run2.TextItems    = new List <DocxText> {
                text2
            };

            p.ContentRuns = new List <DocxRun> {
                run, run2
            };

            DocxFooter footer = new DocxFooter();

            footer.Paragraphs = new List <DocxParagraph> {
                p
            };

            reqConfig.FooterToApply = footer;

            DocxSetFooterResponse footerResult = apiInstance.EditDocumentDocxSetFooter(reqConfig);

            // Add a table

            var addTable = new InsertDocxTablesRequest(); // InsertDocxTablesRequest |

            addTable.InputFileUrl = footerResult.EditedDocumentURL;

            DocxTable table = new DocxTable();

            table.TopBorderType  = "Single";
            table.TopBorderSize  = 4;
            table.TopBorderSpace = 0;
            table.TopBorderColor = "000000";

            table.LeftBorderType  = "Single";
            table.LeftBorderSize  = 4;
            table.LeftBorderColor = "000000";

            table.RightBorderType  = "Single";
            table.RightBorderSize  = 4;
            table.RightBorderColor = "000000";

            table.CellHorizontalBorderType  = "Single";
            table.CellHorizontalBorderSize  = 4;
            table.CellHorizontalBorderColor = "000000";
            table.CellHorizontalBorderSpace = 0;

            table.CellVerticalBorderType  = "Single";
            table.CellVerticalBorderSize  = 4;
            table.CellVerticalBorderColor = "000000";
            table.CellVerticalBorderSpace = 0;

            DocxTableRow  headerRow = new DocxTableRow();
            DocxTableCell col1      = new DocxTableCell();

            col1.CellShadingFill = "FFFFFF";

            p                = new DocxParagraph();
            run              = new DocxRun();
            text             = new DocxText();
            text.TextContent = "First Header";
            run.TextItems    = new List <DocxText>()
            {
                text
            };
            run.Bold      = true;
            p.ContentRuns = new List <DocxRun>()
            {
                run
            };
            col1.Paragraphs = new List <DocxParagraph>()
            {
                p
            };
            headerRow.RowCells = new List <DocxTableCell>()
            {
                col1
            };

            table.TableRows = new List <DocxTableRow> {
                headerRow
            };


            col1 = new DocxTableCell();
            col1.CellShadingFill = "FFFFFF";

            p                = new DocxParagraph();
            run              = new DocxRun();
            text             = new DocxText();
            text.TextContent = "Second Header";
            run.TextItems    = new List <DocxText>()
            {
                text
            };
            run.Bold      = true;
            p.ContentRuns = new List <DocxRun>()
            {
                run
            };
            col1.Paragraphs = new List <DocxParagraph>()
            {
                p
            };
            headerRow.RowCells = new List <DocxTableCell>()
            {
                col1
            };

            headerRow.RowCells.Add(col1);

            table.TableRows = new List <DocxTableRow> {
                headerRow
            };

            for (int i = 1; i <= 10; i++)
            {
                // Column 1

                DocxTableRow  dataRow  = new DocxTableRow();
                DocxTableCell dataCol1 = new DocxTableCell();
                dataCol1.CellShadingFill = "FFFFFF";

                p                = new DocxParagraph();
                run              = new DocxRun();
                text             = new DocxText();
                text.TextContent = "Data Row " + i.ToString();
                run.TextItems    = new List <DocxText>()
                {
                    text
                };
                run.Bold      = false;
                p.ContentRuns = new List <DocxRun>()
                {
                    run
                };
                dataCol1.Paragraphs = new List <DocxParagraph>()
                {
                    p
                };
                dataRow.RowCells = new List <DocxTableCell>()
                {
                    dataCol1
                };

                table.TableRows.Add(dataRow);

                // Column 2

                dataCol1 = new DocxTableCell();
                dataCol1.CellShadingFill = "FFFFFF";

                p                = new DocxParagraph();
                run              = new DocxRun();
                text             = new DocxText();
                text.TextContent = "Data Row " + i.ToString();
                run.TextItems    = new List <DocxText>()
                {
                    text
                };
                run.Bold      = false;
                p.ContentRuns = new List <DocxRun>()
                {
                    run
                };
                dataCol1.Paragraphs = new List <DocxParagraph>()
                {
                    p
                };
                dataRow.RowCells = new List <DocxTableCell>()
                {
                    dataCol1
                };

                dataRow.RowCells.Add(dataCol1);

                table.TableRows.Add(dataRow);
            }

            addTable.TableToInsert = table;

            InsertDocxTablesResponse tableAdded = apiInstance.EditDocumentDocxInsertTable(addTable);

            // Finish editing

            var finEditing = new FinishEditingRequest(); // FinishEditingRequest |

            finEditing.InputFileUrl = tableAdded.EditedDocumentURL;

            byte[] finishedDocument = apiInstance.EditDocumentFinishEditing(finEditing);

            // Convert to PDF

            var convertApi  = new ConvertDocumentApi();
            var finishedDoc = new MemoryStream(finishedDocument); // System.IO.Stream | Input file to perform the operation on.

            byte[] pdf = convertApi.ConvertDocumentDocxToPdf(finishedDoc);

            // Display the result

            var viewerApi = new ViewerToolsApi();

            var            finalResult   = new MemoryStream(pdf);
            ViewerResponse viewerSnippet = viewerApi.ViewerToolsCreateSimple(finalResult);

            resultDiv.InnerHtml = viewerSnippet.HtmlEmbed.Replace("iframe", "iframe width='800' height='1000'");
        }