コード例 #1
0
        public static void Run()
        {
            // ExStart:LoadDataInXMLTemplate
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_AdvanceFeatures();

            // Creating a new Pdf object
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

            // Binding the content from the named XML file
            pdf.BindXML(dataDir + "Sample.xml", null);

            // In a real scenario, data is usually input from Database. So, we can get data
            // From a database. In this case, we are using a method that will provide us an
            // Instance of DataTable. The implementation of this method is also given below.
            DataTable getDT = creatDataTable();

            // Accessing a table through its ID
            Aspose.Pdf.Generator.Table contenTable = (Aspose.Pdf.Generator.Table)pdf.GetObjectByID("Content");

            // Importing data from a DataTable and filling the table in PDF document
            contenTable.ImportDataTable(getDT, false, 1, 1, 5, 4);

            // Saving the results
            pdf.Save(dataDir + "Sample_out.pdf");
            // ExEnd:LoadDataInXMLTemplate
        }
コード例 #2
0
        public static void Run()
        {
            try
            {
                // ExStart:XSLToPdf
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_AdvanceFeatures();

                XmlDocument  xmlDoc = new XmlDocument();
                MemoryStream ms     = new MemoryStream();

                XslCompiledTransform xsl = new XslCompiledTransform();
                xsl.Load(dataDir + "test.xsl");
                xsl.Transform(xmlDoc, null, ms);

                ms.Position = 0;
                xmlDoc.Load(ms);
                ms.Close();

                // Instantiate the Pdf instance
                Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
                // Bind the XML file
                pdf1.BindXML(xmlDoc, null);
                // Save the resultant PDF
                pdf1.Save(dataDir + "XSLToPdf_out.pdf");
                // ExEnd:XSLToPdf
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #3
0
        public static void Run()
        {
            // ExStart:SendingPdfToBrowser
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_AdvanceFeatures();

            // Instantiate Pdf instance by calling its empty constructor
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

            MemoryStream stream   = new MemoryStream();
            HttpResponse Response = new HttpResponse(null);

            pdf1.Save(stream);
            Response.Clear();
            Response.ClearHeaders();
            Response.ClearContent();
            Response.Charset = "UTF-8";
            Response.AddHeader("Content-Length", stream.Length.ToString());
            Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", dataDir + "SendingPdfToBrowser.pdf"));
            Response.ContentType = "application/pdf";
            Response.BinaryWrite(stream.ToArray());
            Response.Flush();
            Response.End();
            // ExEnd:SendingPdfToBrowser
        }
コード例 #4
0
        public static void Run()
        {
            // ExStart:AddPageBorder
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_AdvanceFeatures();

            // Instantiate Pdf instance by calling its empty constructor
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

            // Add a section in the Pdf
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

            // Set the page border of the section using BorderInfo object
            sec1.PageInfo.PageBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 0.2F);

            // Set the left margin of page border of the section
            sec1.PageInfo.PageBorderMargin.Left = 20;

            // Add a text paragraph to the paragraphs collection of the section
            sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text("Hello World"));

            dataDir = dataDir + "AddPageBorder_out_.pdf";
            // Save the Pdf
            pdf1.Save(dataDir);
            // ExEnd:AddPageBorder
        }
コード例 #5
0
        public static void Run()
        {
            // ExStart:XMLAsTemplate
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_AdvanceFeatures();

            // Create a Pdf instance and bind the XML template file to Pdf instance
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
            pdf1.BindXML(dataDir + "Template.xml", null);

            // Get the section and then table from the obtained section of the Pdf that
            // is built from the XML template
            Aspose.Pdf.Generator.Section sec1   = pdf1.Sections["Section1"];
            Aspose.Pdf.Generator.Table   table1 = sec1.Paragraphs["Table1"] as Aspose.Pdf.Generator.Table;

            // Clone a new table
            Aspose.Pdf.Generator.Table table2 = table1.CompleteClone() as Aspose.Pdf.Generator.Table;

            // Change the ID of table2 to "Table2" to make it different from table1
            table2.ID = "Table2";

            // Add table2 into the section
            sec1.Paragraphs.Add(table2);

            // Now there are 2 segments with ID "Item",
            // We change the IDs to make sure they are different
            Aspose.Pdf.Generator.Segment item = sec1.GetObjectByID("Item") as Aspose.Pdf.Generator.Segment;
            item.ID = "Item1";
            item    = sec1.GetObjectByID("Item") as Aspose.Pdf.Generator.Segment;
            item.ID = "Item2";

            // Change the content
            item.Content = "item 2";

            // Now clone section1
            Aspose.Pdf.Generator.Section sec2 = sec1.CompleteClone() as Aspose.Pdf.Generator.Section;

            // Add a cloned section to the Pdf and change the contents of the text segments
            // in the section2 of the Pdf object
            pdf1.Sections.Add(sec2);
            item         = sec2.GetObjectByID("Item1") as Aspose.Pdf.Generator.Segment;
            item.Content = "item1 sec2";
            item         = sec2.GetObjectByID("Item2") as Aspose.Pdf.Generator.Segment;
            item.Content = "item2 sec2";

            // Save the Pdf
            pdf1.Save(dataDir + "XmlTemp_out_.pdf");
            // ExEnd:XMLAsTemplate
        }
コード例 #6
0
        public static void Run()
        {
            // ExStart:MergeXMLFiles
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_AdvanceFeatures();

            FileStream fs1 = new FileStream(dataDir + "XSLFOToPDF.xml", FileMode.Open);
            FileStream fs2 = new FileStream(dataDir + "XSLFOToPDF.xsl", FileMode.Open);

            // Instantiate the Pdf instance
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
            // Bind the XML and XSLT file
            pdf1.BindXML(fs1, fs2);
            // Save the resultant PDF
            pdf1.Save(dataDir + "XMlXSLTMERGE_out.pdf");

            fs1.Close();
            fs2.Close();
            // ExEnd:MergeXMLFiles
        }
コード例 #7
0
        public static void Run()
        {
            // ExStart:TableMinimumColumnWidth
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_AdvanceFeatures();

            // Instantiate Pdf instance by calling its empty constructor
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

            // Add a section in the Pdf
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

            // Create a table object and add it to the paragraphs collection of the section
            Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();
            sec1.Paragraphs.Add(tab1);

            // Set the column widths and default cell border of the table
            tab1.ColumnWidths      = "60 100 100";
            tab1.DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 1F);

            // Prepare an array of string values to be added to table
            string[] darr = new string[]
            { "Owner/Marketing Assistant", "dhasf hh ddt", "dhaosdha djsd dsads",
              "dsd dajd", "hdsah jj jj jdj", "ddfa jjj jhdusa" };

            // Import the contents of the array created in above step
            tab1.ImportArray(darr, 0, 0, true);

            // Call GetMinColumnWidth and pass the column number whose minimum width is needed
            float width = tab1.GetMinColumnWidth(pdf1, 0);

            // Call SetColumnWidth and pass the column number with minimum width
            tab1.SetColumnWidth(0, width);

            dataDir = dataDir + "TableMinimumColumnWidth_out.pdf";
            // Save the Pdf
            pdf1.Save(dataDir);
            // ExEnd:TableMinimumColumnWidth
        }