public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Conversion(); // Instantiate an object PDF class Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(); // add the section to PDF document sections collection Aspose.Pdf.Generator.Section section = pdf.Sections.Add(); // Read the contents of HTML file into StreamReader object StreamReader r = File.OpenText(dataDir + "Aspose.htm"); //Create text paragraphs containing HTML text Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd()); // enable the property to display HTML contents within their own formatting text2.IsHtmlTagSupported = true; //Add the text paragraphs containing HTML text to the section section.Paragraphs.Add(text2); // Specify the URL which serves as images database //pdf.HtmlInfo.ImgUrl = "D:/pdftest/MemoryStream/"; //Save the pdf document pdf.Save(dataDir + "HTML2pdf.pdf"); }
public static void Run() { // ExStart:SVGToPDF // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Conversion(); // Instantiate Pdf object Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(); // Bind the source SVG file pdf.BindSvg(dataDir + "SVGToPDF.svg"); // Save the resultant PDF document pdf.Save(dataDir + @"SVGToPDF_out_.pdf"); // ExEnd:SVGToPDF }
public static void Run() { // ExStart:PCLToPDF // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Conversion(); // Instantiate Pdf object Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(); // Bind the source PCL file pdf.BindPCL(dataDir + "hidetext.pcl"); // Save the resultant PDF document pdf.Save(dataDir + "PCLToPDF_out.pdf"); // ExEnd:PCLToPDF }
public static void XSLFOToPDFUsingBind() { // ExStart:XSLFOToPDFUsingBind // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Conversion(); // Create pdf document Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(); // Bind FO document with Pdf object pdf.BindFO(dataDir + "XSLFOToPDF.fo"); // Save the PDF document pdf.Save(dataDir + "XSLFOToPDFUsingBind_out.pdf"); // ExEnd:XSLFOToPDFUsingBind }
public static void Run() { // ExStart:WebToPDF // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Conversion(); // The address of the web URL which you need to convert into PDF format string WebUrl = "http:// En.wikipedia.org/wiki/Main_Page"; // Create a Web Request object to connect to remote URL HttpWebRequest request = (HttpWebRequest)WebRequest.Create(WebUrl); // Set the Web Request timeout request.Timeout = 10000; // 10 secs // Retrieve request info headers HttpWebResponse localWebResponse = (HttpWebResponse)request.GetResponse(); // Windows default Code Page (Include System.Text namespace in project) Encoding encoding = Encoding.GetEncoding(1252); // Read the contents of into StreamReader object StreamReader localResponseStream = new StreamReader(localWebResponse.GetResponseStream(), encoding); // Instantiate an object PDF class Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(); // Add the section to PDF document sections collection Aspose.Pdf.Generator.Section section = pdf.Sections.Add(); // Create text paragraphs containing HTML text Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, localResponseStream.ReadToEnd()); // Enable the property to display HTML contents within their own formatting text2.IsHtmlTagSupported = true; // Add the text object containing HTML contents to PD Sections section.Paragraphs.Add(text2); // Specify the URL which serves as images database // Pdf.HtmlInfo.ImgUrl = "http:// En.wikipedia.org/"; // Save the pdf document pdf.Save(dataDir + "WebToPDF_out.pdf"); localWebResponse.Close(); localResponseStream.Close(); // ExEnd:WebToPDF }
public static void Run() { // ExStart:HTMLToPDF // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Conversion(); // Instantiate an object PDF class Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(); // Add the section to PDF document sections collection Aspose.Pdf.Generator.Section section = pdf.Sections.Add(); // Read the contents of HTML file into StreamReader object StreamReader r = File.OpenText(dataDir + "resultant.html"); // Create text paragraphs containing HTML text Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd()); // Enable the property to display HTML contents within their own formatting text2.IsHtmlTagSupported = true; // ExStart:OverwriteFontNames text2.IfHtmlTagSupportedOverwriteHtmlFontNames = true; text2.IfHtmlTagSupportedOverwriteHtmlFontSizes = true; // ExEnd:OverwriteFontNames // Add the text paragraphs containing HTML text to the section section.Paragraphs.Add(text2); // Specify the URL which serves as images database pdf.HtmlInfo.ImgUrl = dataDir; // ExStart:SpecialCharacters // Following properties are added from Aspose.Pdf for .NET 8.4.0 pdf.HtmlInfo.BadHtmlHandlingStrategy = BadHtmlHandlingStrategy.TreatAsPlainText; pdf.HtmlInfo.ShowUnknownHtmlTagsAsText = true; // ExEnd:SpecialCharacters // Save the Pdf document pdf.Save(dataDir + "HTML2pdf_out_.pdf"); // ExEnd:HTMLToPDF }
public static void Run() { // ExStart:HTMLToPDFUsingStream // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Conversion(); // Instantiate Pdf object Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf(); // Specify the Character encoding for HTML file pdf.HtmlInfo.CharSet = "UTF-8"; pdf.HtmlInfo.CharsetApplyingLevelOfForce = HtmlInfo.CharsetApplyingForceLevel.UseWhenImpossibleDetectFromContent; // Load the HTML file to Stream object using (Stream htmlAsStream = System.IO.File.OpenRead(dataDir + "resultant.html")) { // Bind the source HTML pdf.BindHTML(htmlAsStream, ""); } // Save the PDF file pdf.Save(dataDir + "HTMLToPDFUsingStream_out.pdf"); // ExEnd:HTMLToPDFUsingStream }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_Conversion(); //Set up your product license. //If you just want to evaluate Aspose.Pdf, you can annotate these two lines. //License license = new License(); //license.SetLicense(dataDir + "Aspose.Total.lic"); //Create a Converter object.. Aspose.Pdf.Generator.Pdf app; System.IO.Stream pdf; string name = "test"; string fo = dataDir + name + ".fo"; string xml = dataDir + name + ".xml"; string xsl = dataDir + name + ".xsl"; // Create the XmlDocument. XmlDocument doc_fo = new XmlDocument(); doc_fo.Load(new StreamReader(fo)); XPathDocument doc_xml = new XPathDocument(xml); XmlDocument doc_xsl = new XmlDocument(); doc_xsl.Load(new StreamReader(xsl)); //1. fo:string2string app = new Aspose.Pdf.Generator.Pdf(); app.BindFO(fo); app.Save(dataDir + name + "_fo_sring2string.pdf"); //2. fo:string2stream app = new Aspose.Pdf.Generator.Pdf(); app.BindFO(fo); pdf = new System.IO.FileStream(name + "_fo_string2stream.pdf", System.IO.FileMode.Create); app.Save(pdf); //3. fo:stream2string app = new Aspose.Pdf.Generator.Pdf(); app.BindFO(doc_fo, doc_xsl); //app.BindFO(new System.IO.FileStream(fo, System.IO.FileMode.Open, System.IO.FileAccess.Read)); app.Save(dataDir + name + "_fo_stream2string.pdf"); //4. fo:stream2stream app = new Aspose.Pdf.Generator.Pdf(); //app.BindFO(new System.IO.FileStream(fo, System.IO.FileMode.Open, System.IO.FileAccess.Read)); //pdf = new System.IO.FileStream(name + "_fo_stream2stream.pdf", System.IO.FileMode.Create); //app.Save(pdf); //5. fo:doc2string app = new Aspose.Pdf.Generator.Pdf(); app.BindFO(doc_fo); app.Save(dataDir + name + "_fo_doc2string.pdf"); //6. fo:doc2stream app = new Aspose.Pdf.Generator.Pdf(); app.BindFO(doc_fo); pdf = new System.IO.FileStream(name + "_fo_doc2stream.pdf", System.IO.FileMode.Create); app.Save(pdf); //7. xml:string2string app = new Aspose.Pdf.Generator.Pdf(); //app.BindFO(xml, xsl); app.BindFO(xml); app.Save(dataDir + name + "_xml_string2string.pdf"); //8. xml:string2stream app = new Aspose.Pdf.Generator.Pdf(); app.BindFO(xml);//, xsl); pdf = new System.IO.FileStream(name + "_xml_string2stream.pdf", System.IO.FileMode.Create); app.Save(pdf); //9. xml:doc2string //app = new Aspose.Pdf.Generator.Pdf(); //app.BindFO(doc_xml, xsl); //app.Save(dataDir + name + "_xml_doc2string.pdf"); //10. xml:doc2stream app = new Aspose.Pdf.Generator.Pdf(); //app.BindFO(doc_xml, xsl); pdf = new System.IO.FileStream(name + "_xml_doc2stream.pdf", System.IO.FileMode.Create); app.Save(pdf); //0. An example of how to set the metadata of your generated pdf document //If you do not want to set these tedious metadata of pdf, you can set the //second parameter of Save method to be "null" simply, as shown in above. //At first create a IDictionary to contain your metadata. System.Collections.IDictionary metadata = new System.Collections.Hashtable(); //Then set the various items. //If you don't set them, Aspose.Pdf.Fo will set default value. //a. title of your pdf doc: metadata.Add("Title", "New Title"); //b. author of your pdf doc: metadata.Add("Author", "New Author"); //c. subject of your pdf doc: metadata.Add("Subject", "New Subject"); //d. keywords of your pdf doc: metadata.Add("Keywords", "New Key Words"); //e. creator of your pdf doc: metadata.Add("Creator", "New Creator"); //f. producer of your pdf doc: metadata.Add("Producer", "New Producer"); //Make this IDictionary be the parameter of Save method, and start converting. app = new Aspose.Pdf.Generator.Pdf(); //app.FoMetaData = metadata; app.BindFO(fo); app.Save(dataDir + "Test.pdf"); }