public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            // Instantiate Document instance by calling empty constructor
            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();
            // Create a page in the pdf document
            Aspose.Pdf.Page page = pdfDocument.Pages.Add();

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

            // Instantiate a table object
            Aspose.Pdf.Table tab1 = new Aspose.Pdf.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.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
            // Set with column widths of the table
            tab1.ColumnWidths = "60 300";

            Aspose.Pdf.Image img = new Aspose.Pdf.Image();
            img.File = dataDir + "aspose-logo.jpg";

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

            row1.Cells.Add("Table in Header Section");
            row1.BackgroundColor = Color.Gray;
            // Set the row span value for first row as 2
            tab1.Rows[0].Cells[0].ColSpan = 2;
            tab1.Rows[0].Cells[0].DefaultCellTextState.ForegroundColor = Color.Cyan;
            tab1.Rows[0].Cells[0].DefaultCellTextState.Font            = FontRepository.FindFont("Helvetica");
            // Create rows in the table and then cells in the rows
            Aspose.Pdf.Row row2 = tab1.Rows.Add();
            // Set the background color for Row2
            row2.BackgroundColor = Color.White;
            // Add the cell which holds the image
            Aspose.Pdf.Cell cell2 = row2.Cells.Add();
            // Set the image width to 60
            img.FixWidth = 60;

            // Add the image to the table cell
            cell2.Paragraphs.Add(img);
            row2.Cells.Add("Logo is looking fine !");
            row2.Cells[1].DefaultCellTextState.Font = FontRepository.FindFont("Helvetica");
            // Set the vertical allignment of the text as center alligned
            row2.Cells[1].VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center;
            row2.Cells[1].Alignment         = Aspose.Pdf.HorizontalAlignment.Center;

            // Save the Pdf file
            pdfDocument.Save(dataDir + "TableInHeaderFooterSection_out.pdf");
            // ExEnd:1
        }
Exemple #2
0
        public static void Run()
        {
            // ExStart:SetImageSize
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
            // Instantiate Document object
            Document doc = new Document();

            // add page to pages collection of PDF file
            Aspose.Pdf.Page page = doc.Pages.Add();
            // Create an image instance
            Aspose.Pdf.Image img = new Aspose.Pdf.Image();
            // Set Image Width and Height in Points
            img.FixWidth  = 100;
            img.FixHeight = 100;
            // Set image type as SVG
            img.FileType = Aspose.Pdf.ImageFileType.Unknown;
            // Path for source file
            img.File = dataDir + "aspose-logo.jpg";
            page.Paragraphs.Add(img);
            //Set page properties
            page.PageInfo.Width  = 800;
            page.PageInfo.Height = 800;
            dataDir = dataDir + "SetImageSize_out.pdf";
            // save resultant PDF file
            doc.Save(dataDir);
            // ExEnd:SetImageSize
            Console.WriteLine("\nImage size added successfully.\nFile saved at " + dataDir);
        }
Exemple #3
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
            // Create a page in the document object
            Aspose.Pdf.Page page = doc.Pages.Add();

            // Create Header Section of the document
            Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
            // Set the header for the PDF file
            page.Header = header;
            // Create an image object in the page
            Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
            // Set the path of image file
            image1.File = dataDir + "aspose-logo.jpg";
            // Add image to Header page of the Pdf file
            header.Paragraphs.Add(image1);

            // Create a Footer Section of the document
            Aspose.Pdf.HeaderFooter footer = new Aspose.Pdf.HeaderFooter();
            // Set the footer of the PDF file
            page.Footer = footer;
            // Create a Text object
            Aspose.Pdf.Text.TextFragment txt = new Aspose.Pdf.Text.TextFragment("Page: ($p of $P ) ");
            // Add text to Header section of the Pdf file
            footer.Paragraphs.Add(txt);
            // Save the Pdf file
            doc.Save(dataDir + "ImageAndPageNumberInHeaderFooter_out.pdf");
            // ExEnd:1
        }
Exemple #4
0
        public static void Run()
        {
            // ExStart:AddImageinATableCell
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

            // Instantiate a Document object
            Document pdfDocument = new Document();
            // Create a page in the pdf document
            Page sec1 = pdfDocument.Pages.Add();

            // Instantiate a table object
            Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
            // Add the table in paragraphs collection of the desired page
            sec1.Paragraphs.Add(tab1);
            // Set default cell border using BorderInfo object
            tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
            // Set with column widths of the table
            tab1.ColumnWidths = "100 100 120";
            Aspose.Pdf.Image img = new Aspose.Pdf.Image();
            img.File = dataDir + "aspose.jpg";
            // Create rows in the table and then cells in the rows
            Aspose.Pdf.Row row1 = tab1.Rows.Add();
            row1.Cells.Add("Sample text in cell");
            // Add the cell which holds the image
            Aspose.Pdf.Cell cell2 = row1.Cells.Add();
            // Add the image to the table cell
            cell2.Paragraphs.Add(img);
            row1.Cells.Add("Previous cell with image");
            row1.Cells[2].VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center;
            // Save the Document
            pdfDocument.Save(dataDir + "AddImageInTableCell_out.pdf");
            // ExEnd:AddImageinATableCell
        }
        public static void Run()
        {
            // ExStart:ConvertImageStreamtoPDF
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Images();

            // Instantiate Document instance by calling its empty constructor
            Aspose.Pdf.Document pdf1 = new Aspose.Pdf.Document();
            // Add a Page into the pdf document
            Aspose.Pdf.Page sec = pdf1.Pages.Add();

            // Create a FileStream object to read the imag file
            FileStream fs = File.OpenRead(dataDir + "aspose.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
            Aspose.Pdf.Image imageht = new Aspose.Pdf.Image();

            // Specify the image source as MemoryStream
            imageht.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:ConvertImageStreamtoPDF
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

            Aspose.Pdf.Document pdf = new Aspose.Pdf.Document();

            Aspose.Pdf.Page sec1            = pdf.Pages.Add();
            Aspose.Pdf.Text.TextFragment t1 = new Aspose.Pdf.Text.TextFragment("paragraph 3 segment");
            sec1.Paragraphs.Add(t1);

            Aspose.Pdf.Text.TextSegment seg1 = new Aspose.Pdf.Text.TextSegment();
            t1.Text = "paragraph 3 segment 1";
            t1.TextState.ForegroundColor = Color.Red;
            t1.TextState.FontSize        = 12;

            Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
            image1.File = dataDir + "test_image.png";

            Aspose.Pdf.FloatingBox box1 = new Aspose.Pdf.FloatingBox(117, 21);
            sec1.Paragraphs.Add(box1);

            box1.Left = -4;
            box1.Top  = -4;
            box1.Paragraphs.Add(image1);

            pdf.Save(dataDir + "CreateMultiLayerPdf_out.pdf");
            // ExEnd:1
        }
Exemple #7
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

            // Get a list of tiff image files
            string[] files = System.IO.Directory.GetFiles(dataDir, "*.tif");

            // Instantiate a Document object
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document();

            // Navigate through the files and them in the pdf file
            foreach (string myFile in files)
            {
                // Load all tiff files in byte array
                FileStream fs       = new FileStream(myFile, FileMode.Open, FileAccess.Read);
                byte[]     tmpBytes = new byte[fs.Length];
                fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length));

                MemoryStream mystream = new MemoryStream(tmpBytes);
                Bitmap       b        = new Bitmap(mystream);
                // Create a new Page in the Pdf document
                Aspose.Pdf.Page currpage = doc.Pages.Add();

                // Set margins so image will fit, etc.
                currpage.PageInfo.Margin.Top    = 5;
                currpage.PageInfo.Margin.Bottom = 5;
                currpage.PageInfo.Margin.Left   = 5;
                currpage.PageInfo.Margin.Right  = 5;

                currpage.PageInfo.Width  = (b.Width / b.HorizontalResolution) * 72;
                currpage.PageInfo.Height = (b.Height / b.VerticalResolution) * 72;

                // Create an image object
                Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();

                // Add the image into paragraphs collection of the page
                currpage.Paragraphs.Add(image1);

                // Set IsBlackWhite property to true for performance improvement
                image1.IsBlackWhite = true;
                // Set the ImageStream to a MemoryStream object
                image1.ImageStream = mystream;
                // Set desired image scale
                image1.ImageScale = 0.95F;
            }

            // Save the Pdf
            doc.Save(dataDir + "PerformaceImprovement_out.pdf");
            // ExEnd:1
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();

            Aspose.Pdf.Document doc = new Aspose.Pdf.Document();

            // Retrieve names of all the JPG files in a particular Directory
            string[] fileEntries = Directory.GetFiles(dataDir, "*.JPG");

            int counter;

            for (counter = 0; counter < fileEntries.Length - 1; counter++)
            {
                // Create a page object
                Aspose.Pdf.Page page = doc.Pages.Add();

                // Creat an image object
                Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
                image1.File = fileEntries[counter];

                // Create a BitMap object in order to get the information of image file
                Bitmap myimage = new Bitmap(fileEntries[counter]);
                // Check if the width of the image file is greater than Page width or not
                if (myimage.Width > page.PageInfo.Width)
                {
                    // If the Image width is greater than page width, then set the page orientation to Landscape
                    page.PageInfo.IsLandscape = true;
                }
                else
                {
                    // If the Image width is less than page width, then set the page orientation to Portrait
                    page.PageInfo.IsLandscape = false;
                }
                // Add the image to paragraphs collection of the PDF document
                page.Paragraphs.Add(image1);
            }
            // Save the Pdf file
            doc.Save(dataDir + "SetPageOrientation_out.pdf");
            // ExEnd:1
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            // Instantiate a Document object by calling its empty constructor
            Aspose.Pdf.Document pdf1 = new Aspose.Pdf.Document();
            // Create a page in the Pdf object
            Aspose.Pdf.Page page = pdf1.Pages.Add();

            // Create Header Section of the document
            Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
            // Set the header for the PDF file
            page.Header = header;

            // Create a Text object
            Aspose.Pdf.Text.TextFragment txt1 = new Aspose.Pdf.Text.TextFragment("Aspose.Pdf is a Robust component by");
            // Specify the color
            txt1.TextState.ForegroundColor = Color.Blue;
            txt1.IsInLineParagraph         = true;

            // Create an image object in the section
            Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
            // Set the path of image file
            image1.File = dataDir + "aspose-logo.jpg";
            // Set the image width Information
            image1.FixWidth  = 50;
            image1.FixHeight = 20;
            // Indicate seg1's InlineParagraph is a image.
            image1.IsInLineParagraph = true;

            Aspose.Pdf.Text.TextFragment txt2 = new Aspose.Pdf.Text.TextFragment(" Pty Ltd.");
            txt2.IsInLineParagraph         = true;
            txt2.TextState.ForegroundColor = Color.Maroon;
            header.Paragraphs.Add(txt1);
            header.Paragraphs.Add(image1);
            header.Paragraphs.Add(txt2);
            // Save the Pdf
            pdf1.Save(dataDir + "ImageAndPageNumberInHeaderFooter_UsingInlineParagraph_out.pdf");
            // ExEnd:1
        }
Exemple #10
0
        public static void Run()
        {
            // ExStart:2
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

            int   alpha      = 10;
            int   green      = 0;
            int   red        = 100;
            int   blue       = 0;
            Color alphaColor = Color.FromArgb(alpha, red, green, blue);

            Aspose.Pdf.Document doc = new Aspose.Pdf.Document();

            Aspose.Pdf.Page page            = doc.Pages.Add();
            Aspose.Pdf.Text.TextFragment t1 = new Aspose.Pdf.Text.TextFragment("paragraph 3 segment");
            t1.TextState.ForegroundColor = Color.Red;
            t1.IsInLineParagraph         = true;
            t1.TextState.FontSize        = 12;
            Aspose.Pdf.FloatingBox TextFloatingBox1 = new Aspose.Pdf.FloatingBox(117, 21);
            TextFloatingBox1.ZIndex = 1;
            TextFloatingBox1.Left   = -4;
            TextFloatingBox1.Top    = -4;
            page.Paragraphs.Add(TextFloatingBox1);
            TextFloatingBox1.Paragraphs.Add(t1);
            Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
            image1.File = dataDir + "test_image.png";
            Aspose.Pdf.FloatingBox ImageFloatingBox = new Aspose.Pdf.FloatingBox(117, 21);
            page.Paragraphs.Add(ImageFloatingBox);

            ImageFloatingBox.Left   = -4;
            ImageFloatingBox.Top    = -4;
            ImageFloatingBox.ZIndex = 2;
            ImageFloatingBox.Paragraphs.Add(image1);

            doc.Save(dataDir + @"Multilayer-2ndApproach_out.pdf");
            // ExEnd:2
        }
        public void GeneratePDF(SendLetter sendLetter)
        {
            MemoryStream stream = null;

            if (sendLetter.sendLetterFiles != null &&
                sendLetter.sendLetterFiles.Count > 0)
            {
                //Render Letter Content With Files
                Aspose.Pdf.Document contentPdf = new Aspose.Pdf.Document();
                foreach (var file in sendLetter.sendLetterFiles)
                {
                    if (file.File.ContentType.Contains("image"))
                    {
                        Aspose.Pdf.Page page = contentPdf.Pages.Add();
                        Bitmap          b    = new Bitmap(new MemoryStream(file.File.Content));
                        page.PageInfo.Width  = b.Width;
                        page.PageInfo.Height = b.Height;
                        // Set margins so image will fit, etc.
                        page.PageInfo.Margin.Bottom = 0;
                        page.PageInfo.Margin.Top    = 0;
                        page.PageInfo.Margin.Left   = 0;
                        page.PageInfo.Margin.Right  = 0;

                        page.CropBox = new Aspose.Pdf.Rectangle(0, 0, b.Width, b.Height);

                        Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
                        // Add the image into paragraphs collection of the section
                        page.Paragraphs.Add(image1);
                        // Set the image file stream
                        image1.ImageStream = new MemoryStream(file.File.Content);
                    }
                    else if (file.File.ContentType.Contains("pdf"))
                    {
                        //Append pdf to appendages
                        Aspose.Pdf.Document thisPDF = new Aspose.Pdf.Document(new MemoryStream(file.File.Content));
                        contentPdf.Pages.Add(thisPDF.Pages);
                    }
                    else if (file.File.ContentType.Contains("word"))
                    {
                        //Convert to pdf first
                        Document     thisDoc = new Document(new MemoryStream(file.File.Content));
                        MemoryStream temp    = new MemoryStream();
                        thisDoc.Save(temp, SaveFormat.Pdf);
                        //Second append it to appendages
                        Aspose.Pdf.Document thisPDF = new Aspose.Pdf.Document(temp);
                        contentPdf.Pages.Add(thisPDF.Pages);
                    }
                }
                stream = new MemoryStream();
                contentPdf.Save(stream);
                sendLetter.LetterFileContent = stream.ToArray();
            }

            //Debug
            //Aspose.Pdf.Document letterFile = new Aspose.Pdf.Document(stream);
            //letterFile.Save(Server.MapPath("~/LetterOnly.pdf"));


            //Save letter with Appendage
            if (sendLetter.Appendages != null &&
                sendLetter.Appendages.Count > 0)
            {
                Aspose.Pdf.Document appendagePdf = new Aspose.Pdf.Document();
                foreach (var file in sendLetter.Appendages)
                {
                    if (file.File.ContentType.Contains("image"))
                    {
                        Page   page = appendagePdf.Pages.Add();
                        Bitmap b    = new Bitmap(new MemoryStream(file.File.Content));
                        page.PageInfo.Width  = b.Width;
                        page.PageInfo.Height = b.Height;
                        // Set margins so image will fit, etc.
                        page.PageInfo.Margin.Bottom = 0;
                        page.PageInfo.Margin.Top    = 0;
                        page.PageInfo.Margin.Left   = 0;
                        page.PageInfo.Margin.Right  = 0;

                        page.CropBox = new Aspose.Pdf.Rectangle(0, 0, b.Width, b.Height);

                        Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
                        // Add the image into paragraphs collection of the section
                        page.Paragraphs.Add(image1);
                        // Set the image file stream
                        image1.ImageStream = new MemoryStream(file.File.Content);
                    }
                    else if (file.File.ContentType.Contains("pdf"))
                    {
                        //Append pdf to appendages
                        Aspose.Pdf.Document thisPDF = new Aspose.Pdf.Document(new MemoryStream(file.File.Content));
                        appendagePdf.Pages.Add(thisPDF.Pages);
                    }
                    else if (file.File.ContentType.Contains("word"))
                    {
                        //Convert to pdf first
                        Document     thisDoc = new Document(new MemoryStream(file.File.Content));
                        MemoryStream temp    = new MemoryStream();
                        thisDoc.Save(temp, SaveFormat.Pdf);
                        //Second append it to appendages
                        Aspose.Pdf.Document thisPDF = new Aspose.Pdf.Document(temp);
                        appendagePdf.Pages.Add(thisPDF.Pages);
                    }
                }

                //Return PDF from letter
                if (stream != null)
                {
                    Aspose.Pdf.Document letterPdf = new Aspose.Pdf.Document(stream);

                    stream = new MemoryStream();
                    appendagePdf.Save(stream);
                    sendLetter.AppendageContent = stream.ToArray();
                    //Debug
                    //appendagePdf.Save(Server.MapPath("~/AppendagesOnly.pdf"));

                    letterPdf.Pages.Add(appendagePdf.Pages);
                    stream = new MemoryStream();
                    letterPdf.Save(stream);
                    //Debug
                    //letterPdf.Save(Server.MapPath("~/letterWithAppendages.pdf"));

                    sendLetter.LetterFileAppendageContent = stream.ToArray();
                }
                else
                {
                    stream = new MemoryStream();
                    appendagePdf.Save(stream);
                    sendLetter.AppendageContent           = stream.ToArray();
                    sendLetter.LetterFileAppendageContent = stream.ToArray();
                }
            }
        }
        public void GeneratePDF(SendLetter sendLetter, Guid LetterTemplate)
        {
            MemoryStream stream;

            if (sendLetter.sendLetterFiles == null ||
                sendLetter.sendLetterFiles.Count == 0)
            {
                //Create Template and Print letter to Database
                TemplateManager templateManager = new TemplateManager();
                Template        template        = templateManager.Read(LetterTemplate);
                stream = new MemoryStream(template.File.Content);
                if (template != null)
                {
                    Document        doc    = new Document(stream);
                    ReportingEngine engine = new ReportingEngine {
                        Options = ReportBuildOptions.AllowMissingMembers
                    };

                    PrintableSendLetter printableSendLetter = new PrintableSendLetter
                    {
                        DateTime =
                            sendLetter.LetterDateTime.ToPersianTime().toPersianNumber(),
                        Appendage =
                            (sendLetter.Appendages != null &&
                             sendLetter.Appendages.Count > 0)
                                ? "دارد"
                                : "ندارد",
                        Number     = sendLetter.RowNumber.toPersianNumber(),
                        Body       = HttpUtility.HtmlDecode(sendLetter.Body).toPersianNumber(),
                        SenderName = (sendLetter.SenderEmployee?.Employee != null) ? sendLetter.SenderEmployee?.Employee.FullName() : "",
                        //DepartMentName = (sendLetter.SenderEmployee?.Post != null ? sendLetter.SenderEmployee.Post.Name : "") + " " + (sendLetter.SenderEmployee?.Department != null ? sendLetter.SenderEmployee.Department.Name : "")
                        DepartMentName = sendLetter.SenderEmployee?.Post != null?sendLetter.SenderEmployee.Post.Name:""
                    };



                    if (sendLetter.Recievers != null && sendLetter.Recievers.Count > 0 && sendLetter.Recievers.First()?.Person != null)
                    {
                        StringBuilder subtitleStbBuilder = new StringBuilder();

                        subtitleStbBuilder.Append(sendLetter.Recievers.First().Person.Gender == 0
                            ? "سرکار خانم "
                            : "جناب آقاي ");

                        subtitleStbBuilder.Append(sendLetter.Recievers.First().Person.FullName());
                        printableSendLetter.SubTitle = subtitleStbBuilder.ToString();
                    }


                    if (sendLetter.Recievers != null && sendLetter.Recievers.Count > 0 && sendLetter.Recievers.First().Organization != null)
                    {
                        StringBuilder titleStbBuilder = new StringBuilder();
                        titleStbBuilder.Append("");

                        if (sendLetter.Recievers.First().Organization != null)
                        {
                            if (sendLetter.Recievers.First().Post != null)
                            {
                                titleStbBuilder.Append(sendLetter.Recievers.First().Post.Name + " محترم ");

                                titleStbBuilder.Append(sendLetter.Recievers.First().Organization.GetFullOrganizationPath());
                            }


                            printableSendLetter.Title = titleStbBuilder.ToString();
                        }
                    }
                    // Execute the build report.
                    engine.BuildReport(doc, printableSendLetter, "s");

                    //Save letter without Appendage as pdf
                    stream = new MemoryStream();
                    doc.Save(stream, SaveFormat.Pdf);
                    sendLetter.LetterFileContent = stream.ToArray();
                }
                else
                {
                    //Should send error to User
                    throw new Exception("قالب انتخاب شده یافت نگردید");
                }
            }
            else
            {
                //Render Letter Content With Files
                Aspose.Pdf.Document contentPdf = new Aspose.Pdf.Document();
                foreach (var file in sendLetter.sendLetterFiles)
                {
                    if (file.File.ContentType.Contains("image"))
                    {
                        Aspose.Pdf.Page page = contentPdf.Pages.Add();
                        Bitmap          b    = new Bitmap(new MemoryStream(file.File.Content));
                        page.PageInfo.Width  = b.Width;
                        page.PageInfo.Height = b.Height;
                        // Set margins so image will fit, etc.
                        page.PageInfo.Margin.Bottom = 0;
                        page.PageInfo.Margin.Top    = 0;
                        page.PageInfo.Margin.Left   = 0;
                        page.PageInfo.Margin.Right  = 0;

                        page.CropBox = new Aspose.Pdf.Rectangle(0, 0, b.Width, b.Height);

                        Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
                        // Add the image into paragraphs collection of the section
                        page.Paragraphs.Add(image1);
                        // Set the image file stream
                        image1.ImageStream = new MemoryStream(file.File.Content);
                    }
                    else if (file.File.ContentType.Contains("pdf"))
                    {
                        //Append pdf to appendages
                        Aspose.Pdf.Document thisPDF = new Aspose.Pdf.Document(new MemoryStream(file.File.Content));
                        contentPdf.Pages.Add(thisPDF.Pages);
                    }
                    else if (file.File.ContentType.Contains("word"))
                    {
                        //Convert to pdf first
                        Document     thisDoc = new Document(new MemoryStream(file.File.Content));
                        MemoryStream temp    = new MemoryStream();
                        thisDoc.Save(temp, SaveFormat.Pdf);
                        //Second append it to appendages
                        Aspose.Pdf.Document thisPDF = new Aspose.Pdf.Document(temp);
                        contentPdf.Pages.Add(thisPDF.Pages);
                    }
                }
                stream = new MemoryStream();
                contentPdf.Save(stream);
                sendLetter.LetterFileContent = stream.ToArray();
            }

            //Debug
            //Aspose.Pdf.Document letterFile = new Aspose.Pdf.Document(stream);
            //letterFile.Save(Server.MapPath("~/LetterOnly.pdf"));


            //Save letter with Appendage
            if (sendLetter.Appendages != null &&
                sendLetter.Appendages.Count > 0)
            {
                Aspose.Pdf.Document appendagePdf = new Aspose.Pdf.Document();
                foreach (var file in sendLetter.Appendages)
                {
                    if (file.File.ContentType.Contains("image"))
                    {
                        Page   page = appendagePdf.Pages.Add();
                        Bitmap b    = new Bitmap(new MemoryStream(file.File.Content));
                        page.PageInfo.Width  = b.Width;
                        page.PageInfo.Height = b.Height;
                        // Set margins so image will fit, etc.
                        page.PageInfo.Margin.Bottom = 0;
                        page.PageInfo.Margin.Top    = 0;
                        page.PageInfo.Margin.Left   = 0;
                        page.PageInfo.Margin.Right  = 0;

                        page.CropBox = new Aspose.Pdf.Rectangle(0, 0, b.Width, b.Height);

                        Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
                        // Add the image into paragraphs collection of the section
                        page.Paragraphs.Add(image1);
                        // Set the image file stream
                        image1.ImageStream = new MemoryStream(file.File.Content);
                    }
                    else if (file.File.ContentType.Contains("pdf"))
                    {
                        //Append pdf to appendages
                        Aspose.Pdf.Document thisPDF = new Aspose.Pdf.Document(new MemoryStream(file.File.Content));
                        appendagePdf.Pages.Add(thisPDF.Pages);
                    }
                    else if (file.File.ContentType.Contains("word"))
                    {
                        //Convert to pdf first
                        Document     thisDoc = new Document(new MemoryStream(file.File.Content));
                        MemoryStream temp    = new MemoryStream();
                        thisDoc.Save(temp, SaveFormat.Pdf);
                        //Second append it to appendages
                        Aspose.Pdf.Document thisPDF = new Aspose.Pdf.Document(temp);
                        appendagePdf.Pages.Add(thisPDF.Pages);
                    }
                }
                //Return PDF from letter
                Aspose.Pdf.Document letterPdf = new Aspose.Pdf.Document(stream);

                stream = new MemoryStream();
                appendagePdf.Save(stream);
                sendLetter.AppendageContent = stream.ToArray();
                //Debug
                //appendagePdf.Save(Server.MapPath("~/AppendagesOnly.pdf"));

                letterPdf.Pages.Add(appendagePdf.Pages);
                stream = new MemoryStream();
                letterPdf.Save(stream);
                //Debug
                //letterPdf.Save(Server.MapPath("~/letterWithAppendages.pdf"));

                sendLetter.LetterFileAppendageContent = stream.ToArray();
            }
        }
        public static void Run()
        {
            // ExStart:PlacingTextAroundImage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();

            // Instantiate document object
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
            // Create a page in the Pdf
            Aspose.Pdf.Page page = doc.Pages.Add();

            // Instantiate a table object
            Aspose.Pdf.Table table1 = new Aspose.Pdf.Table();
            // Add the table in paragraphs collection of the desired section
            page.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.MarginInfo margin = new Aspose.Pdf.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.Row row1 = table1.Rows.Add();

            // Create an image object
            Aspose.Pdf.Image logo = new Aspose.Pdf.Image();
            // Specify the image file path
            logo.File = dataDir + "aspose-logo.jpg";
            // Specify the image Fixed Height
            logo.FixHeight = 120;
            // Specify the image Fixed Width
            logo.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>";

            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>";

            // Create a text object to be added to the right of image
            Aspose.Pdf.HtmlFragment TitleText = new Aspose.Pdf.HtmlFragment(TitleString + BodyString1);
            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.Cells[1].VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;

            // Create rows in the table and then cells in the rows
            Aspose.Pdf.Row SecondRow = table1.Rows.Add();
            SecondRow.Cells.Add();
            // Set the row span value for Second row as 2
            SecondRow.Cells[0].ColSpan = 2;
            // Set the vertical alignment of the second row as Top
            SecondRow.Cells[0].VerticalAlignment = Aspose.Pdf.VerticalAlignment.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.HtmlFragment SecondRowText = new Aspose.Pdf.HtmlFragment(SecondRowString);
            // Add the text paragraphs containing HTML text to the table cell
            SecondRow.Cells[0].Paragraphs.Add(SecondRowText);
            // Save the Pdf file
            doc.Save(dataDir + "PlacingTextAroundImage_out.pdf");
            // ExEnd:PlacingTextAroundImage
        }