Beispiel #1
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Text();

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);
            if (!IsExists)
                System.IO.Directory.CreateDirectory(dataDir);

            //Instantiate Pdf instance by calling it empty constructor
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
            //Create a section in the Pdf object
            pdf.Sections.Add();

            pdf.IsTruetypeFontMapCached = true;
            //Specify the location where to save TruetypeFontMap.xml
            pdf.TruetypeFontMapPath = dataDir+ "" ;

            //Create a text object and pass the string object carrying arabic text in it
            Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text();
            //Create a segment and add it to segments collection of text object
            Aspose.Pdf.Generator.Segment seg0 = text1.Segments.Add();
            //specify contents for segment
            seg0.Content = "أسبوز هو بائع عنصر ال";
            Aspose.Pdf.Generator.Segment seg1 = text1.Segments.Add();
            seg1.Content = ".NET";
            Aspose.Pdf.Generator.Segment seg2 = text1.Segments.Add();
            seg2.Content = "البارز";

            //Enable text alignment from right to left
            seg0.TextInfo.IsRightToLeft = true;
            seg1.TextInfo.IsRightToLeft = false;         //default
            seg2.TextInfo.IsRightToLeft = true;

            //Enable unicode character set for the text segment
            seg0.TextInfo.IsUnicode = true;
            seg1.TextInfo.IsUnicode = true;
            seg2.TextInfo.IsUnicode = true;

            //Set Font Name
            seg0.TextInfo.FontName = "Times New Roman";
            seg1.TextInfo.FontName = "Times New Roman";
            seg2.TextInfo.FontName = "Times New Roman";
            //Set font size
            seg0.TextInfo.FontSize = 14;
            seg1.TextInfo.FontSize = 14;
            seg2.TextInfo.FontSize = 14;

            //Align text to right hand side using AlignmentType enumeration    
            //Make the text right aligned(The meaning of Alignment.Left and AlignmentType.Right are //exchanged when processing RTL language).
            text1.TextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Left;

            pdf.Sections[0].Paragraphs.Add(text1);
            pdf.IsRtlInSegmentMode = true;         //default

            pdf.Save(dataDir+"AsposeOutput.pdf");
            
            
        }
        public static void Run()
        {
            try
            {
                // ExStart:CreatePdfA1
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles();

                // Create pdf document
                Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

                // Instantiate License class and call its SetLicense method to use the license
                Aspose.Pdf.License license = new Aspose.Pdf.License();
                license.SetLicense("Aspose.Custom.lic");

                // Set the conformance property of Pdf class to predefined value
                pdf1.Conformance = Aspose.Pdf.Generator.PdfConformance.PdfA1B;

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

                // Save the document
                pdf1.Save(dataDir + "CreatePdfA1_out.pdf");
                // ExEnd:CreatePdfA1  
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            // ExStart:ImageFromWeb
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Images();

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

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

            // Create an image object in the section
            Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1);

            // Add image object into the Paragraphs collection of the section
            sec1.Paragraphs.Add(image1);

            // Set the path of image file
            image1.ImageInfo.File = "http:// Www.aspose.com/Images/Apple.jpg";

            // Set the type of image using ImageFileType enumeration
            image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;

            // Set image title
            image1.ImageInfo.Title = "JPEG image";

            // Save the Pdf
            pdf1.Save(dataDir + "ImageFromLocalDisk_out.pdf");
            // ExEnd:ImageFromWeb         
        }
        public static void Run()
        {
            // ExStart:ConvertMemoryStreamImageToPdf
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles();

            // Instantiate Pdf instance by calling its empty constructor
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
            // Add a section into the pdf document
            Aspose.Pdf.Generator.Section sec = pdf1.Sections.Add();

            // Create a FileStream object to read the imag file
            FileStream fs = File.OpenRead(dataDir + "aspose-logo.jpg");
            // Read the image into Byte array
            byte[] data = new byte[fs.Length];
            fs.Read(data, 0, data.Length);

            // Create a MemoryStream object from image Byte array
            MemoryStream ms = new MemoryStream(data);
            // Create an image object in the section 
            Aspose.Pdf.Generator.Image imageht = new Aspose.Pdf.Generator.Image(sec);
            // Set the type of image using ImageFileType enumeration
            imageht.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;

            // Specify the image source as MemoryStream
            imageht.ImageInfo.ImageStream = ms;
            // Add image object into the Paragraphs collection of the section
            sec.Paragraphs.Add(imageht);

            // Save the Pdf
            pdf1.Save(dataDir + "ConvertMemoryStreamImageToPdf_out.pdf");
            // Close the MemoryStream Object
            ms.Close();
            // ExEnd:ConvertMemoryStreamImageToPdf           
        }
        public static void Run()
        {
            // ExStart:SetPassword
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_SecurityFeatures();

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

            // Assign a security instance to Pdf object
            pdf1.Security = new Aspose.Pdf.Generator.Security();

            // Set the master password for the PDF document
            pdf1.Security.MasterPassword="******";

            // Set the user password for the PDF document
            pdf1.Security.UserPassword="******";

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

            // Create a text paragraph
            Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text(sec1,"this is text content");

            // Set the top maring of text paragraph to 30
            text1.Margin.Top = 30;

            // Add the text paragraph to the section
            sec1.Paragraphs.Add(text1);
            dataDir = dataDir +"SetPassword_out.pdf";
            // Save the Pdf
            pdf1.Save(dataDir);
            // ExEnd:SetPassword           
        }
        public static void Run()
        {
            // ExStart:SetPageBackgroundImage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Sections();
            
            // Instantiate a PDF Object 
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

            // Add a section into the pdf document
            Aspose.Pdf.Generator.Section section1 = pdf.Sections.Add();

            // Assign the image file path to BackgroundImageFile property of section
            section1.BackgroundImageFile = dataDir+ "aspose-logo.jpg";

            // Set the image type using ImageFileType enumeration
            section1.BackgroundImageType = Aspose.Pdf.Generator.ImageFileType.Jpeg;

            dataDir = dataDir + "SetPageBackgroundImage_out.pdf";

            // Save Pdf Document
            pdf.Save(dataDir);
            // ExEnd:SetPageBackgroundImage
            Console.WriteLine("\nPage background image setup successfully.\nFile saved at " + dataDir);
        }
        public static void FontsEmbeddingUsingHTML()
        {
            // ExStart:FontsEmbeddingUsingHTML 
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles();

            // Instantiate a pdf document
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

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

            // Create string variables with text containing html tags
            string s = "<html><body><font isUnicode='true' face='Bete Noir NF' size=18><i>Sample text </i>with Custome font Embedded </font><br><font isUnicode='true' face='Courier New' size=10><s>Sample Text </s>in <u>Courier New</u> font</font></body></html>";

            // Create text paragraphs containing HTML text
            Aspose.Pdf.Generator.Text t1 = new Aspose.Pdf.Generator.Text(s);

            // Enable the HTML tag support property
            t1.IsHtmlTagSupported = true;

            // Add the text paragraphs containing HTML text to the section
            sec1.Paragraphs.Add(t1);

            // Save the pdf document
            pdf1.Save( dataDir + "inLineFormated_HtmlSuported_out.pdf");
            // ExEnd:FontsEmbeddingUsingHTML 
        }
        public static void Run()
        {
            
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Text();

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

            // Create a section in the Pdf object
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
            // ExStart:PFMFont
            // Create a text object in a section
            Aspose.Pdf.Generator.Text t1 = new Aspose.Pdf.Generator.Text(sec1, "Arial Bold MT");

            // Set the font name of a segment in the text object
            t1.Segments[0].TextInfo.FontName = "Arial-BoldMT";

            // Set the PFM file for the text segment 
            t1.Segments[0].TextInfo.FontPfmFile = "_AB_____.PFM";

            // Set the font encoding file for the text segment
            t1.Segments[0].TextInfo.FontEncodingFile = @"CP1250.txt";

            // Set the font encoding name of the text segment
            t1.Segments[0].TextInfo.FontEncoding = "cp1250";
            // ExEnd:PFMFont
            dataDir = dataDir + "PFMFont_out.pdf";
            // Create the result PDF Document
            pdf1.Save(dataDir);
            
        }
        public static void Run()
        {
            // ExStart:InlineParagraph
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Text();

            // Instantiate Pdf instance by calling its empty constructor
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
            // Create section object and add it to sections collection of PDF
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

            // Create a text object
            Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text();
            // Add text object to paragraphs collection of section
            sec1.Paragraphs.Add(text1);
            // Add sample text to segments collection of text object
            text1.Segments.Add("This is a test for inline");
            // Create segment 2 and add it to segements collection of text object
            Aspose.Pdf.Generator.Segment seg2 = text1.Segments.Add();

            // Create a Image object to contain logo gif.
            Aspose.Pdf.Generator.Image img1 = new Aspose.Pdf.Generator.Image();
            // Specify the image file path
            img1.ImageInfo.File = dataDir + "aspose-logo.jpg";
            // Indicate seg2's InlineParagraph is a image.
            seg2.InlineParagraph = img1;
            dataDir = dataDir + "InlineImage_out.pdf";
            // Create the result PDF Document
            pdf1.Save(dataDir);
            // ExEnd:InlineParagraph
        }
        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
        }
        public static void Run()
        {
            try
            {
                // ExStart:HyperlinkTags
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Text();

                // Instantiate a pdf document
                Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

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

                // Create a string variable with text containing hyperlink tag
                string string1 = "<a href=\"http:// Www.aspose.com/\">This is a test</a>";

                // Create text paragraph containing HTML hyperlink tag
                Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text(string1);
                text1.IsHtmlTagSupported = true;

                // Add the text paragraph containing HTML text to the section
                sec1.Paragraphs.Add(text1);

                // Save the document
                pdf1.Save(dataDir + "HyperlinkTags_out.pdf");
                // ExEnd:HyperlinkTags
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #12
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Paragraphs();
            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);
            if (!IsExists)
                System.IO.Directory.CreateDirectory(dataDir);

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

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

            //Create a text paragraph with the reference of a section, sec1
            Aspose.Pdf.Generator.Text text3 = new Aspose.Pdf.Generator.Text(sec1, "product 1 info ...");

            //Add the text paragraph in the section
            sec1.Paragraphs.Add(text3);

            //Set the text paragraph to be the first paragraph among the other ones
            text3.IsFirstParagraph = true;

            //Assign and ID to the text paragraph
            text3.ID = "product1";

            // save the resultant PDF
            pdf1.Save(dataDir+ "ParaID.pdf");
            
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

             // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);
            if (!IsExists)
                System.IO.Directory.CreateDirectory(dataDir);

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

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

            //Create a new text paragraph with an initial text segment "Aspose"
            Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text(sec1,"Aspose");

            //Add the text paragraph to the section
            sec1.Paragraphs.Add(text1);

            //Create a new text segment into the text paragraph
            Aspose.Pdf.Generator.Segment seg2 = text1.Segments.Add("TM");

            //Set the vertical alignment of text segment "seg2" to Topline by setting
            //IsBaseline property  ot seg2.TextInfo to true
            seg2.TextInfo.IsBaseline=false;
            // set the font size information for the segment
            seg2.TextInfo.FontSize = 5;

            //Save the Pdf
            pdf1.Save(dataDir+ "AsposeOutput.pdf");
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);
            if (!IsExists)
                System.IO.Directory.CreateDirectory(dataDir);

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

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

            //Add a text paragraph in the section
            sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text("page 1"));

            //Create another text paragraph that has to be rendered
            Aspose.Pdf.Generator.Text t2 = new Aspose.Pdf.Generator.Text("page2");

            //Set the IsFirstParagraph property of the text paragraph to true
            //to render it to a new page
            t2.IsFirstParagraph = true;

            //Add the text paragraph to be rendered to the section
            sec1.Paragraphs.Add(t2);

            //Save the Pdf document
            pdf1.Save(dataDir+ "HelloWorld.pdf");
        }
        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           
        }
        public static void Run()
        {
            // ExStart:ReplaceableSymbols
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Text();

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

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

            // Create a HeaderFooter object for the section
            Aspose.Pdf.Generator.HeaderFooter hf = new Aspose.Pdf.Generator.HeaderFooter(sec1);

            // Set the HeaderFooter object to odd and even footers
            sec1.OddFooter = sec1.EvenFooter = hf;

            // Add a text paragraph containing current page number of total number of pages
            hf.Paragraphs.Add(new Aspose.Pdf.Generator.Text(hf, "page $p of $P"));

            dataDir = dataDir + "ReplaceableSymbols_out.pdf";
            // Create the result PDF Document
            pdf1.Save(dataDir);
            // ExEnd:ReplaceableSymbols
        }
        public static void DefineFormat()
        {
            
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_UtilityFeatures();

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

            // Create a list section 
            Aspose.Pdf.Generator.ListSection tocSection = new Aspose.Pdf.Generator.ListSection("Table Of Contents");

            // Set its list type as table of of contents
            tocSection.ListType = Aspose.Pdf.Generator.ListType.TableOfContents;

            // ExStart:DefineFormat
            // Set the length of list levels to 3 and set their left margins and text formats 
            tocSection.ListFormatArray.Length = 3;
            tocSection.ListFormatArray[0].LeftMargin = 0;
            tocSection.ListFormatArray[0].TextInfo.FontSize = 16;
            tocSection.ListFormatArray[0].TextInfo.IsTrueTypeFontBold = true;
            tocSection.ListFormatArray[1].LeftMargin = 16;
            tocSection.ListFormatArray[1].TextInfo.FontSize = 14;
            tocSection.ListFormatArray[2].LeftMargin = 32;
            tocSection.ListFormatArray[2].TextInfo.FontSize = 12;
            // ExEnd:DefineFormat  

            // Add the list section to the sections collection of the Pdf document
            pdf1.Sections.Add(tocSection);

            dataDir = dataDir + "DefineFormat_out.pdf";
            // Save the Pdf
            pdf1.Save(dataDir);
                     
        }
        public static void Run()
        {
            // ExStart:GraphCoordinate
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Graphs();

            // Instantiate a Pdf document object
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

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

            // Create a graph object in the section with Width=100 and Height=400
            Aspose.Pdf.Generator.Graph graph1 = new Aspose.Pdf.Generator.Graph(sec1,100,400);

            // Add the graph object to the paragraphs collection of the section
            sec1.Paragraphs.Add(graph1);

            // Create an array containing the (X,Y) values of 4 control points
            // Required to position a curve
            float[] posArr = new float[]{0,0,200,80,300,40,350,90};

            // Create a curve in the graph with the coordinates given as an array to
            // The constructor of curve class
            Aspose.Pdf.Generator.Curve curve1 = new Aspose.Pdf.Generator.Curve(graph1,posArr);

            // Add the curve shape into the shapes collection of the graph
            graph1.Shapes.Add(curve1);

            dataDir = dataDir + "GraphCoordinate_out.pdf";

            // Save the Pdf
            pdf1.Save(dataDir);   
            // ExEnd:GraphCoordinate         
        }
        public static void Run()
        {
            // ExStart:CreatePdf
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_UtilityFeatures();

            // Create a file stream to create the PDF document
            FileStream fs = new FileStream( dataDir +  "SingleSeg-d_out.pdf", FileMode.Create);

            // Instantiate the Pdf instance and pass the file stream object to its constructor
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(fs);

            // Add a section to the PDF document
            Aspose.Pdf.Generator.Section sec1 = pdf.Sections.Add();

            // Add 1000 text paragraphs to the section
            for (int i = 0; i < 1000; i++)
            {
                Aspose.Pdf.Generator.Text t = new Aspose.Pdf.Generator.Text("hello world hello world hello " + i.ToString());
                sec1.AddParagraph(t);
            }

            // Close the Pdf. This method is used only for direct file mode
            pdf.Close(); 
            // ExEnd:CreatePdf           
        }
        public static void Run()
        {
            // ExStart:AssignID
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Paragraphs();

            // Instantiate Pdf object by calling its empty constructor and add a new section to the Pdf object
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();             
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

            // Create a text paragraph with the reference of a section, sec1 and add the text paragraph in the section
            Aspose.Pdf.Generator.Text text3 = new Aspose.Pdf.Generator.Text(sec1, "product 1 info ...");    
            sec1.Paragraphs.Add(text3);

            // Set the text paragraph to be the first paragraph among the other ones
            text3.IsFirstParagraph = true;

            // Assign and ID to the text paragraph
            text3.ID = "product1";

            dataDir = dataDir + "AssignID_out.pdf";
            // Save the resultant PDF
            pdf1.Save(dataDir);
            // ExEnd:AssignID   
            Console.WriteLine("\nAn id assigned successfully to a paragraph.\nFile saved at " + dataDir);
        }
        public static void TrueTypeBoldFont()
        {
          
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Text();

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

            // Create a section in the Pdf object
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
            // ExStart:TrueTypeBoldFont
            // Create a text object in the section
            Aspose.Pdf.Generator.Text t1 = new Aspose.Pdf.Generator.Text(sec1, "Courier New Bold font");

            // Set font name of a specific text segment to courier new
            t1.Segments[0].TextInfo.FontName = "Courier New";

            // Set the font to bold
            t1.Segments[0].TextInfo.IsTrueTypeFontBold = true;
            // ExEnd:TrueTypeBoldFont
            dataDir = dataDir + "TrueTypeBoldFont_out.pdf";
            // Create the result PDF Document
            pdf1.Save(dataDir);
            
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);
            if (!IsExists)
                System.IO.Directory.CreateDirectory(dataDir);

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

            //Create a text object
            Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text("This #$TAB is a example for custom TAB stop positions.");

            //Assign an instance of TabStops to the TabStops property of text object
            text1.TabStops = new Aspose.Pdf.Generator.TabStops();

            //Call Add method of TabStops and pass a specified position as argument
            text1.TabStops.Add(150);

            //Call Add method with specified position and tab leader type as Dot
            text1.TabStops.Add(350, Aspose.Pdf.Generator.TabLeaderType.Dot);

            pdf.Save(dataDir + "Output.pdf");
        }
        public static void Run()
        {
            
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Sections();
            
            // Instantiate a PDF Object 
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

            // Add a section into the pdf document
            Aspose.Pdf.Generator.Section section1 = pdf.Sections.Add();

            // ExStart:SetPageSize
            section1.PageInfo.PageWidth = Aspose.Pdf.Generator.PageSize.A3Width;
            section1.PageInfo.PageHeight = Aspose.Pdf.Generator.PageSize.A3Height;
            // ExEnd:SetPageSize
            // OR 
            // ExStart:SetPageSize-1
            section1.PageInfo.PageWidth = 576;
            section1.PageInfo.PageHeight = 707.5F;
            // ExEnd:SetPageSize-1
 
            dataDir = dataDir + "SetPageSize_out.pdf";

            // Save Pdf Document
            pdf.Save(dataDir);
            
            Console.WriteLine("\nPage size setup successfully.\nFile saved at " + dataDir);
        }
        public static void Run()
        {
            // ExStart:HyperlinkToWeb
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Hyperlinks();
            // Instantiate Pdf document object 
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
            // Create a section in the Pdf
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add(); 
            // Create text paragraph with the reference of a section
            Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(sec1);

            // Add the text paragraph in the paragraphs collection of the section
            sec1.Paragraphs.Add(text2);

            // Add a text segment in the text paragraph
            Aspose.Pdf.Generator.Segment segment2 = text2.Segments.Add("this is a web link");

            // Assign a new instance of hyperlink to hyperlink property of segment
            segment2.Hyperlink = new Aspose.Pdf.Generator.Hyperlink();

            // Set the link type of the text segment to Web
            segment2.Hyperlink.LinkType = Aspose.Pdf.Generator.HyperlinkType.Web;

            // Set the URL of the web location to create a web link for the segment
            segment2.Hyperlink.Url = "http:// Localhost/popup.htm";

            dataDir = dataDir + "HyperlinkToWeb_out.pdf";
            // Save the Pdf
            pdf1.Save(dataDir);
            // ExEnd:HyperlinkToWeb           
        }
Beispiel #25
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_WorkingDocuments();
            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);
            if (!IsExists)
                System.IO.Directory.CreateDirectory(dataDir);


            //Instantiate a PDF Object 
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

            //Instantiate a Aspose PDF JavaScript Object
            pdf.JavaScripts = new Aspose.Pdf.Generator.JavaScripts();

            //Call the Add method and pass JavaScript statement as an argument, to show Print Dialog
            pdf.JavaScripts.Add("this.print(true);");

            //Call the Add method and JavaScript statement as an argument, to show alert
            pdf.JavaScripts.Add("app.alert(\"hello world\");");

            //Save Pdf Document
            pdf.Save(dataDir+ "Aspose.pdf");
            
            
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Instantiate an object PDF class
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

            // add the section to PDF document sections collection
            Aspose.Pdf.Generator.Section section = pdf.Sections.Add();

            // Read the contents of HTML file into StreamReader object
            StreamReader r = File.OpenText(dataDir + "Aspose.htm");

            //Create text paragraphs containing HTML text
            Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd());

            // enable the property to display HTML contents within their own formatting
            text2.IsHtmlTagSupported = true;

            //Add the text paragraphs containing HTML text to the section
            section.Paragraphs.Add(text2);

            // Specify the URL which serves as images database
            //pdf.HtmlInfo.ImgUrl = "D:/pdftest/MemoryStream/";

            //Save the pdf document
            pdf.Save(dataDir + "HTML2pdf.pdf");
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);
            if (!IsExists)
                System.IO.Directory.CreateDirectory(dataDir);

            //Instantiate a PDF Object
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

            //Add a section into the pdf document
            Aspose.Pdf.Generator.Section section1 = pdf.Sections.Add();

            //Assign the image file path to BackgroundImageFile property of section
            section1.BackgroundImageFile = dataDir+ "aspose-logo.jpg";

            //Set the image type using ImageFileType enumeration
            section1.BackgroundImageType = Aspose.Pdf.Generator.ImageFileType.Jpeg;
            //Save Pdf Document

            pdf.Save(dataDir+ "Aspose.pdf");
        }
        public static void Run()
        {
            // ExStart:RotationAndScaling
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Graphs();

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

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

            // Create 1st graph in the section with width=100 and height=400
            Aspose.Pdf.Generator.Graph graph1 = new Aspose.Pdf.Generator.Graph(sec1, 100, 400);

            // Add 1st graph into the paragraphs collection of the section
            sec1.Paragraphs.Add(graph1);

            // Create a rectangle shape with specified coordinates
            Aspose.Pdf.Generator.Rectangle rect1 = new Aspose.Pdf.Generator.Rectangle(graph1, 85, 100, 100, 50);

            // Add the rectangle into the shapes collection of the 1st graph
            graph1.Shapes.Add(rect1);

            // Create 2nd graph in the section with width=100 and height=400
            Aspose.Pdf.Generator.Graph graph2 = new Aspose.Pdf.Generator.Graph(sec1, 100, 400);

            // Add 2nd graph into the paragraphs collection of the section
            sec1.Paragraphs.Add(graph2);

            // Create a rectangle shape with specified coordinates  
            Aspose.Pdf.Generator.Rectangle rect2 = new Aspose.Pdf.Generator.Rectangle(graph2, 85, 100, 100, 50);

            // Add the rectangle into the shapes collection of the 2nd graph
            graph2.Shapes.Add(rect2);

            // Rotate the 2nd graph to 30 degree using RotationAngle property
            graph2.GraphInfo.RotationAngle = 30;

            // Create 3rd graph in the section with width=100 and height=400                
            Aspose.Pdf.Generator.Graph graph3 = new Aspose.Pdf.Generator.Graph(sec1, 100, 400);

            // Add 3rd graph into the paragraphs collection of the section
            sec1.Paragraphs.Add(graph3);

            // Create a rectangle shape with specified coordinates
            Aspose.Pdf.Generator.Rectangle rect3 = new Aspose.Pdf.Generator.Rectangle(graph3, 85, 100, 100, 50);

            // Add the rectangle into the shapes collection of the 3rd graph
            graph3.Shapes.Add(rect3);

            // Adjust the horizontal size of the 3rd graph using ScalingRateX property
            graph3.GraphInfo.ScalingRateX = 1.5f;     

            dataDir = dataDir + "RotationAndScaling_out.pdf";

            // Save the Pdf
            pdf1.Save(dataDir);
            // ExEnd:RotationAndScaling         
        }
        public static void Run()
        {
            // ExStart:SetEncryption
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_SecurityFeatures();

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

            // Assign a security instance to Pdf object
            pdf1.Security = new Aspose.Pdf.Generator.Security();

            // Set encryption level to 128 bits
            pdf1.Security.Is128BitsEncrypted = true;

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

            // Create a text paragraph                           
            Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text(sec1,"this is text content");

            // Set the top maring of text paragraph to 30
            text1.Margin.Top = 30;

            // Add the text paragraph to the section
            sec1.Paragraphs.Add(text1);

            dataDir = dataDir + "SetEncryption_out.pdf";
            // Save the Pdf                           
            pdf1.Save(dataDir);
            // ExEnd:SetEncryption           
        }
        public static void Run()
        {
            // ExStart:UserDefinedBullets
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Headings();
            // Instntiate the Pdf object by calling its empty constructor
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

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

            /*
             * Create 1st heading in the Pdf object's section with level=1. Then create a text 
             * segment and add it in the heading. Set its UserLabel="98" to use a user defined
             * bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". After setting
             * all properties, add heading into the paragraphs collection of the section
             */

            Aspose.Pdf.Generator.Heading heading1 = new Aspose.Pdf.Generator.Heading(pdf1, sec1, 1);
            Aspose.Pdf.Generator.Segment segment1 = new Aspose.Pdf.Generator.Segment(heading1);
            heading1.Segments.Add(segment1);
            segment1.Content = "Symbol";
            heading1.BulletFontName = "Symbol";
            heading1.UserLabel = "98";
            sec1.Paragraphs.Add(heading1);

            /*
             * Create 2nd heading in the Pdf object's section with level=2. Then create a text 
             * segment and add it in the heading. Set its UserLabel="99" to use a user defined
             * bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". After setting
             * all properties, add heading into the paragraphs collection of the section
             */

            Aspose.Pdf.Generator.Heading heading2 = new Aspose.Pdf.Generator.Heading(pdf1, sec1, 2);
            Aspose.Pdf.Generator.Segment segment2 = new Aspose.Pdf.Generator.Segment(heading2);
            heading2.Segments.Add(segment2);
            segment2.Content = "Symbol";
            heading2.BulletFontName = "Symbol";
            heading2.UserLabel = "99";
            sec1.Paragraphs.Add(heading2);

            /*
             * Create 3rd heading in the Pdf object's section with level=3. Then create a text 
             * segment and add it in the heading. Set its UserLabel="100" to use a user defined
             * bullet. You must set BulletFontName to "Symbol" or "ZapfDingbats". After setting
             * all properties, add heading into the paragraphs collection of the section
             */

            Aspose.Pdf.Generator.Heading heading3 = new Aspose.Pdf.Generator.Heading(pdf1, sec1, 3);
            Aspose.Pdf.Generator.Segment segment3 = new Aspose.Pdf.Generator.Segment(heading3);
            heading3.Segments.Add(segment3);
            segment3.Content = "Symbol";
            heading3.BulletFontName = "Symbol";
            heading3.UserLabel = "100";
            sec1.Paragraphs.Add(heading3); 

            pdf1.Save(dataDir + "UserDefinedBullets_out.pdf");
            // ExEnd:UserDefinedBullets   
                
        }
Beispiel #31
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Text();

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

            // Create a section in the Pdf object
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
            // ExStart:EmbedFont
            // Create a text object in a section
            Aspose.Pdf.Generator.Text t1 = new Aspose.Pdf.Generator.Text(sec1, "Arial Bold MT");

            // Set the font name of a segment in the text object
            t1.Segments[0].TextInfo.FontName = "Arial-BoldMT";

            // Set the PFM file for the text segment
            t1.Segments[0].TextInfo.FontPfmFile = "_AB_____.PFM";

            // Set the font encoding file for the text segment
            t1.Segments[0].TextInfo.FontEncodingFile = "CP1250.txt";

            // Set the font encoding name of the text segment
            t1.Segments[0].TextInfo.FontEncoding = "cp1250";

            // Set the font outline file for the text segment
            t1.Segments[0].TextInfo.FontOutlineFile = "_AB_____.PFB";

            // Set IsFontEmbedded to true
            t1.Segments[0].TextInfo.IsFontEmbedded = true;
            // ExEnd:EmbedFont
            dataDir = dataDir + "EmbedFont_out_.pdf";
            // Create the result PDF Document
            pdf1.Save(dataDir);
        }
Beispiel #32
0
        public static void TrueTypeBoldFont()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Text();

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

            // Create a section in the Pdf object
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
            // ExStart:TrueTypeBoldFont
            // Create a text object in the section
            Aspose.Pdf.Generator.Text t1 = new Aspose.Pdf.Generator.Text(sec1, "Courier New Bold font");

            // Set font name of a specific text segment to courier new
            t1.Segments[0].TextInfo.FontName = "Courier New";

            // Set the font to bold
            t1.Segments[0].TextInfo.IsTrueTypeFontBold = true;
            // ExEnd:TrueTypeBoldFont
            dataDir = dataDir + "TrueTypeBoldFont_out_.pdf";
            // Create the result PDF Document
            pdf1.Save(dataDir);
        }
Beispiel #33
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

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

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

            //Create an image object in the section
            Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1);

            //Add image object into the Paragraphs collection of the section
            sec1.Paragraphs.Add(image1);

            //Set the path of image file
            image1.ImageInfo.File = dataDir + "aspose.jpg";

            //Set the type of image using ImageFileType enumeration
            image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;

            //Set image title
            image1.ImageInfo.Title = "JPEG image";

            //Save the Pdf
            pdf1.Save(dataDir + "jpegOutput.pdf");


            // 2.
            // create a PDF object
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

            // create a section and add it to pdf document
            Aspose.Pdf.Generator.Section MainSection = pdf.Sections.Add();

            //Add the radio form field to the paragraphs collection of the section
            // create an image object
            Aspose.Pdf.Generator.Image sample_image = new Aspose.Pdf.Generator.Image();

            // specify the image file path information
            sample_image.ImageInfo.File = dataDir + "aspose.bmp";

            // specify the image file type
            sample_image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp;

            // specify the image width information equal to page width
            sample_image.ImageInfo.FixWidth = MainSection.PageInfo.PageWidth - MainSection.PageInfo.Margin.Left - MainSection.PageInfo.Margin.Right;

            // specify the image Height information equal to page Height
            sample_image.ImageInfo.FixWidth = MainSection.PageInfo.PageHeight - MainSection.PageInfo.Margin.Top - MainSection.PageInfo.Margin.Bottom;

            // create bitmap image object to load image information
            Bitmap myimage = new Bitmap(dataDir + "aspose.bmp");

            // check if the width of the image file is greater than Page width or not
            if (myimage.Width > MainSection.PageInfo.PageWidth)
            {
                // if the Image width is greater than page width, then set the page orientation to Landscape
                MainSection.IsLandscape = true;
            }
            else
            {
                // if the Image width is less than page width, then set the page orientation to Portrait
                MainSection.IsLandscape = false;
            }

            // add image to paragraphs collection of section
            MainSection.Paragraphs.Add(sample_image);

            // save the resultant PDF
            pdf.Save(dataDir + "resizedBmpOutput.pdf");


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

            //Create a new section in the Pdf object
            Aspose.Pdf.Generator.Section sec3 = pdf1.Sections.Add();

            //Create an image object in the section
            Aspose.Pdf.Generator.Image image3 = new Aspose.Pdf.Generator.Image(sec1);

            //Add image object into the Paragraphs collection of the section
            sec3.Paragraphs.Add(image3);

            //Set the ImageStream information
            image3.ImageInfo.SystemImage = System.Drawing.Image.FromFile(dataDir + "aspose.tif");

            // set the value that all frames of tiff image need be added into PDF document
            image3.ImageInfo.TiffFrame = -1;

            image3.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff;

            //Save the pdf document
            pdf3.Save(dataDir + "tifOutput.pdf");
        }
        /// <summary>
        /// 上传附件转换成PDF
        /// </summary>
        /// <param name="fileFullPath">文件完整路径</param>
        /// <returns>转换后PDF的URL</returns>
        protected static string AttachmentFile2PDF(ref string savePath, ref string fileName, string fileFullPath)
        {
            string ret = string.Empty;

            try
            {
                string fileExt  = Path.GetExtension(fileFullPath).ToLower();
                string filePath = Path.GetFullPath(fileFullPath);
                string pdfFile  = fileFullPath + ".pdf";
                string pdfPath  = fileFullPath.Replace(@"\", @"/") + ".pdf";
                if (!File.Exists(pdfFile))
                {
                    switch (fileExt)
                    {
                    case ".doc":
                    case ".docx":
                    case ".rtf":
                        Aspose.Words.Document doc = new Aspose.Words.Document(fileFullPath);
                        doc.Save(pdfFile, Aspose.Words.SaveFormat.Pdf);
                        ret      = savePath + ".pdf";
                        fileName = fileName + ".pdf";
                        break;

                    case ".xls":
                    case ".xlsx":
                        Aspose.Cells.Workbook excel = new Aspose.Cells.Workbook(fileFullPath);
                        excel.Settings.MemorySetting        = Aspose.Cells.MemorySetting.MemoryPreference;
                        excel.Settings.AutoCompressPictures = true;
                        excel.Settings.EnableMacros         = false;
                        Aspose.Cells.PdfSaveOptions saveOptions = new Aspose.Cells.PdfSaveOptions(Aspose.Cells.SaveFormat.Pdf);
                        saveOptions.OnePagePerSheet  = true;
                        saveOptions.PdfCompression   = Aspose.Cells.Rendering.PdfCompressionCore.Flate;
                        saveOptions.PrintingPageType = Aspose.Cells.PrintingPageType.IgnoreBlank;
                        excel.Save(pdfFile, saveOptions);
                        ret      = savePath + ".pdf";
                        fileName = fileName + ".pdf";
                        break;

                    case ".ppt":
                    case ".pptx":
                        Aspose.Slides.Presentation ppt = new Aspose.Slides.Presentation(fileFullPath);
                        ppt.Save(pdfFile, Aspose.Slides.Export.SaveFormat.Pdf);
                        ret      = savePath + ".pdf";
                        fileName = fileName + ".pdf";
                        break;

                    case ".png":
                    case ".jpg":
                        try
                        {
                            Aspose.Pdf.Generator.Pdf     pdf   = new Aspose.Pdf.Generator.Pdf();
                            Aspose.Pdf.Generator.Section sec   = pdf.Sections.Add();
                            Aspose.Pdf.Generator.Image   image = new Aspose.Pdf.Generator.Image(sec);
                            sec.Paragraphs.Add(image);
                            image.ImageInfo.File = fileFullPath;
                            //image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;
                            pdf.Save(pdfFile);
                        }
                        catch (Exception ex)
                        {
                            if (File.Exists(pdfFile))
                            {
                                File.Delete(pdfFile);
                            }
                            throw ex;
                        }

                        ret      = savePath + ".pdf";
                        fileName = fileName + ".pdf";
                        break;

                    case ".pdf":

                    case ".rar":
                    case ".zip":
                    case ".7z":
                        pdfPath = pdfPath.Substring(0, pdfPath.Length - 4);
                        ret     = savePath;
                        break;
                    }
                }
                return(ret);
            }
            catch (Exception ex)
            {
                ret = string.Empty;
                return(ret);
            }
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);

            if (!IsExists)
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }

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

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

            //Set text color to blue in the whole section
            sec1.TextInfo.Color = new Aspose.Pdf.Generator.Color("Blue");

            //Add 1st paragraph (inheriting the text format settings from the section)
            //to the section
            sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text(sec1, "paragraph 1 "));

            //Add 2nd paragraph (inheriting the text format settings from the section)
            //to the section
            sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text(sec1, "paragraph 2"));

            //Create 3rd paragraph (inheriting the text format settings from the section)
            Aspose.Pdf.Generator.Text t3 = new Aspose.Pdf.Generator.Text(sec1);

            //Create a segment "seg1" in the paragraph "t3"
            Aspose.Pdf.Generator.Segment seg1 = new Aspose.Pdf.Generator.Segment(t3);

            //Assign some content to the segment
            seg1.Content = "paragraph 3 segment 1";

            //Set the color of the segment to red
            seg1.TextInfo.Color = new Aspose.Pdf.Generator.Color("Red");

            //Add segment (with red text color) to the paragraph
            t3.Segments.Add(seg1);

            //Create a new segment "seg2" in the paragraph "t3"
            Aspose.Pdf.Generator.Segment seg2 = new Aspose.Pdf.Generator.Segment(t3);

            //Assign some content to the segment
            seg2.Content = "paragraph 3 segment 2";

            //Set the color of the segment to green
            seg2.TextInfo.Color = new Aspose.Pdf.Generator.Color("Green");

            //Add segment (with green text color) to the paragraph
            t3.Segments.Add(seg2);

            //Add 3rd text paragraph to the section with overridden text format settings
            sec1.Paragraphs.Add(t3);

            //Add 4th paragraph (inheriting the text format settings from the section)
            //to the section
            sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text(sec1, "paragraph 4"));

            Aspose.Pdf.Generator.TextInfo info1 = t3.TextInfo.Clone() as Aspose.Pdf.Generator.TextInfo;

            //Modify the font side to 16 pt
            info1.FontSize = 16;

            //Set TextInfo property of the text paragraph to newly cloned instance "info1"
            t3.TextInfo = info1;

            //save the document
            pdf1.Save(dataDir + "output.pdf");
        }
        public static void Run()
        {
            // ExStart:IntegrateWithDatabase
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Tables();

            DataTable dt = new DataTable("Employee");

            dt.Columns.Add("Employee_ID", typeof(Int32));
            dt.Columns.Add("Employee_Name", typeof(string));
            dt.Columns.Add("Gender", typeof(string));

            // Add 2 rows into the DataTable object programmatically

            DataRow dr = dt.NewRow();

            dr[0] = 1;
            dr[1] = "John Smith";
            dr[2] = "Male";
            dt.Rows.Add(dr);

            dr    = dt.NewRow();
            dr[0] = 2;
            dr[1] = "Mary Miller";
            dr[2] = "Female";
            dt.Rows.Add(dr);

            // Instantiate a Pdf instance
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

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

            // Create a Table object
            Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();


            // Add the Table object in the paragraphs collection of the section
            sec1.Paragraphs.Add(tab1);

            // Set column widths of the table
            tab1.ColumnWidths = "40 100 100 100";

            // Set default cell border of the table using BorderInfo object
            tab1.DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 0.1F);

            // Import data into the Table object from the DataTable created above
            tab1.ImportDataTable(dt, true, 0, 1, 3, 3);

            // Get 1st row from the table
            Aspose.Pdf.Generator.Row row1 = tab1.Rows[0];

            // Iterate through all cells in the row and set their background color to blue
            foreach (Aspose.Pdf.Generator.Cell curCell in row1.Cells)
            {
                curCell.BackgroundColor = new Aspose.Pdf.Generator.Color("Blue");
            }

            // Save the Pdf
            pdf1.Save(dataDir + "IntegrateWithDatabase_out.pdf");
            // ExEnd:IntegrateWithDatabase
        }
Beispiel #37
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //Instantiate PDF instance by calling empty constructor
            Aspose.Pdf.Generator.Pdf pdfConv = new Aspose.Pdf.Generator.Pdf();
            //Create a section in the pdf document
            Aspose.Pdf.Generator.Section sec1 = pdfConv.Sections.Add();

            // Create a Header Section of the PDF file
            Aspose.Pdf.Generator.HeaderFooter header = new Aspose.Pdf.Generator.HeaderFooter(sec1);
            // Set the Odd Header for the PDF file
            sec1.OddHeader = header;
            // set the top margin for the header section
            header.Margin.Top = 20;

            //Instantiate a table object
            Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();
            //Add the table in paragraphs collection of the desired section
            header.Paragraphs.Add(tab1);
            //Set default cell border using BorderInfo object
            tab1.DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 0.1F);
            //Set with column widths of the table
            tab1.ColumnWidths = "60 300";

            Aspose.Pdf.Generator.Image img = new Aspose.Pdf.Generator.Image();
            img.ImageInfo.File          = dataDir + "asposelogo.png";
            img.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Png;

            //Create rows in the table and then cells in the rows
            Aspose.Pdf.Generator.Row row1 = tab1.Rows.Add();

            row1.Cells.Add("Table in Header Section");
            row1.BackgroundColor           = new Aspose.Pdf.Generator.Color("#CCCCCC");
            row1.DefaultCellTextInfo.Color = new Aspose.Pdf.Generator.Color("#6699FF");
            // set the font face for the text in the row
            row1.DefaultCellTextInfo.FontName = "Helvetica";
            // set the row span value for first row as 2
            tab1.Rows[0].Cells[0].ColumnsSpan = 2;

            //Create rows in the table and then cells in the rows
            Aspose.Pdf.Generator.Row row2 = tab1.Rows.Add();
            // set the background color for Row2
            row2.BackgroundColor = new Aspose.Pdf.Generator.Color("#FFFFCC");
            // Add the cell which holds the image
            Aspose.Pdf.Generator.Cell cell2 = row2.Cells.Add();
            // set the image width to 60
            img.ImageInfo.FixWidth = 60;

            Aspose.Pdf.Generator.Text txt2 = new Aspose.Pdf.Generator.Text();
            // Add a text segment to hold image and text together
            Aspose.Pdf.Generator.Segment seg1 = new Aspose.Pdf.Generator.Segment();
            seg1.InlineParagraph = img;
            txt2.Segments.Add(seg1);

            //Add the image to the table cell
            cell2.Paragraphs.Add(txt2);
            row2.Cells.Add("Aspose Logo is looking very lovely !");
            row2.DefaultCellTextInfo.FontName = "Helvetica";
            // set the vertical allignment of the text as center alligned
            row2.Cells[1].VerticalAlignment = Aspose.Pdf.Generator.VerticalAlignmentType.Center;
            row2.Cells[1].Alignment         = Aspose.Pdf.Generator.AlignmentType.Center;

            // save the Pdf file
            pdfConv.Save(dataDir + "Table_in_Header.pdf");
        }
Beispiel #38
0
        /// <summary>
        /// 上传附件转换成PDF
        /// </summary>
        /// <param name="fileFullPath">文件完整路径</param>
        /// <returns>转换后PDF的URL</returns>
        public static string AttachmentFile2PDF(string fileFullPath, string target)
        {
            string ret = string.Empty;

            try
            {
                string fileExt  = Path.GetExtension(fileFullPath).ToLower();
                string filePath = Path.GetFullPath(fileFullPath);
                string pdfFile  = fileFullPath + ".pdf";
                string outFile  = "";
                // string pdfPath = fileFullPath.Replace(ConfigUtil.GetAppConfig("AttachmentPath"), "").Replace(@"\", @"/") + ".pdf";
                string pdfPath = target.Replace(@"\", @"/") + ".pdf";
                if (!File.Exists(pdfFile))
                {
                    switch (fileExt)
                    {
                    case ".doc":
                    case ".docx":
                        Aspose.Words.Document doc = new Aspose.Words.Document(fileFullPath);
                        doc.Save(pdfFile, Aspose.Words.SaveFormat.Pdf);
                        outFile = pdfPath;
                        break;

                    case ".xls":
                    case ".xlsx":
                        Aspose.Cells.Workbook excel = new Aspose.Cells.Workbook(fileFullPath);
                        excel.Settings.MemorySetting        = Aspose.Cells.MemorySetting.MemoryPreference;
                        excel.Settings.AutoCompressPictures = true;
                        excel.Settings.EnableMacros         = false;
                        Aspose.Cells.PdfSaveOptions saveOptions = new Aspose.Cells.PdfSaveOptions(Aspose.Cells.SaveFormat.Pdf);
                        saveOptions.OnePagePerSheet  = true;
                        saveOptions.PdfCompression   = Aspose.Cells.Rendering.PdfCompressionCore.Flate;
                        saveOptions.PrintingPageType = Aspose.Cells.PrintingPageType.IgnoreBlank;
                        excel.Save(pdfFile, saveOptions);
                        outFile = pdfPath;
                        break;

                    case ".ppt":
                    case ".pptx":
                        Aspose.Slides.Presentation ppt = new Aspose.Slides.Presentation(fileFullPath);
                        ppt.Save(pdfFile, Aspose.Slides.Export.SaveFormat.Pdf);
                        outFile = pdfPath;
                        break;

                    case ".png":
                    case ".jpg":
                    case ".jpeg":
                    case ".bmp":
                        try
                        {
                            Aspose.Pdf.Generator.Pdf     pdf   = new Aspose.Pdf.Generator.Pdf();
                            Aspose.Pdf.Generator.Section sec   = pdf.Sections.Add();
                            Aspose.Pdf.Generator.Image   image = new Aspose.Pdf.Generator.Image(sec);
                            sec.Paragraphs.Add(image);
                            image.ImageInfo.File = fileFullPath;
                            // image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;
                            pdf.Save(pdfFile);
                            outFile = pdfPath;
                        }
                        catch (Exception ex)
                        {
                            if (File.Exists(pdfFile))
                            {
                                File.Delete(pdfFile);
                            }
                            throw ex;
                        }


                        break;

                    case ".pdf":
                        pdfPath = pdfPath.Substring(0, pdfPath.Length - 4);
                        outFile = pdfPath;
                        break;
                    }
                }

                return(outFile);
            }
            catch (System.Exception ex)
            {
                ret = string.Empty;
                // LogWriter.GetInstance().ErrOut(ex.ToString());
            }
            return(ret);
        }
        public static void Run()
        {
            // ExStart:NestedTables
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Tables();

            // Instantiate Pdf document object
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
            // Create a section in the Pdf
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

            // Create a table
            Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();

            // Add the table into the paragraphs collection of section
            sec1.Paragraphs.Add(tab1);

            // Set the column widths of the table
            tab1.ColumnWidths = "100 200";

            // Set the default cell border using BorderInfo instance
            tab1.DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All);

            // Add a row into the table
            Aspose.Pdf.Generator.Row row1 = tab1.Rows.Add();

            // Add 1st cell in the row
            row1.Cells.Add("left cell");

            // Add 2nd cell in the row
            Aspose.Pdf.Generator.Cell cell2 = row1.Cells.Add();

            // Create a table to be nested with the reference of 2nd cell in the row
            Aspose.Pdf.Generator.Table tab2 = new Aspose.Pdf.Generator.Table(cell2);

            // Add the nested table into the paragraphs collection of the 2nd cell
            cell2.Paragraphs.Add(tab2);

            // Set the column widths of the nested table
            tab2.ColumnWidths = "100 100";

            // Create 1st row in the nested table
            Aspose.Pdf.Generator.Row row21 = tab2.Rows.Add();

            // Create 1st cell in the 1st row of the nested table
            Aspose.Pdf.Generator.Cell cell21 = row21.Cells.Add("top cell");

            // Set the column span of the 1st cell (in the 1st row of the nested table) to 2
            cell21.ColumnsSpan = 2;

            // Create 2nd row in the nested table
            Aspose.Pdf.Generator.Row row22 = tab2.Rows.Add();

            // Create 1st cell in the 2nd row of the nested table
            row22.Cells.Add("left bottom cell");

            // Create 2nd cell in the 2nd row of the nested table
            row22.Cells.Add("right bottom cell");

            // Save the Pdf
            pdf1.Save(dataDir + "NestedTables_out.pdf");
            // ExEnd:NestedTables
        }
        public static void Run()
        {
            // ExStart:SpecifyHeadingLevel
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Headings();

            // Instntiate the Pdf object by calling its empty constructor
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

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

            /*
             * Create 1st heading in the Pdf object's section with level=1. Then create
             * a text segment and add it in the heading. Set its StartNumber=6 to start
             * the numbering from 6 and onwards. And don't forget to set IsAutoSequence=true.
             * If IsAutoSeguence property is set to true then the heading's sequence is
             * controlled automatically by Aspose.Pdf for .NET. After setting all properties, add
             * heading into the paragraphs collection of the section
             */

            Aspose.Pdf.Generator.Heading heading1 = new Aspose.Pdf.Generator.Heading(pdf1, sec1, 1);
            Aspose.Pdf.Generator.Segment segment1 = new Aspose.Pdf.Generator.Segment(heading1);
            heading1.Segments.Add(segment1);
            segment1.Content        = "Level 1";
            heading1.IsAutoSequence = true;
            heading1.StartNumber    = 6;
            sec1.Paragraphs.Add(heading1);

            /*
             * Create 2nd heading in the Pdf object's section with level=2. Then create
             * a text segment and add it in the heading. And don't forget to set
             * IsAutoSequence=true.If IsAutoSeguence property is set to true then the
             * heading's sequence is controlled automatically by Aspose.Pdf for .NET. After setting
             * all properties, add heading into the paragraphs collection of the section
             */

            Aspose.Pdf.Generator.Heading heading2 = new Aspose.Pdf.Generator.Heading(pdf1, sec1, 2);
            Aspose.Pdf.Generator.Segment segment2 = new Aspose.Pdf.Generator.Segment(heading2);
            heading2.Segments.Add(segment2);
            segment2.Content        = "Level 2";
            heading2.IsAutoSequence = true;
            sec1.Paragraphs.Add(heading2);

            /*
             * Create 3rd heading in the Pdf object's section with level=3. Then create
             * a text segment and add it in the heading. And don't forget to set
             * IsAutoSequence=true.If IsAutoSeguence property is set to true then the
             * heading's sequence is controlled automatically by Aspose.Pdf for .NET. After setting
             * all properties, add heading into the paragraphs collection of the section
             */

            Aspose.Pdf.Generator.Heading heading3 = new Aspose.Pdf.Generator.Heading(pdf1, sec1, 3);
            Aspose.Pdf.Generator.Segment segment3 = new Aspose.Pdf.Generator.Segment(heading3);
            heading3.Segments.Add(segment3);
            segment3.Content        = "Level 3";
            heading3.IsAutoSequence = true;
            sec1.Paragraphs.Add(heading3);

            pdf1.Save(dataDir + "SpecifyHeadingLevel_out.pdf");
            // ExEnd:SpecifyHeadingLevel
        }
        public static void Run()
        {
            // ExStart:ApplyingNumber
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Headings();

            // Instntiate the Pdf object by calling its empty constructor
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

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

            /*
             * Create 1st heading in the Pdf object's section with level=1. Then create
             * a text segment and add it in the heading. Set its numbering style to "Arab"
             * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.
             * If IsAutoSeguence property is set to true then the heading's sequence is
             * controlled automatically by Aspose.Pdf. After setting all properties, add
             * heading into the paragraphs collection of the section
             */

            Aspose.Pdf.Generator.Heading heading1 = new Aspose.Pdf.Generator.Heading(pdf1, sec1, 1);
            Aspose.Pdf.Generator.Segment segment1 = new Aspose.Pdf.Generator.Segment(heading1);
            heading1.Segments.Add(segment1);
            segment1.Content        = "Arab";
            heading1.HeadingType    = Aspose.Pdf.Generator.HeadingType.Arab;
            heading1.IsAutoSequence = true;
            sec1.Paragraphs.Add(heading1);

            /*
             * Create 2nd heading in the Pdf object's section with level=1. Then create
             * a text segment and add it in the heading. Set its numbering style to "RomanUpper"
             * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.
             * If IsAutoSeguence property is set to true then the heading's sequence is
             * controlled automatically by Aspose.Pdf for .NET. After setting all properties, add
             * heading into the paragraphs collection of the section
             */

            Aspose.Pdf.Generator.Heading heading2 = new Aspose.Pdf.Generator.Heading(pdf1, sec1, 1);
            Aspose.Pdf.Generator.Segment segment2 = new Aspose.Pdf.Generator.Segment(heading2);
            heading2.Segments.Add(segment2);
            segment2.Content        = "RomanUpper";
            heading2.HeadingType    = Aspose.Pdf.Generator.HeadingType.RomanUpper;
            heading2.IsAutoSequence = true;
            sec1.Paragraphs.Add(heading2);

            /*
             * Create 3rd heading in the Pdf object's section with level=1. Then create
             * a text segment and add it in the heading. Set its numbering style to "RomanLower"
             * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.
             * If IsAutoSeguence property is set to true then the heading's sequence is
             * controlled automatically by Aspose.Pdf for .NET. After setting all properties, add
             * heading into the paragraphs collection of the section
             */

            Aspose.Pdf.Generator.Heading heading3 = new Aspose.Pdf.Generator.Heading(pdf1, sec1, 1);
            Aspose.Pdf.Generator.Segment segment3 = new Aspose.Pdf.Generator.Segment(heading3);
            heading3.Segments.Add(segment3);
            segment3.Content        = "RomanLower";
            heading3.HeadingType    = Aspose.Pdf.Generator.HeadingType.RomanLower;
            heading3.IsAutoSequence = true;
            sec1.Paragraphs.Add(heading3);

            /*
             * Create 4th heading in the Pdf object's section with level=1. Then create a
             * text segment and add it in the heading. Set its numbering style to "EnglishUpper"
             * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.
             * If IsAutoSeguence property is set to true then the heading's sequence is
             * controlled automatically by Aspose.Pdf for .NET. After setting all properties, add
             * heading into the paragraphs collection of the section
             */

            Aspose.Pdf.Generator.Heading heading4 = new Aspose.Pdf.Generator.Heading(pdf1, sec1, 1);
            Aspose.Pdf.Generator.Segment segment4 = new Aspose.Pdf.Generator.Segment(heading4);
            heading4.Segments.Add(segment4);
            segment4.Content        = "EnglishUpper";
            heading4.HeadingType    = Aspose.Pdf.Generator.HeadingType.EnglishUpper;
            heading4.IsAutoSequence = true;
            sec1.Paragraphs.Add(heading4);

            /*
             * Create 5th heading in the Pdf object's section with level=1. Then create a
             * text segment and add it in the heading. Set its numbering style to "EnglishLower"
             * using HeadingType enumeration. And don't forget to set IsAutoSequence=true.
             * If IsAutoSeguence property is set to true then the heading's sequence is
             * controlled automatically by Aspose.Pdf for .NET. After setting all properties, add
             * heading into the paragraphs collection of the section
             */

            Aspose.Pdf.Generator.Heading heading5 = new Aspose.Pdf.Generator.Heading(pdf1, sec1, 1);
            Aspose.Pdf.Generator.Segment segment5 = new Aspose.Pdf.Generator.Segment(heading5);
            heading5.Segments.Add(segment5);
            segment5.Content        = "EnglishLower";
            heading5.HeadingType    = Aspose.Pdf.Generator.HeadingType.EnglishLower;
            heading5.IsAutoSequence = true;
            sec1.Paragraphs.Add(heading5);
            pdf1.Save(dataDir + "headings_out.pdf");
            // ExEnd:ApplyingNumber
        }
Beispiel #42
0
        public static void Run()
        {
            // ExStart:AdvancedHeaderAndFooter
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Sections();

            // Instantiate a PDF Object
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

            // Create a Section object by calling Add method of Sections collection of Pdf class
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

            // Instantiate First HeaderFooter object and pass the Section reference in which
            // The header or footer is to be added
            Aspose.Pdf.Generator.HeaderFooter hf1 = new Aspose.Pdf.Generator.HeaderFooter(sec1);

            // Set the header of odd pages of the PDF document
            sec1.OddHeader = hf1;

            // Set the header of even pages of the PDF document
            sec1.EvenHeader = hf1;

            // Enable this header for first page only
            hf1.IsFirstPageOnly = true;

            // Add Distance From Edge Property to 80 unit Points
            hf1.DistanceFromEdge = 80;

            // Set the First HeaderFooter, top and bottom property respectively
            hf1.Margin.Bottom = 50;
            hf1.Margin.Top    = 100;

            // Instantiate a Text paragraph that will store the content to show as header
            Aspose.Pdf.Generator.Text text = new Aspose.Pdf.Generator.Text(hf1, "header for first page");

            // Add the text object to the Paragraphs collection of HeaderFooter object to
            // Display header on the pages of PDF document
            hf1.Paragraphs.Add(text);

            /*
             * Second Header "hf2" for odd subsequent pages only
             */

            // Instantiate Second HeaderFooter object and pass the Section reference in which
            // The header or footer is to be added
            Aspose.Pdf.Generator.HeaderFooter hf2 = new Aspose.Pdf.Generator.HeaderFooter(sec1);

            // Set the additional header of odd pages of the PDF document
            sec1.AdditionalOddHeader = hf2;

            // Enable this header for subsequent page only
            hf2.IsSubsequentPagesOnly = true;

            // Add Distance From Edge Property of header to 150 unit Points
            hf2.DistanceFromEdge = 150;
            hf2.Margin.Bottom    = 70;

            // Instantiate a Text paragraph that will store the content to show as header
            text = new Aspose.Pdf.Generator.Text(hf2, "odd header for subsequent pages");

            // Add the text object to the Paragraphs collection of HeaderFooter object to
            // Display header on the pages of PDF document
            hf2.Paragraphs.Add(text);

            /*
             * Third Header "hf3" for even subsequent pages only
             */

            // Instantiate Third HeaderFooter object and pass the Section reference in which
            // The header or footer is to be added
            Aspose.Pdf.Generator.HeaderFooter hf3 = new Aspose.Pdf.Generator.HeaderFooter(sec1);

            // Set the additional header of even pages of the PDF document
            sec1.AdditionalEvenHeader = hf3;

            // Enable this header for subsequent page only
            hf3.IsSubsequentPagesOnly = true;

            // Add the Distance from Edge for the third Header
            hf3.DistanceFromEdge = 180;
            hf3.Margin.Top       = 90;

            // Instantiate a Text paragraph that will store the content to show as header
            text = new Aspose.Pdf.Generator.Text(hf3, "even header for subsequent pages");

            // Add the text object to the Paragraphs collection of HeaderFooter object to
            // Display header on the pages of PDF document
            hf3.Paragraphs.Add(text);

            // ExEnd:SetHeaderAndFooter
            dataDir = dataDir + "AdvancedHeaderAndFooter_out.pdf";

            // Save Pdf Document
            pdf1.Save(dataDir);
            // ExEnd:AdvancedHeaderAndFooter
            Console.WriteLine("\nAdvanced header and footer setup successfully.\nFile saved at " + dataDir);
        }
Beispiel #43
0
        private void ConvertToPDF_Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Document doc = e_For_ConvertToPDF_Worker.Result as Document;

            if (!OneFileSave.Checked)
            {
                Util.Save(doc, "學生在校成績證明書", Preference.ConvertToPDF);
            }
            else
            {
                int i = 0;

                foreach (Section section in doc.Sections)
                {
                    // 依照 學號_身分字號_班級_座號_姓名 .doc 來存檔
                    string fileName = "";

                    Document document = new Document();
                    document.Sections.Clear();
                    document.Sections.Add(document.ImportNode(section, true));

                    fileName = PrintStudents[i].StudentNumber;

                    fileName += "_" + PrintStudents[i].IDNumber;

                    if (!string.IsNullOrEmpty(PrintStudents[i].RefClassID))
                    {
                        fileName += "_" + PrintStudents[i].Class.Name;
                    }
                    else
                    {
                        fileName += "_";
                    }

                    fileName += "_" + PrintStudents[i].SeatNo;

                    fileName += "_" + PrintStudents[i].Name;

                    //document.Save(fbd.SelectedPath + "\\" +fileName+ ".doc");

                    if (Preference.ConvertToPDF)
                    {
                        //string fPath = fbd.SelectedPath + "\\" + fileName + ".pdf";

                        string fPath = fbdPath + "\\" + fileName + ".pdf";

                        FileInfo fi = new FileInfo(fPath);

                        DirectoryInfo folder = new DirectoryInfo(Path.Combine(fi.DirectoryName, Path.GetRandomFileName()));
                        if (!folder.Exists)
                        {
                            folder.Create();
                        }

                        FileInfo fileinfo = new FileInfo(Path.Combine(folder.FullName, fi.Name));

                        string XmlFileName = fileinfo.FullName.Substring(0, fileinfo.FullName.Length - fileinfo.Extension.Length) + ".xml";
                        string PDFFileName = fileinfo.FullName.Substring(0, fileinfo.FullName.Length - fileinfo.Extension.Length) + ".pdf";

                        document.Save(XmlFileName, Aspose.Words.SaveFormat.Pdf);

                        Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

                        pdf1.BindXML(XmlFileName, null);
                        pdf1.Save(PDFFileName);

                        if (File.Exists(fPath))
                        {
                            File.Delete(Path.Combine(fi.DirectoryName, fi.Name));
                        }

                        File.Move(PDFFileName, fPath);
                        folder.Delete(true);

                        int percent = (((i + 1) * 100 / doc.Sections.Count));

                        ConvertToPDF_Worker.ReportProgress(percent, "PDF轉換中...進行到" + (i + 1) + "/" + doc.Sections.Count + "個檔案");
                    }
                    else
                    {
                        document.Save(fbdPath + "\\" + fileName + ".doc");

                        int percent = (((i + 1) * 100 / doc.Sections.Count));

                        ConvertToPDF_Worker.ReportProgress(percent, "Doc存檔...進行到" + (i + 1) + "/" + doc.Sections.Count + "個檔案");
                    }

                    i++;
                }
            }
        }
Beispiel #44
0
        private void MasterWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            Util.EnableControls(this);

            if (Preference.SpiltPDF)
            {
                Dictionary <string, Document> dataDict = e.Result as Dictionary <string, Document>;

                FolderBrowserDialog fbd = new FolderBrowserDialog();
                fbd.Description         = "請選擇儲存資料夾";
                fbd.ShowNewFolderButton = true;

                if (fbd.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }
                if (Preference.ConvertToPDF)
                {
                    MotherForm.SetStatusBarMessage("轉換成 PDF 格式中...");
                    foreach (string each in dataDict.Keys)
                    {
                        #region 處理產生 PDF

                        string fPath = fbd.SelectedPath + "\\" + each + ".pdf";

                        FileInfo fi = new FileInfo(fPath);

                        DirectoryInfo folder = new DirectoryInfo(Path.Combine(fi.DirectoryName, Path.GetRandomFileName()));
                        if (!folder.Exists)
                        {
                            folder.Create();
                        }

                        FileInfo fileinfo = new FileInfo(Path.Combine(folder.FullName, fi.Name));

                        string XmlFileName = fileinfo.FullName.Substring(0, fileinfo.FullName.Length - fileinfo.Extension.Length) + ".xml";
                        string PDFFileName = fileinfo.FullName.Substring(0, fileinfo.FullName.Length - fileinfo.Extension.Length) + ".pdf";

                        dataDict[each].Save(XmlFileName, Aspose.Words.SaveFormat.Pdf);

                        Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

                        pdf1.BindXML(XmlFileName, null);
                        pdf1.Save(PDFFileName);

                        if (File.Exists(fPath))
                        {
                            File.Delete(Path.Combine(fi.DirectoryName, fi.Name));
                        }

                        File.Move(PDFFileName, fPath);
                        folder.Delete(true);
                        #endregion
                    }
                }
                else
                {
                    MotherForm.SetStatusBarMessage("儲存中...");
                    foreach (string each in dataDict.Keys)
                    {
                        #region 處理產生 Doc

                        string fPath = fbd.SelectedPath + "\\" + each + ".doc";
                        dataDict[each].Save(fPath, Aspose.Words.SaveFormat.Doc);
                        #endregion
                    }
                }

                MotherForm.SetStatusBarMessage("產生完成");
                System.Diagnostics.Process.Start(fbd.SelectedPath);
            }
            else
            {
                Document doc = e.Result as Document;
                Util.Save(doc, "學生在校成績證明書_英文", Preference.ConvertToPDF);
            }
        }
Beispiel #45
0
        public static void Run()
        {
            // ExStart:RoundedCornerTable
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Tables();

            // Instantiate Pdf object
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

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

            // Instantiate a table object
            Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();

            // Add the table in paragraphs collection of the desired section
            sec1.Paragraphs.Add(tab1);

            // Set with column widths of the table
            tab1.ColumnWidths = "100";

            // Set fixed table row height
            tab1.FixedHeight = 30;

            // Create a blank BorderInfo object
            Aspose.Pdf.Generator.BorderInfo bInfo = new Aspose.Pdf.Generator.BorderInfo();

            // Create a GraphInfo object without any argument to its constructor
            Aspose.Pdf.Generator.GraphInfo gInfo = new Aspose.Pdf.Generator.GraphInfo();

            // Set the corner radius for GraphInfo
            gInfo.CornerRadius = 15F;

            // Specify the line color information
            gInfo.Color = new Aspose.Pdf.Generator.Color("Red");

            // Set the rounded corner table border
            bInfo.Round = gInfo;

            // Specify the Corner style for table border as Round
            tab1.CornerStyle = Aspose.Pdf.Generator.BorderCornerStyle.Round;

            // Set the table border information
            tab1.Border = bInfo;

            // Create rows in the table and then cells in the rows
            Aspose.Pdf.Generator.Row row1 = tab1.Rows.Add();

            // Add sample string to paragraphs collection of table cell
            row1.Cells.Add("Hello World...");

            // Set the vertical alignment of text as center aligned
            row1.Cells[0].DefaultCellTextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Center;

            // Set the horizontal alignment of text as center aligned
            row1.Cells[0].VerticalAlignment = Aspose.Pdf.Generator.VerticalAlignmentType.Center;

            // Save the Pdf
            pdf1.Save(dataDir + "Rounded_Corner-Table_out.pdf");
            // ExEnd:RoundedCornerTable
        }
        public static void Run()
        {
            // ExStart:ChangeTextFormat
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Text();

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

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

            // Set text color to blue in the whole section
            sec1.TextInfo.Color = new Aspose.Pdf.Generator.Color("Blue");

            // Add 1st paragraph (inheriting the text format settings from the section)
            // to the section
            sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text(sec1, "paragraph 1 "));

            // Add 2nd paragraph (inheriting the text format settings from the section)
            // to the section
            sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text(sec1, "paragraph 2"));

            // Create 3rd paragraph (inheriting the text format settings from the section)
            Aspose.Pdf.Generator.Text t3 = new Aspose.Pdf.Generator.Text(sec1);

            // Create a segment "seg1" in the paragraph "t3"
            Aspose.Pdf.Generator.Segment seg1 = new Aspose.Pdf.Generator.Segment(t3);

            // Assign some content to the segment
            seg1.Content = "paragraph 3 segment 1";

            // Set the color of the segment to red
            seg1.TextInfo.Color = new Aspose.Pdf.Generator.Color("Red");

            // Add segment (with red text color) to the paragraph
            t3.Segments.Add(seg1);

            // Create a new segment "seg2" in the paragraph "t3"
            Aspose.Pdf.Generator.Segment seg2 = new Aspose.Pdf.Generator.Segment(t3);

            // Assign some content to the segment
            seg2.Content = "paragraph 3 segment 2";

            // Set the color of the segment to green
            seg2.TextInfo.Color = new Aspose.Pdf.Generator.Color("Green");

            // Add segment (with green text color) to the paragraph
            t3.Segments.Add(seg2);

            // Add 3rd text paragraph to the section with overridden text format settings
            sec1.Paragraphs.Add(t3);

            // Add 4th paragraph (inheriting the text format settings from the section)
            // to the section
            sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text(sec1, "paragraph 4"));

            Aspose.Pdf.Generator.TextInfo info1 = t3.TextInfo.Clone() as Aspose.Pdf.Generator.TextInfo;

            // Modify the font side to 16 pt
            info1.FontSize = 16;

            // Set TextInfo property of the text paragraph to newly cloned instance "info1"
            t3.TextInfo = info1;

            // Save the document
            pdf1.Save(dataDir + "ChangeTextFormat_out_.pdf");
            // ExEnd:ChangeTextFormat
        }
        public static void Run()
        {
            // ExStart:PlacingTextAroundImage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles();

            // Instantiate Pdf document object
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
            // Create a section in the Pdf
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

            // Instantiate a table object
            Aspose.Pdf.Generator.Table table1 = new Aspose.Pdf.Generator.Table();
            // Add the table in paragraphs collection of the desired section
            sec1.Paragraphs.Add(table1);
            // Set with column widths of the table
            table1.ColumnWidths = "120 270";

            // Create MarginInfo object and set its left, bottom, right and top margins
            Aspose.Pdf.Generator.MarginInfo margin = new Aspose.Pdf.Generator.MarginInfo();
            margin.Top    = 5f;
            margin.Left   = 5f;
            margin.Right  = 5f;
            margin.Bottom = 5f;
            // Set the default cell padding to the MarginInfo object
            table1.DefaultCellPadding = margin;

            // Create rows in the table and then cells in the rows
            Aspose.Pdf.Generator.Row row1 = table1.Rows.Add();

            // Create an image object
            Aspose.Pdf.Generator.Image logo = new Aspose.Pdf.Generator.Image();
            // Specify the image file path
            logo.ImageInfo.File = dataDir + "aspose-logo.jpg";
            // Specify the image Fixed Height
            logo.ImageInfo.FixHeight = 120;
            // Specify the image Fixed Width
            logo.ImageInfo.FixWidth = 110;
            row1.Cells.Add();
            // Add the image to paragraphs collection of the table cell
            row1.Cells[0].Paragraphs.Add(logo);

            // Create string variables with text containing html tags
            string TitleString = "<font face=\"Arial\" size=6 color=\"#101090\"><b> Aspose.Pdf for .NET</b></font>";

            // Create a text object to be added to the right of image
            Aspose.Pdf.Generator.Text TitleText = new Aspose.Pdf.Generator.Text(TitleString);
            TitleText.IsHtmlTagSupported = true;
            row1.Cells.Add();
            // Add the text paragraphs containing HTML text to the table cell
            row1.Cells[1].Paragraphs.Add(TitleText);
            // Set the vertical alignment of the row contents as Top
            row1.VerticalAlignment = Aspose.Pdf.Generator.VerticalAlignmentType.Top;

            string BodyString1 = "<font face=\"Arial\" size=2><br/>Aspose.Pdf for .NET is a non-graphical PDF® document reporting component that enables .NET applications to <b> create PDF documents from scratch </b> without utilizing Adobe Acrobat®. Aspose.Pdf for .NET is very affordably priced and offers a wealth of strong features including: compression, tables, graphs, images, hyperlinks, security and custom fonts. </font>";

            // Add a text segment to segments collection of the text object
            TitleText.Segments.Add(BodyString1);

            // Create rows in the table and then cells in the rows
            Aspose.Pdf.Generator.Row SecondRow = table1.Rows.Add();
            SecondRow.Cells.Add();
            // Set the row span value for Second row as 2
            SecondRow.Cells[0].ColumnsSpan = 2;
            // Set the vertical alignment of the second row as Top
            SecondRow.VerticalAlignment = Aspose.Pdf.Generator.VerticalAlignmentType.Top;

            string SecondRowString = "<font face=\"Arial\" size=2>Aspose.Pdf for .NET supports the creation of PDF files through API and XML or XSL-FO templates. Aspose.Pdf for .NET is very easy to use and is provided with 14 fully featured demos written in both C# and Visual Basic.</font>";

            Aspose.Pdf.Generator.Text SecondRowText = new Aspose.Pdf.Generator.Text(SecondRowString);
            SecondRowText.IsHtmlTagSupported = true;
            // Add the text paragraphs containing HTML text to the table cell
            SecondRow.Cells[0].Paragraphs.Add(SecondRowText);
            // Save the Pdf file
            pdf1.Save(dataDir + "PlacingTextAroundImage_out.pdf");
            // ExEnd:PlacingTextAroundImage
        }
        public static void Run()
        {
            // ExStart:CustomizingWatermark
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_UtilityFeatures();

            // Instantiate the Pdf object
            Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

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

            Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text(sec1, "This is text in section1.");
            text1.Left = 30;
            text1.Top  = 100;
            sec1.Paragraphs.Add(text1);
            Aspose.Pdf.Generator.Section sec2  = pdf1.Sections.Add();
            Aspose.Pdf.Generator.Text    text2 = new Aspose.Pdf.Generator.Text(sec2, "This is text in section2.");
            text2.Left = 30;
            text2.Top  = 100;
            sec2.Paragraphs.Add(text2);


            // Setting image watermark
            Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image();
            image1.ImageInfo.File          = dataDir + "aspose-logo.jpg";
            image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;
            image1.ImageScale = 0.1f;
            Aspose.Pdf.Generator.FloatingBox watermark1 = new Aspose.Pdf.Generator.FloatingBox(108, 80);
            watermark1.BoxHorizontalPositioning = Aspose.Pdf.Generator.BoxHorizontalPositioningType.Page;
            watermark1.BoxHorizontalAlignment   = Aspose.Pdf.Generator.BoxHorizontalAlignmentType.Center;
            watermark1.BoxVerticalPositioning   = Aspose.Pdf.Generator.BoxVerticalPositioningType.Page;
            watermark1.BoxVerticalAlignment     = Aspose.Pdf.Generator.BoxVerticalAlignmentType.Center;
            watermark1.Paragraphs.Add(image1);


            // Graph watermark
            Aspose.Pdf.Generator.Graph graph1 = new Aspose.Pdf.Generator.Graph(100, 400);
            float[] posArr = new float[] { 0, 0, 200, 80, 300, 40, 350, 90 };
            Aspose.Pdf.Generator.Curve curve1 = new Aspose.Pdf.Generator.Curve(graph1, posArr);
            graph1.Shapes.Add(curve1);
            Aspose.Pdf.Generator.FloatingBox watermark2 = new Aspose.Pdf.Generator.FloatingBox(108, 80);
            watermark2.Paragraphs.Add(graph1);


            // Text watermark
            Aspose.Pdf.Generator.Text        text3      = new Aspose.Pdf.Generator.Text("Text Watermark");
            Aspose.Pdf.Generator.FloatingBox watermark3 = new Aspose.Pdf.Generator.FloatingBox(108, 80);
            watermark3.Left = 50;
            watermark3.Top  = 500;
            watermark3.Paragraphs.Add(text3);


            pdf1.Watermarks.Add(watermark1);
            pdf1.Watermarks.Add(watermark2);
            pdf1.Watermarks.Add(watermark3);

            dataDir = dataDir + "CustomizingWatermark_out.pdf";
            // Save the Pdf
            pdf1.Save(dataDir);
            // ExEnd:CustomizingWatermark
        }
Beispiel #49
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Text();

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);

            if (!IsExists)
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }


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

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

            //Set text color to blue in the whole section
            sec1.TextInfo.Color = new Aspose.Pdf.Generator.Color("Blue");

            //Add 1st paragraph (inheriting the text format settings from the section)
            //to the section
            sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text(sec1, "paragraph 1 "));

            //Add 2nd paragraph (inheriting the text format settings from the section)
            //to the section
            sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text(sec1, "paragraph 2"));

            //Create 3rd paragraph (inheriting the text format settings from the section)
            Aspose.Pdf.Generator.Text t3 = new Aspose.Pdf.Generator.Text(sec1);

            //Create a segment "seg1" in the paragraph "t3"
            Aspose.Pdf.Generator.Segment seg1 = new Aspose.Pdf.Generator.Segment(t3);

            //Assign some content to the segment
            seg1.Content = "paragraph 3 segment 1";

            //Set the color of the segment to red
            seg1.TextInfo.Color = new Aspose.Pdf.Generator.Color("Red");

            //Add segment (with red text color) to the paragraph
            t3.Segments.Add(seg1);

            //Create a new segment "seg2" in the paragraph "t3"
            Aspose.Pdf.Generator.Segment seg2 = new Aspose.Pdf.Generator.Segment(t3);

            //Assign some content to the segment
            seg2.Content = "paragraph 3 segment 2";

            //Set the color of the segment to green
            seg2.TextInfo.Color = new Aspose.Pdf.Generator.Color("Green");

            //Add segment (with green text color) to the paragraph
            t3.Segments.Add(seg2);

            //Add 3rd text paragraph to the section with overridden text format settings
            sec1.Paragraphs.Add(t3);

            //Add 4th paragraph (inheriting the text format settings from the section)
            //to the section
            sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text(sec1, "paragraph 4"));

            //save the document
            pdf1.Save(dataDir + "InheritTextFormat_out.pdf");
        }
Beispiel #50
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Conversion();

            //Set up your product license.
            //If you just want to evaluate Aspose.Pdf, you can annotate these two lines.
            //License license = new License();
            //license.SetLicense(dataDir + "Aspose.Total.lic");

            //Create a Converter object..
            Aspose.Pdf.Generator.Pdf app;

            System.IO.Stream pdf;
            string           name = "test";
            string           fo   = dataDir + name + ".fo";
            string           xml  = dataDir + name + ".xml";
            string           xsl  = dataDir + name + ".xsl";

            // Create the XmlDocument.
            XmlDocument doc_fo = new XmlDocument();

            doc_fo.Load(new StreamReader(fo));

            XPathDocument doc_xml = new XPathDocument(xml);

            XmlDocument doc_xsl = new XmlDocument();

            doc_xsl.Load(new StreamReader(xsl));


            //1. fo:string2string
            app = new Aspose.Pdf.Generator.Pdf();
            app.BindFO(fo);
            app.Save(dataDir + name + "_fo_sring2string.pdf");

            //2. fo:string2stream
            app = new Aspose.Pdf.Generator.Pdf();
            app.BindFO(fo);
            pdf = new System.IO.FileStream(name + "_fo_string2stream.pdf", System.IO.FileMode.Create);
            app.Save(pdf);

            //3. fo:stream2string
            app = new Aspose.Pdf.Generator.Pdf();
            app.BindFO(doc_fo, doc_xsl);
            //app.BindFO(new System.IO.FileStream(fo, System.IO.FileMode.Open, System.IO.FileAccess.Read));
            app.Save(dataDir + name + "_fo_stream2string.pdf");

            //4. fo:stream2stream
            app = new Aspose.Pdf.Generator.Pdf();
            //app.BindFO(new System.IO.FileStream(fo, System.IO.FileMode.Open, System.IO.FileAccess.Read));
            //pdf = new System.IO.FileStream(name + "_fo_stream2stream.pdf", System.IO.FileMode.Create);
            //app.Save(pdf);


            //5. fo:doc2string
            app = new Aspose.Pdf.Generator.Pdf();
            app.BindFO(doc_fo);
            app.Save(dataDir + name + "_fo_doc2string.pdf");

            //6. fo:doc2stream
            app = new Aspose.Pdf.Generator.Pdf();
            app.BindFO(doc_fo);
            pdf = new System.IO.FileStream(name + "_fo_doc2stream.pdf", System.IO.FileMode.Create);
            app.Save(pdf);

            //7. xml:string2string
            app = new Aspose.Pdf.Generator.Pdf();
            //app.BindFO(xml, xsl);
            app.BindFO(xml);
            app.Save(dataDir + name + "_xml_string2string.pdf");

            //8. xml:string2stream
            app = new Aspose.Pdf.Generator.Pdf();
            app.BindFO(xml);//, xsl);
            pdf = new System.IO.FileStream(name + "_xml_string2stream.pdf", System.IO.FileMode.Create);
            app.Save(pdf);

            //9. xml:doc2string
            //app = new Aspose.Pdf.Generator.Pdf();
            //app.BindFO(doc_xml, xsl);
            //app.Save(dataDir + name + "_xml_doc2string.pdf");

            //10. xml:doc2stream
            app = new Aspose.Pdf.Generator.Pdf();
            //app.BindFO(doc_xml, xsl);
            pdf = new System.IO.FileStream(name + "_xml_doc2stream.pdf", System.IO.FileMode.Create);
            app.Save(pdf);

            //0. An example of how to set the metadata of your generated pdf document
            //If you do not want to set these tedious metadata of pdf, you can set the
            //second parameter of Save method to be "null" simply, as shown in above.

            //At first create a IDictionary to contain your metadata.
            System.Collections.IDictionary metadata = new System.Collections.Hashtable();

            //Then set the various items.
            //If you don't set them, Aspose.Pdf.Fo will set default value.
            //a. title of your pdf doc:
            metadata.Add("Title", "New Title");
            //b. author of your pdf doc:
            metadata.Add("Author", "New Author");
            //c. subject of your pdf doc:
            metadata.Add("Subject", "New Subject");
            //d. keywords of your pdf doc:
            metadata.Add("Keywords", "New Key Words");
            //e. creator of your pdf doc:
            metadata.Add("Creator", "New Creator");
            //f. producer of your pdf doc:
            metadata.Add("Producer", "New Producer");

            //Make this IDictionary be the parameter of Save method, and start converting.
            app = new Aspose.Pdf.Generator.Pdf();
            //app.FoMetaData = metadata;
            app.BindFO(fo);

            app.Save(dataDir + "Test.pdf");
        }
Beispiel #51
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);

            if (!IsExists)
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }

            //Instantiate Pdf instance by calling it empty constructor
            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
            //Create a section in the Pdf object
            pdf.Sections.Add();

            pdf.IsTruetypeFontMapCached = true;
            //Specify the location where to save TruetypeFontMap.xml
            pdf.TruetypeFontMapPath = dataDir + "";

            //Create a text object and pass the string object carrying arabic text in it
            Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text();
            //Create a segment and add it to segments collection of text object
            Aspose.Pdf.Generator.Segment seg0 = text1.Segments.Add();
            //specify contents for segment
            seg0.Content = "أسبوز هو بائع عنصر ال";
            Aspose.Pdf.Generator.Segment seg1 = text1.Segments.Add();
            seg1.Content = ".NET";
            Aspose.Pdf.Generator.Segment seg2 = text1.Segments.Add();
            seg2.Content = "البارز";

            //Enable text alignment from right to left
            seg0.TextInfo.IsRightToLeft = true;
            seg1.TextInfo.IsRightToLeft = false;         //default
            seg2.TextInfo.IsRightToLeft = true;

            //Enable unicode character set for the text segment
            seg0.TextInfo.IsUnicode = true;
            seg1.TextInfo.IsUnicode = true;
            seg2.TextInfo.IsUnicode = true;

            //Set Font Name
            seg0.TextInfo.FontName = "Times New Roman";
            seg1.TextInfo.FontName = "Times New Roman";
            seg2.TextInfo.FontName = "Times New Roman";
            //Set font size
            seg0.TextInfo.FontSize = 14;
            seg1.TextInfo.FontSize = 14;
            seg2.TextInfo.FontSize = 14;

            //Align text to right hand side using AlignmentType enumeration
            //Make the text right aligned(The meaning of Alignment.Left and AlignmentType.Right are //exchanged when processing RTL language).
            text1.TextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Left;

            pdf.Sections[0].Paragraphs.Add(text1);
            pdf.IsRtlInSegmentMode = true;         //default

            pdf.Save(dataDir + "AsposeOutput.pdf");
        }
Beispiel #52
0
        public static void RadioButtonWithCustomPosition()
        {
            // ExStart:RadioButtonWithCustomPosition
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_UtilityFeatures();

            // Instantiate the Pdf document and add a section to it
            Aspose.Pdf.Generator.Pdf     pdf1 = new Aspose.Pdf.Generator.Pdf();
            Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();


            // Create a table, set its column widths and add it to paragraphs collection
            // of the  section
            Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();
            tab1.ColumnWidths = "120 120 120";
            sec1.Paragraphs.Add(tab1);


            // Add a row to the table
            Aspose.Pdf.Generator.Row r1 = tab1.Rows.Add();


            // Add 1st cell to the row, set its padding and set the ID of the first paragraph
            // in the cell to "text1"
            Aspose.Pdf.Generator.Cell c1 = r1.Cells.Add("item1");
            c1.Padding.Left     = 30;
            c1.Paragraphs[0].ID = "text1";


            // Add 2nd cell to the row, set its padding and set the ID of the first paragraph
            // in the cell to "text2"
            Aspose.Pdf.Generator.Cell c2 = r1.Cells.Add("item2");
            c2.Padding.Left     = 30;
            c2.Paragraphs[0].ID = "text2";


            // Add 3rd cell to the row, set its padding and set the ID of the first paragraph
            // in the cell to "text3"
            Aspose.Pdf.Generator.Cell c3 = r1.Cells.Add("item3");
            c3.Padding.Left     = 30;
            c3.Paragraphs[0].ID = "text3";


            // Create a form field of RadioButton type. Set its field name and button color.
            // Then set the index of the radio button value to be checked
            Aspose.Pdf.Generator.FormField radio = new Aspose.Pdf.Generator.FormField();
            radio.FormFieldType           = Aspose.Pdf.Generator.FormFieldType.RadioButton;
            radio.FieldName               = "ARadio";
            radio.ButtonColor             = System.Drawing.Color.FromName("Red");
            radio.RadioButtonCheckedIndex = 0;


            // Create 1st radio button instance and add it to above created radio form field.
            // Set its width and height. The position of the radio button is set to be
            // relative to the paragraph. Link this radio button with the paragraph with ID
            // equal to "text1".
            Aspose.Pdf.Generator.RadioButton bt1 = radio.RadioButtons.Add();
            bt1.ButtonHeight         = 12;
            bt1.ButtonWidth          = 12;
            bt1.PositioningType      = Aspose.Pdf.Generator.PositioningType.ParagraphRelative;
            bt1.ReferenceParagraphID = "text1";
            bt1.Left = -20;
            bt1.Top  = 0;


            // Create 2nd radio button instance and add it to above created radio form field.
            // Set its width and height. The position of the radio button is set to be
            // relative to the paragraph. Link this radio button with the paragraph with ID
            // equal to "text2".
            Aspose.Pdf.Generator.RadioButton bt2 = radio.RadioButtons.Add();
            bt2.ButtonHeight         = 12;
            bt2.ButtonWidth          = 12;
            bt2.PositioningType      = Aspose.Pdf.Generator.PositioningType.ParagraphRelative;
            bt2.ReferenceParagraphID = "text2";
            bt2.Left = -20;
            bt2.Top  = 0;


            // Create 3rd radio button instance and add it to above created radio form field.
            // Set its width and height. The position of the radio button is set to be
            // relative to the paragraph. Link this radio button with the paragraph with ID
            // equal to "text3".
            Aspose.Pdf.Generator.RadioButton bt3 = radio.RadioButtons.Add();
            bt3.ButtonHeight         = 12;
            bt3.ButtonWidth          = 12;
            bt3.PositioningType      = Aspose.Pdf.Generator.PositioningType.ParagraphRelative;
            bt3.ReferenceParagraphID = "text3";
            bt3.Left = -20;
            bt3.Top  = 0;


            // Add the radio form field to the paragraphs collection of the section
            sec1.Paragraphs.Add(radio);

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