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: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:ImageFromLocalDisk // 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 = dataDir + "aspose-logo.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:ImageFromLocalDisk }
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 SecondApproach() { // ExStart:SecondApproach // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles(); // Create a PDF object Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(); Aspose.Pdf.Generator.Section sec1 = pdf.Sections.Add(); // Create a text object Aspose.Pdf.Generator.Text t1 = new Aspose.Pdf.Generator.Text(sec1); // Create a Floating Box object that will hold image file Aspose.Pdf.Generator.FloatingBox TextFloatingBox1 = new Aspose.Pdf.Generator.FloatingBox(117, 21); // Specify the ZIndex value for TextFloatingBox TextFloatingBox1.ZIndex = 1; TextFloatingBox1.Left = -4; TextFloatingBox1.Top = -4; // Add Floating box to paragraphs collection of Section1 sec1.Paragraphs.Add(TextFloatingBox1); // Add the text object to Paragraphs collection of FloatingBox TextFloatingBox1.Paragraphs.Add(t1); Aspose.Pdf.Generator.Segment seg1 = new Aspose.Pdf.Generator.Segment(t1); // Add the contents for Segment1 seg1.Content = "paragraph 3 segment 1"; // Specify the Font fore color for segement1 seg1.TextInfo.Color = new Aspose.Pdf.Generator.Color("red"); // Specify the font size information for segment1 seg1.TextInfo.FontSize = 12; // Specify the value for Opacity of text. Default is 1.0. Use it for multilayer effect t1.Opacity = 0F; // Add the segment to segments collection of Text1 t1.Segments.Add(seg1); // JPeg image cover the underlayer text Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1); image1.ImageInfo.File = dataDir + "aspose-logo.jpg"; image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; // Create a Floating Box object that will hold image file Aspose.Pdf.Generator.FloatingBox ImageFloatingBox = new Aspose.Pdf.Generator.FloatingBox(117, 21); // Add Floating box to paragraphs collection of Section1 sec1.Paragraphs.Add(ImageFloatingBox); // Specify the left margin of FloatingBox1 ImageFloatingBox.Left = -4; // Specify the Top margin of FloatingBox1 ImageFloatingBox.Top = -4; // Specify the ZIndex of ImageFloatingBox ImageFloatingBox.ZIndex = 2; // Add the image file to paragraphs collection of FloatingBox ImageFloatingBox.Paragraphs.Add(image1); // Save the reusltant PDF document pdf.Save(dataDir + @"Multilayer-2ndApproach_out_.pdf"); // ExEnd:SecondApproach }
public static void Run() { // ExStart:PerformaceImprovement // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles(); // Get a list of tiff image files string[] files = System.IO.Directory.GetFiles(dataDir); // Instantiate a Pdf object Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf(); // 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 section in the Pdf document Aspose.Pdf.Generator.Section sec1 = new Aspose.Pdf.Generator.Section(pdf1); // Set margins so image will fit, etc. sec1.PageInfo.Margin.Top = 5; sec1.PageInfo.Margin.Bottom = 5; sec1.PageInfo.Margin.Left = 5; sec1.PageInfo.Margin.Right = 5; sec1.PageInfo.PageWidth = (b.Width / b.HorizontalResolution) * 72; sec1.PageInfo.PageHeight = (b.Height / b.VerticalResolution) * 72; // Add the section in the sections collection of the Pdf document pdf1.Sections.Add(sec1); // Create an image object Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1); // Add the image into paragraphs collection of the section sec1.Paragraphs.Add(image1); image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff; // Set IsBlackWhite property to true for performance improvement image1.ImageInfo.IsBlackWhite = true; // Set the ImageStream to a MemoryStream object image1.ImageInfo.ImageStream = mystream; // Set desired image scale image1.ImageScale = 0.95F; } // Save the Pdf pdf1.Save(dataDir + "PerformaceImprovement_out.pdf"); // ExEnd:PerformaceImprovement }
public static void Run() { // ExStart:PerformaceImprovement // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles(); // Get a list of tiff image files string[] files = System.IO.Directory.GetFiles(dataDir); // Instantiate a Pdf object Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf(); // 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 section in the Pdf document Aspose.Pdf.Generator.Section sec1 = new Aspose.Pdf.Generator.Section(pdf1); // Set margins so image will fit, etc. sec1.PageInfo.Margin.Top = 5; sec1.PageInfo.Margin.Bottom = 5; sec1.PageInfo.Margin.Left = 5; sec1.PageInfo.Margin.Right = 5; sec1.PageInfo.PageWidth = (b.Width / b.HorizontalResolution) * 72; sec1.PageInfo.PageHeight = (b.Height / b.VerticalResolution) * 72; // Add the section in the sections collection of the Pdf document pdf1.Sections.Add(sec1); // Create an image object Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1); // Add the image into paragraphs collection of the section sec1.Paragraphs.Add(image1); image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff; // Set IsBlackWhite property to true for performance improvement image1.ImageInfo.IsBlackWhite = true; // Set the ImageStream to a MemoryStream object image1.ImageInfo.ImageStream = mystream; // Set desired image scale image1.ImageScale = 0.95F; } // Save the Pdf pdf1.Save(dataDir + "PerformaceImprovement_out_.pdf"); // ExEnd:PerformaceImprovement }
public static void UsingInlineParagraph() { // ExStart:UsingInlineParagraph // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles(); // 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(); //=====================================================// // Header to show an Image inline with text //=====================================================// // Create Header Section of the document Aspose.Pdf.Generator.HeaderFooter header = new Aspose.Pdf.Generator.HeaderFooter(sec1); // Set the Odd header for the PDF file sec1.OddHeader = header; // Set the Even Header for the PDF file sec1.EvenHeader = header; // Create a Text object Aspose.Pdf.Generator.Text txt1 = new Aspose.Pdf.Generator.Text(); // Add text to Header section of the Pdf file header.Paragraphs.Add(txt1); // Add the text string to Segment of text object txt1.Segments.Add("Aspose.Pdf is a Robust component by"); // Specify the color & Font information using TextInfo property txt1.TextInfo.Color = new Aspose.Pdf.Generator.Color("Blue"); txt1.TextInfo.FontName = "Helvetica"; // Create a new segment to be added to text object Aspose.Pdf.Generator.Segment seg1 = txt1.Segments.Add(); // Create an image object in the section Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1); // Set the path of image file image1.ImageInfo.File = dataDir + "aspose-logo.jpg"; // Set the type of image using ImageFileType enumeration image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; // Set the image width Information image1.ImageInfo.FixWidth = 150; // Indicate seg1's InlineParagraph is a image. seg1.InlineParagraph = image1; // Create a new segment to be added to text object Aspose.Pdf.Generator.Segment seg2 = txt1.Segments.Add("Pty Ltd."); seg2.TextInfo.Color = new Aspose.Pdf.Generator.Color("Maroon"); // Save the Pdf pdf1.Save(dataDir + "ImageAndPageNumberInHeaderFooter_UsingInlineParagraph_out.pdf"); // ExEnd:UsingInlineParagraph }
public static void Run() { // ExStart:ImageAndPageNumberInHeaderFooter // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles(); // 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(); //=====================================================// // Header to show an Image //=====================================================// // Create Header Section of the document Aspose.Pdf.Generator.HeaderFooter header = new Aspose.Pdf.Generator.HeaderFooter(sec1); // Set the Odd header for the PDF file sec1.OddHeader = header; // Set the Even Header for the PDF file sec1.EvenHeader = header; // Create an image object in the section Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1); // Set the path of image file image1.ImageInfo.File = dataDir + "aspose-logo.jpg"; // Set the type of image using ImageFileType enumeration image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; // Add image to Header section of the Pdf file header.Paragraphs.Add(image1); //=====================================================// // Footer to show Page Number //=====================================================// // Create a Footer Section of the document Aspose.Pdf.Generator.HeaderFooter footer = new Aspose.Pdf.Generator.HeaderFooter(sec1); // Set the Odd footer of the PDF file sec1.OddFooter = footer; // Set the Even footer of the PDF file sec1.EvenFooter = footer; // Create a Text object Aspose.Pdf.Generator.Text txt = new Aspose.Pdf.Generator.Text("Page: ($p of $P ) "); // Add text to Header section of the Pdf file footer.Paragraphs.Add(txt); // Save the Pdf file pdf1.Save(dataDir + "ImageAndPageNumberInHeaderFooter_out.pdf"); // ExEnd:ImageAndPageNumberInHeaderFooter }
public static void Run() { try { // ExStart:ImageFromMemory // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_General(); // Set the license for Aspose.Pdf Aspose.Pdf.License license = new Aspose.Pdf.License(); license.SetLicense("Aspose.Custom.lic"); // Create a memory stream object System.IO.MemoryStream mstream = new System.IO.MemoryStream(); // Instantiate a Pdf object Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf(); // Create a new section in the Pdf document Aspose.Pdf.Generator.Section sec1 = new Aspose.Pdf.Generator.Section(pdf1); // Add the section in the sections collection of the Pdf document pdf1.Sections.Add(sec1); // Create an image object Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1); // Add the image into paragraphs collection of the section sec1.Paragraphs.Add(image1); image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp; // Set the ImageStream to a MemoryStream object image1.ImageInfo.ImageStream = mstream ; // Set desired the image scale image1.ImageScale = 0.5F; // Save the Pdf pdf1.Save(dataDir + "ImageFromMemory_out.pdf"); // ExEnd:ImageFromMemory } 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:CreateMultiLayerPdf // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles(); // Create a PDF object Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(); Aspose.Pdf.Generator.Section sec1 = pdf.Sections.Add(); // Create a text object Aspose.Pdf.Generator.Text t1 = new Aspose.Pdf.Generator.Text(sec1); // Add the text object to Paragraphs collection of section sec1.Paragraphs.Add(t1); Aspose.Pdf.Generator.Segment seg1 = new Aspose.Pdf.Generator.Segment(t1); // Add the contents for Segment1 seg1.Content = "paragraph 3 segment 1"; // Specify the Font fore color for segement1 seg1.TextInfo.Color = new Aspose.Pdf.Generator.Color("red"); // Specify the font size information for segment1 seg1.TextInfo.FontSize = 12; // Specify the value for Opacity of text. Default is 1.0. Use it for multilayer effect t1.Opacity = 0F; // Add the segment to segments collection of Text1 t1.Segments.Add(seg1); // Jpg image cover the underlayer text Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1); image1.ImageInfo.File = dataDir + "aspose-logo.jpg"; image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; // Create a Floating Box object that will hold image file Aspose.Pdf.Generator.FloatingBox box1 = new Aspose.Pdf.Generator.FloatingBox(117, 21); // Add Floating box to paragraphs collection of Section1 sec1.Paragraphs.Add(box1); // Specify the left margin of FloatingBox1 box1.Left = -4; // Specify the Top margin of FloatingBox1 box1.Top = -4; // Add the image file to paragraphs collection of FloatingBox box1.Paragraphs.Add(image1); // Save the reusltant PDF document pdf.Save(dataDir + "CreateMultiLayerPdf_out.pdf"); // ExEnd:CreateMultiLayerPdf }
public static void Run() { // ExStart:CCITTImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Images(); string faxImageFile = ""; if (faxImageFile != "") { // 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(); // Instantiate an image object Aspose.Pdf.Generator.Image img1 = new Aspose.Pdf.Generator.Image(sec1); // Add image object into the Paragraphs collection of the section sec1.Paragraphs.Add(img1); // Set the path of image file img1.ImageInfo.File = faxImageFile; // Set the file type of the image img1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Ccitt; // Set the image width img1.ImageInfo.CcittImageWidth = 2560; // Set the image height img1.ImageInfo.CcittImageHeight = 1779; // Set the sub-format of the ccitt image img1.ImageInfo.CcittSubFormat = Aspose.Pdf.Generator.CcittSubFormat.Group31D; // Set the desired scaling of the image img1.ImageScale = 0.1F; pdf1.Save(dataDir + "CCITTImage_out_.pdf"); // ExEnd:CCITTImage } else { Console.WriteLine("\nPlease set valid fax image file path."); } }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //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(); //=====================================================// // Header to show an Image //=====================================================// // Create Header Section of the document Aspose.Pdf.Generator.HeaderFooter header = new Aspose.Pdf.Generator.HeaderFooter(sec1); // set the Odd header for the PDF file sec1.OddHeader = header; // Set the Even Header for the PDF file sec1.EvenHeader = header; //Create an image object in the section Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1); //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; //Add image to Header section of the Pdf file header.Paragraphs.Add(image1); //=====================================================// // Footer to show Page Number //=====================================================// // Create a Footer Section of the document Aspose.Pdf.Generator.HeaderFooter footer = new Aspose.Pdf.Generator.HeaderFooter(sec1); // set the Odd footer of the PDF file sec1.OddFooter = footer; // set the Even footer of the PDF file sec1.EvenFooter = footer; // Create a Text object Aspose.Pdf.Generator.Text txt = new Aspose.Pdf.Generator.Text("Page: ($p of $P ) "); // Add text to Header section of the Pdf file footer.Paragraphs.Add(txt); //Save the Pdf pdf1.Save(dataDir + "pdfWithHeaderAndPageNos.pdf"); }
public static void Run() { try { // ExStart:ImageFromMemory // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_General(); // Set the license for Aspose.Pdf Aspose.Pdf.License license = new Aspose.Pdf.License(); license.SetLicense("Aspose.Custom.lic"); // Create a memory stream object System.IO.MemoryStream mstream = new System.IO.MemoryStream(); // Instantiate a Pdf object Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf(); // Create a new section in the Pdf document Aspose.Pdf.Generator.Section sec1 = new Aspose.Pdf.Generator.Section(pdf1); // Add the section in the sections collection of the Pdf document pdf1.Sections.Add(sec1); // Create an image object Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1); // Add the image into paragraphs collection of the section sec1.Paragraphs.Add(image1); image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp; // Set the ImageStream to a MemoryStream object image1.ImageInfo.ImageStream = mstream; // Set desired the image scale image1.ImageScale = 0.5F; // Save the Pdf pdf1.Save(dataDir + "ImageFromMemory_out.pdf"); // ExEnd:ImageFromMemory } 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:CCITTImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Images(); string faxImageFile = ""; if (faxImageFile != "") { // 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(); // Instantiate an image object Aspose.Pdf.Generator.Image img1 = new Aspose.Pdf.Generator.Image(sec1); // Add image object into the Paragraphs collection of the section sec1.Paragraphs.Add(img1); // Set the path of image file img1.ImageInfo.File = faxImageFile; // Set the file type of the image img1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Ccitt; // Set the image width img1.ImageInfo.CcittImageWidth = 2560; // Set the image height img1.ImageInfo.CcittImageHeight = 1779; // Set the sub-format of the ccitt image img1.ImageInfo.CcittSubFormat = Aspose.Pdf.Generator.CcittSubFormat.Group31D; // Set the desired scaling of the image img1.ImageScale = 0.1F; pdf1.Save( dataDir + "CCITTImage_out.pdf"); // ExEnd:CCITTImage } else { Console.WriteLine("\nPlease set valid fax image file path."); } }
public static void Run() { // ExStart:SetPageOrientation // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles(); // Instantiate a Pdf object by calling its empty constructor Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(); // Retrieve names of all the Pdf files in a particular Directory string[] fileEntries = Directory.GetFiles(dataDir, "*.JPG"); int counter; for (counter = 0; counter < fileEntries.Length - 1; counter++) { // Create a section object Aspose.Pdf.Generator.Section section1 = pdf.Sections.Add(); // Creat an image object Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(section1); image1.ImageInfo.File = fileEntries[counter]; image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; // 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 > section1.PageInfo.PageWidth) { // If the Image width is greater than page width, then set the page orientation to Landscape section1.IsLandscape = true; } else { // If the Image width is less than page width, then set the page orientation to Portrait section1.IsLandscape = false; } // Add the image to paragraphs collection of the PDF document section1.Paragraphs.Add(image1); } // Save the Pdf file pdf.Save(dataDir + "SetPageOrientation_out_.pdf"); // ExEnd:SetPageOrientation }
public static void ConvertBMPImageToPdf() { // ExStart:ConvertBMPImageToPdf // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles(); // 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(); // 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 + "barbara_gray.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 + "barbara_gray.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 + "ConvertBMPImageToPdf_out.pdf"); // ExEnd:ConvertBMPImageToPdf }
public static void Run() { // ExStart:SetPageOrientation // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles(); // Instantiate a Pdf object by calling its empty constructor Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(); // Retrieve names of all the Pdf files in a particular Directory string[] fileEntries = Directory.GetFiles(dataDir, "*.JPG"); int counter; for (counter = 0; counter < fileEntries.Length - 1; counter++) { // Create a section object Aspose.Pdf.Generator.Section section1 = pdf.Sections.Add(); // Creat an image object Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(section1); image1.ImageInfo.File = fileEntries[counter]; image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; // 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 > section1.PageInfo.PageWidth) // If the Image width is greater than page width, then set the page orientation to Landscape section1.IsLandscape = true; else // If the Image width is less than page width, then set the page orientation to Portrait section1.IsLandscape = false; // Add the image to paragraphs collection of the PDF document section1.Paragraphs.Add(image1); } // Save the Pdf file pdf.Save(dataDir + "SetPageOrientation_out.pdf"); // ExEnd:SetPageOrientation }
public static void Run() { // ExStart:AddImageInTableCell // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles(); // Instantiate a Pdf object 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(); // 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 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 = "100 100 120"; Aspose.Pdf.Generator.Image img = new Aspose.Pdf.Generator.Image(); img.ImageInfo.File = dataDir + "aspose-logo.jpg"; img.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; // Create rows in the table and then cells in the rows Aspose.Pdf.Generator.Row row1 = tab1.Rows.Add(); row1.Cells.Add("Sample text in cell"); // Add the cell which holds the image Aspose.Pdf.Generator.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.Generator.VerticalAlignmentType.Center; // Save the Pdf file pdfConv.Save(dataDir + "AddImageInTableCell_out_.pdf"); // ExEnd:AddImageInTableCell }
public static void Run() { // ExStart:AddImageInTableCell // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles(); // Instantiate a Pdf object 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(); // 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 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 = "100 100 120"; Aspose.Pdf.Generator.Image img = new Aspose.Pdf.Generator.Image(); img.ImageInfo.File = dataDir + "aspose-logo.jpg"; img.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; // Create rows in the table and then cells in the rows Aspose.Pdf.Generator.Row row1 = tab1.Rows.Add(); row1.Cells.Add("Sample text in cell"); // Add the cell which holds the image Aspose.Pdf.Generator.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.Generator.VerticalAlignmentType.Center; // Save the Pdf file pdfConv.Save(dataDir + "AddImageInTableCell_out.pdf"); // ExEnd:AddImageInTableCell }
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 Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //Create a section in the pdf document 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(); //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 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 = "100 100 120"; Aspose.Pdf.Generator.Image img = new Aspose.Pdf.Generator.Image(); img.ImageInfo.File = dataDir + "aspose.jpg"; img.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; //Create rows in the table and then cells in the rows Aspose.Pdf.Generator.Row row1 = tab1.Rows.Add(); row1.Cells.Add("Sample text in cell"); // Add the cell which holds the image Aspose.Pdf.Generator.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.Generator.VerticalAlignmentType.Center; // save the Pdf file pdfConv.Save(dataDir + "Image_in_Cell.pdf"); }
public static void ConvertBMPImageToPdf() { // ExStart:ConvertBMPImageToPdf // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles(); // 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(); // 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 + "barbara_gray.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 + "barbara_gray.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 + "ConvertBMPImageToPdf_out.pdf"); // ExEnd:ConvertBMPImageToPdf }
/// <summary> /// Processes attachment to the <paramref name="outputStream" />. /// </summary> /// <param name="attachmentData">The attachment data.</param> /// <param name="outputStream">The output stream.</param> protected override void DoProcess(Stream attachmentData, Stream outputStream) { // Read the image into Byte array byte[] data = new byte[attachmentData.Length]; attachmentData.Read(data, 0, (int)attachmentData.Length); Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(); // Add a section into the pdf document Aspose.Pdf.Generator.Section sec = pdf.Sections.Add(); // Create an image object in the section Aspose.Pdf.Generator.Image image = new Aspose.Pdf.Generator.Image(sec); // Set the type of image using ImageFileType enumeration switch (this.fileExtension) { case ".jpg": case ".jpeg": image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; break; case ".gif": image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Gif; break; case ".png": image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Png; break; case ".bmp": image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp; break; case ".tif": image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff; break; } // Create a MemoryStream object from image Byte array MemoryStream ms = new MemoryStream(data); // Specify the image source as MemoryStream image.ImageInfo.ImageStream = ms; // Add image object into the Paragraphs collection of the section sec.Paragraphs.Add(image); // Save the Pdf using (MemoryStream img = new MemoryStream()) { using (var mergedPdf = new Aspose.Pdf.Document(outputStream)) { try { pdf.Save(img); } catch (Exception) { image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp; try { pdf.Save(img); } catch (Exception) { image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff; try { pdf.Save(img); } catch (Exception) { return; } } } Aspose.Pdf.Document imgPdf = new Aspose.Pdf.Document(img); mergedPdf.Pages.Add(imgPdf.Pages); mergedPdf.Save(outputStream); } } // Close the MemoryStream Object ms.Close(); }
public static void UsingInlineParagraph() { // ExStart:UsingInlineParagraph // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_TechnicalArticles(); // 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(); //=====================================================// // Header to show an Image inline with text //=====================================================// // Create Header Section of the document Aspose.Pdf.Generator.HeaderFooter header = new Aspose.Pdf.Generator.HeaderFooter(sec1); // Set the Odd header for the PDF file sec1.OddHeader = header; // Set the Even Header for the PDF file sec1.EvenHeader = header; // Create a Text object Aspose.Pdf.Generator.Text txt1 = new Aspose.Pdf.Generator.Text(); // Add text to Header section of the Pdf file header.Paragraphs.Add(txt1); // Add the text string to Segment of text object txt1.Segments.Add("Aspose.Pdf is a Robust component by"); // Specify the color & Font information using TextInfo property txt1.TextInfo.Color = new Aspose.Pdf.Generator.Color("Blue"); txt1.TextInfo.FontName = "Helvetica"; // Create a new segment to be added to text object Aspose.Pdf.Generator.Segment seg1 = txt1.Segments.Add(); // Create an image object in the section Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1); // Set the path of image file image1.ImageInfo.File = dataDir + "aspose-logo.jpg"; // Set the type of image using ImageFileType enumeration image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; // Set the image width Information image1.ImageInfo.FixWidth = 150; // Indicate seg1's InlineParagraph is a image. seg1.InlineParagraph = image1; // Create a new segment to be added to text object Aspose.Pdf.Generator.Segment seg2 = txt1.Segments.Add("Pty Ltd."); seg2.TextInfo.Color = new Aspose.Pdf.Generator.Color("Maroon"); // Save the Pdf pdf1.Save( dataDir + "ImageAndPageNumberInHeaderFooter_UsingInlineParagraph_out.pdf"); // ExEnd:UsingInlineParagraph }
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 }
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); } }
private static void ConvertTiffToPDF(string pathToTiff, string fileName) { //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 = pathToTiff; //Set the type of image using ImageFileType enumeration image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff; //Set image title image1.ImageInfo.Title = "TIFF image"; //Save the Pdf fileName = fileName.Replace(".tif", ".pdf") .Replace(".tiff", ".pdf") .Replace(".TIF", ".pdf") .Replace(".TIFF", ".pdf"); pdf1.Save(pathToSecondFolder + fileName); File.Delete(pathToTiff); }
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"); }
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"); }
/// <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); }