private static void Main(string[] args) { SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); // After purchasing the license, please insert your serial number here to activate the component. //p.Serial = "XXXXXXXXXXX"; //Prepare variables with path. string docxFile = Path.GetFullPath(@"..\..\example.docx"); string pdfFileFromDocx = Path.GetFullPath(@"..\..\exampleResultDocx.pdf"); string rtfFile = Path.GetFullPath(@"..\..\example.rtf"); string pdfFileFromRtf = Path.GetFullPath(@"..\..\exampleResultRtf.pdf"); string htmlFile = Path.GetFullPath(@"..\..\example.htm"); string pdfFileFromHtml = Path.GetFullPath(@"..\..\exampleResultHtml.pdf"); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(Path.GetFullPath(@"..\..\")) { UseShellExecute = true }); // Convert DOCX file to PDF file p.DocxToPdfConvertFile(docxFile, pdfFileFromDocx); // Convert RTF file to PDF file p.RtfToPdfConvertFile(rtfFile, pdfFileFromRtf); // Convert HTML file to PDF file p.HtmlToPdfConvertFile(htmlFile, pdfFileFromHtml); }
static void Main(string[] args) { // How to set a version for the PDF document. SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); // After purchasing the license, please insert your serial number here to activate the component //p.Serial = "XXXXXXXXXXX"; // PDF Metamorphosis .Net generates PDF 1.4 document by default. // Let's change the PDF version to PDF_A. p.PdfSettings.PdfVersion = SautinSoft.PdfMetamorphosis.PdfSetting.PdfVersions.PDF_A; if (p != null) { string rtfPath = @"..\..\example.rtf"; string pdfPath = Path.ChangeExtension(rtfPath, ".pdf"); int i = p.RtfToPdfConvertFile(rtfPath, pdfPath); if (i != 0) { System.Console.WriteLine("An error occurred during converting RTF to PDF!"); } else { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true }); } } }
static void Main(string[] args) { SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); string rtfPath = @"..\..\example.rtf"; string pdfPath = @"..\..\test.pdf"; // Let's create a PDF file from RTF file p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape; //Specify page numbers: {1 of N}, font: Verdana, 18 p.PageSettings.Numbering.Text = "{page} of {numpages}"; p.PageSettings.Numbering.FontFace = "Verdana"; p.PageSettings.Numbering.FontSize = 18; p.RtfToPdfConvertFile(rtfPath, pdfPath); #region split PDF file //Split PDF by pages: 1st, 2nd, 3rd ... p.SplitPDFFileToPDFFolder(pdfPath, Path.GetDirectoryName(pdfPath)); #endregion #region merge PDF files //Merge only 1st and 3rd pages string[] pdfFiles = { @"..\..\test-00001.pdf", @"..\..\test-00003.pdf" }; p.MergePDFFileArrayToPDFFile(pdfFiles, @"..\..\test_Split_and_Merge_1and3page.pdf"); #endregion //Show merged PDF (it doesn't have 2nd page) System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(@"..\..\test_Split_and_Merge_1and3page.pdf") { UseShellExecute = true }); }
static void Main(string[] args) { // This sample shows how to specify page numbers SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); // After purchasing the license, please insert your serial number here to activate the component //p.Serial = "XXXXXXXXXXX"; //Page 1 of N, position: 30 mm from the left of the page p.PageSettings.Numbering.Text = "Page {page} of {numpages}"; p.PageSettings.Numbering.PosX.Mm = 30; p.PageSettings.Numbering.PosY.Mm = 10; p.PageSettings.Numbering.FontFace = "Courier"; p.PageSettings.Numbering.FontSize = 22; if (p != null) { string rtfPath = @"..\..\example.rtf"; string pdfPath = @"..\..\example.pdf"; int i = p.RtfToPdfConvertFile(rtfPath, pdfPath); if (i != 0) { System.Console.WriteLine("An error occurred during converting RTF to PDF!"); } else { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true }); } } }
static void Main(string[] args) { // How to change the page footer to the custom footer SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); // After purchasing the license, please insert your serial number here to activate the component //p.Serial = "XXXXXXXXXXX"; if (p != null) { string inputFile = @"..\..\example.rtf"; string originalPdf = @"..\..\Original.pdf"; string customPdf = @"..\..\CustomFooter.pdf"; // Let's convert RTF which has an own page footer to PDF if (p.RtfToPdfConvertFile(inputFile, originalPdf) == 0) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(originalPdf) { UseShellExecute = true }); } // Let's change the footer to custom string footerInHtml = "<table width=\"100%\" border=\"1\"><tr><td width=\"50%\" align=\"center\"></td><td>This is new custom footer!</td></tr></table>"; p.PageSettings.Footer.FromString(footerInHtml, SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Html); // Let's convert RTF to PDF and change the footer to the custom if (p.RtfToPdfConvertFile(inputFile, customPdf) == 0) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(customPdf) { UseShellExecute = true }); } } }
static void Main(string[] args) { SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); SautinSoft.PdfMetamorphosis.WaterMark w1 = new SautinSoft.PdfMetamorphosis.WaterMark(@"..\..\WaterMark.png"); w1.PosX.Mm = 0; w1.PosX.Mm = 0; w1.PosDX.Mm = 50; w1.PosDY.Mm = 50; p.WaterMarks.Add(w1); SautinSoft.PdfMetamorphosis.WaterMark w2 = p.WaterMarks.Add(); w2.Img = System.Drawing.Image.FromFile(@"..\..\WaterMark.png"); w2.Transparency = 20; w2.PosX.Mm = 60; w2.PosY.Mm = 0; w2.PosDX.Mm = 100; w2.PosDY.Mm = 100; w2.SelectedPages = new int[] { 1 }; if (p != null) { string rtfPath = @"..\..\example.rtf"; string pdfPath = Path.ChangeExtension(rtfPath, ".pdf"); int i = p.RtfToPdfConvertFile(rtfPath, pdfPath); if (i != 0) { System.Console.WriteLine("An error occurred during converting RTF to PDF!"); } else { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true }); } } }
static void Main(string[] args) { // How to set a single font for the whole PDF document. SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); // After purchasing the license, please insert your serial number here to activate the component //p.Serial = "XXXXXXXXXXX"; // Let's make that the all text in PDF became in 'Courier New' font p.TextSettings.FontFace.Custom("Courier New"); // Set also a single font size 10 p.TextSettings.FontSize = 10; // Set also single text color p.TextSettings.FontColor = System.Drawing.Color.FromArgb(33, 150, 150); // Embed all fonts inside PDF. p.PdfSettings.EmbedAllFonts = true; if (p != null) { string rtfPath = @"..\..\example.rtf"; string pdfPath = @"..\..\example.pdf"; int i = p.RtfToPdfConvertFile(rtfPath, pdfPath); if (i != 0) { System.Console.WriteLine("An error occurred during converting RTF to PDF!"); } else { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true }); } } }
static void Main(string[] args) { SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); // After purchasing the license, please insert your serial number here to activate the component //p.Serial = "XXXXXXXXXXX"; // Specify some page options. p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape; // Set page header in HTML format. p.PageSettings.Header.FromString("<b style=\"color: green;\">Sample header in HTML format</b>", SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Html); // Set page footer in RTF format. p.PageSettings.Footer.FromString("{\\rtf1 \\b Bold Footer in RTF format}", SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Rtf); // Set page numbers. p.PageSettings.Numbering.Text = "Page {page} of {numpages}"; if (p != null) { string rtfPath = @"..\..\example.rtf"; string pdfPath = Path.ChangeExtension(rtfPath, ".pdf"); int i = p.RtfToPdfConvertFile(rtfPath, pdfPath); if (i != 0) { System.Console.WriteLine("An error occurred during converting RTF to PDF!"); } else { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true }); } } }
private void buttonConvert_Click(object sender, EventArgs e) { SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); // After purchasing the license, please insert your serial number here to activate the component //p.Serial = "XXXXXXXXXXX"; // Specify some options p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape; // Specify header in HTML format p.PageSettings.Header.FromString("<b>Sample header in HTML format</b>", SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Html); // Specify footer in RTF format p.PageSettings.Footer.FromString(@"{\rtf1\b Bold footer}", SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Rtf); // Specify page numbers p.PageSettings.Numbering.Text = "Page {page} of {numpages}"; if (p != null) { string rtfPath = @"..\..\example.rtf"; string pdfPath = @"..\..\test.pdf"; int i = p.RtfToPdfConvertFile(rtfPath, pdfPath); if (i != 0) { MessageBox.Show("An error occurred during converting RTF to PDF!"); } else { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true }); } } }
static void Main(string[] args) { //How to set page size, orientation and margins SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); //After purchasing the license, please insert your serial number here to activate the component //p.Serial = "XXXXXXXXXXX"; //Let's set: A3, Landscape orientation, left and right margins: 1.5 Inch, top and bottom: 1 Inch p.PageSettings.Size.A3(); p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape; p.PageSettings.MarginLeft.Inch(1.5f); p.PageSettings.MarginRight.Inch(1.5f); p.PageSettings.MarginTop.Inch(1.0f); p.PageSettings.MarginBottom.Inch(1.0f); if (p != null) { string rtfPath = @"..\..\example.rtf"; string pdfPath = Path.ChangeExtension(rtfPath, ".pdf"); int i = p.RtfToPdfConvertFile(rtfPath, pdfPath); if (i != 0) { System.Console.WriteLine("An error occurred during converting RTF to PDF!"); } else { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true }); } } }
//private string GetSubmitActionUrlText(string AAction, string ATradeId, string ARqmtId, string AConfirmId, // string AFaxTelexInd, string AFaxTelexNumber, string AConfirmLabel, string ARequestId) //{ // string urlText = Properties.Settings.Default.TransmissionGatewayCallbackUrl; // try // { // string addr = ""; // for (int i = 0; i < AFaxTelexNumber.Length; i++) // if (AFaxTelexNumber[i] != ' ') // addr += AFaxTelexNumber[i]; // urlText += "?action=" + AAction; // urlText += "&tradeId=" + ATradeId; // urlText += "&tradeRqmtId=" + ARqmtId; // urlText += "&tradeRqmtConfirmId=" + AConfirmId; // urlText += "&faxTelexInd=" + AFaxTelexInd; // urlText += "&addr=" + addr; // urlText += "&label=" + AConfirmLabel; // //Israel 10/6/2015 // //urlText += "&sender=" + toolbarOrWindowsUserId.ToUpper(); // urlText += "&sender=" + Utils.GetUserNameWithoutDomain(toolbarOrWindowsUserId.ToUpper()); // } // catch (Exception ex) // { // throw new Exception("GetSubmitActionUrlText: " + ex.Message); // } // return urlText; //} //Israel 11/13/2015 -- Removed as part of move to XmitRequest/XmitResult //private void CallInsertToFaxLogSent(long ATradeId, string AFaxTelexInd, string AFaxTelexNumber, // string ADocRefCode) //{ // try // { // FaxLogSentDto faxLogSentDto = new FaxLogSentDto(); // faxLogSentDto.TradeId = Convert.ToInt32(ATradeId); // faxLogSentDto.DocType = DOC_TYPE[(int)DocType.CNF]; // faxLogSentDto.Sender = p_UserId; // FaxCode faxCode; // if (AFaxTelexNumber.IndexOf("@") > -1) // faxCode = FaxCode.EMAIL; // else if (AFaxTelexInd == "F") // faxCode = FaxCode.FAX; // else if (AFaxTelexInd == "T") // faxCode = FaxCode.TELEX; // else // throw new Exception("Internal Exception: Unsupported FaxTelexInd=" + AFaxTelexInd); // faxLogSentDto.FaxTelexCode = FAX_CODE[(int)faxCode]; // faxLogSentDto.FaxTelexNumber = AFaxTelexNumber; // faxLogSentDto.DocRefCode = ADocRefCode; // FaxLogSentDal faxLogSentDal = new FaxLogSentDal(sqlConnectionStr); // faxLogSentDal.Insert(faxLogSentDto); // } // catch (Exception ex) // { // throw new Exception("CallInsertToFaxLogSent: " + ex.Message); // } //} private void SaveRtfAsPdfDoc(string ARtfFileName, string APdfFileName) { try { SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis(); //specify Metamorphosis options p.Serial = PDF_METAMORPHOSIS_SERIAL; p.PageStyle.PageOrientation.Portrait(); //p.TextStyle.Header = @"Sample header"; //p.PageStyle.PageNumFormat = "Page {page} of {numpages}"; if (p != null) { int result = p.RtfToPdfConvertFile(ARtfFileName, APdfFileName); //if (result != 0) //throw new Exception("Pdf conversion error"); } } catch (Exception ex) { XtraMessageBox.Show("An error occurred while saving a confirm RTF document as a PDF using the following values:" + Environment.NewLine + "RTF File Name: " + ARtfFileName + ", PDF File Name: " + APdfFileName + Environment.NewLine + "Error CNF-148 in " + FORM_NAME + ".SaveRtfAsPdfDoc(): " + ex.Message, MAIN_FORM_ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); } }