protected void Page_Load(object sender, EventArgs e) { try { // Create a invoice form with the sample invoice data //InvoiceForm invoice = new InvoiceForm("E:/Projects/BTMU.UNF.Solution/BTMU.UNF.UI.Web/Reports/invoice.xml"); InvoiceForm invoice = new InvoiceForm(@"Reports\invoice.xml"); // Create a MigraDoc document Document document = invoice.CreateDocument(); document.UseCmykColor = true; #if DEBUG // for debugging only... MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl"); document = MigraDoc.DocumentObjectModel.IO.DdlReader.DocumentFromFile("MigraDoc.mdddl"); #endif // Create a renderer for PDF that uses Unicode font encoding PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true); // Set the MigraDoc document pdfRenderer.Document = document; // Create the PDF document pdfRenderer.RenderDocument(); // Save the PDF document... string filename = "Invoice.pdf"; #if DEBUG // I don't want to close the document constantly... filename = "Invoice-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf"; #endif pdfRenderer.Save(path + filename); System.IO.Stream stream = new System.IO.MemoryStream(); pdfRenderer.Save(stream, true); byte[] output = ToByteArry(stream); // zip PDF file(s) // return as byte array // ...and start a viewer. // Process.Start(filename); // open in PDF Viewer } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
public static void CreatePDFReport(string fileName) { // grab the test result set that were reporting on currentResult = GlobalData.allTestReadings[fileName]; // Create the MigraDoc document this will populate the contents Document document = CreateDocument(); // define the pdf renderer object PdfDocumentRenderer renderer = new PdfDocumentRenderer(); // define the document to render renderer.Document = document; // render out the pdf document renderer.RenderDocument(); // Save the document with the date and time on end of string... DateTime currentTime = DateTime.Now; string fileToSave = fileName + "_" + currentTime.ToShortDateString().Replace("/", "") + currentTime.ToShortTimeString().Replace(":", "") + ".pdf"; renderer.Save(GlobalData.pdfOutputFolderPath + "\\" + fileToSave); //renderer = null; //document = null; }
/// <summary> /// Creates and saves a formatted PDF document containing /// </summary> /// <param name="filePath"></param> public void PrintDocument(string filePath) { try { // Create the document using MigraDoc. var document = CreateDocument(); document.UseCmykColor = true; // Create a renderer for PDF that uses Unicode font encoding. var pdfRenderer = new PdfDocumentRenderer(true); // Set the MigraDoc document. pdfRenderer.Document = document; // Create the PDF document. pdfRenderer.RenderDocument(); // Save the PDF document... pdfRenderer.Save(filePath); // ...and start a PDF viewer. Process.Start(filePath); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public override void MakePDF(int fabID) { this.fabID = fabID; // Create a invoice form with the sample invoice data FAB_Registering_Dk pdfForm = new FAB_Registering_Dk(this.fabID); pdfForm.Logo = Logo; // Create a MigraDoc document Document document = pdfForm.CreateDocument(); //document.UseCmykColor = True // Create a renderer for PDF that uses Unicode font encoding PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true); // Set the MigraDoc document pdfRenderer.Document = document; // Create the PDF document pdfRenderer.RenderDocument(); // Save the PDF document... pdfRenderer.Save(PDFfilename); }
public string CreateRawPDFinTemp(Stone stone) { string filename = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(stone.Filename) + ".pdf"); Document document = this.CreateDocument(); DefineStyles(); PlaceImage(stone); PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true); // Set the MigraDoc document pdfRenderer.Document = document; // Create the PDF document pdfRenderer.RenderDocument(); pdfRenderer.Save(filename); if (File.Exists(filename)) { return(filename); } else { return(String.Empty); } // ...and start a viewer. }
public static void verticalBarCode() { string reportFilename = "verticalBarCode.pdf"; Document document = new Document(); Console.WriteLine(document.DefaultPageSetup.LeftMargin); Section section = document.AddSection(); section.PageSetup.TopMargin = Unit.FromPoint(30); section.PageSetup.LeftMargin = Unit.FromPoint(20); TextFrame leftTF = section.AddTextFrame(); leftTF.Orientation = TextOrientation.Downward; leftTF.WrapFormat.Style = WrapStyle.None; // leftTF.MarginLeft = Unit.FromInch(1); //leftTF.MarginRight = Unit.FromInch(1); //make sure the font is embedded var options = new XPdfFontOptions(PdfFontEncoding.Unicode); Font fontEan = new Font("mrvcode39s", 20); leftTF.AddParagraph().AddFormattedText("*12343*", fontEan); // Now generate a pdf PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true); // Set the MigraDoc document pdfRenderer.Document = document; // Create the PDF document pdfRenderer.RenderDocument(); // Save the PDF document... pdfRenderer.Save(reportFilename); }
void Run() { if (File.Exists(outputName)) { File.Delete(outputName); } var doc = new Document(); StyleDoc(doc); var section = doc.AddSection(); var html = File.ReadAllText("example.html"); section.AddHtml(html); var markdown = File.ReadAllText("example.md"); section.AddMarkdown(markdown); var renderer = new PdfDocumentRenderer(); renderer.Document = doc; renderer.RenderDocument(); renderer.Save(outputName); Process.Start(outputName); }
// todo : add pdfDocumentRender in parameters private static string CreateFileAndSendDownloadLink(string name, string fileContents, string fileExtention, PdfDocumentRenderer pdfRenderer = null, PdfDocument pdfDocument = null) { var randomFolderName = Guid.NewGuid().ToString(); var randomPath = Path.Combine(Path.GetTempPath(), randomFolderName); if (Directory.Exists(randomPath)) { Directory.Delete(randomPath); } Directory.CreateDirectory(randomPath); var filePath = Path.Combine(randomPath, name + "." + fileExtention); if (pdfRenderer == null && pdfDocument == null) { File.WriteAllText(filePath, fileContents); } else if (pdfDocument != null) { pdfDocument.Save(filePath); } else if (pdfRenderer != null) { pdfRenderer.Save(filePath); } return(Path.Combine(randomFolderName, name + "." + fileExtention)); }
/// <summary> /// Must be PDF /// </summary> /// <param name="filename"></param> public void Save(string filename) { try { if (Path.GetExtension(filename).ToLower() != ".pdf") { throw new Exception("Please specify pdf file"); } // Create a MigraDoc document Document document = this.CreateDocument(); document.UseCmykColor = true; // Create a renderer for PDF that uses Unicode font encoding PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true); // Set the MigraDoc document pdfRenderer.Document = document; // Create the PDF document pdfRenderer.RenderDocument(); // Save the PDF document... pdfRenderer.Save(filename); this.docFile = filename; } catch (Exception ex) { throw ex; } }
public InvoiceGenerator(ClientModel client, double price, int nbDays, int invoiceNumber, string month) { this.invoice = new XmlDocument(); this.invoice.Load(Environment.CurrentDirectory + @"\template.xml"); this.navigator = this.invoice.CreateNavigator(); CreateDocument(client, price, nbDays, invoiceNumber, month); PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true); // Set the MigraDoc document pdfRenderer.Document = document; // Create the PDF document pdfRenderer.RenderDocument(); // Save the PDF document... string filename = "Invoice.pdf"; #if DEBUG // I don't want to close the document constantly... filename = "Invoice-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf"; #endif pdfRenderer.Save(filename); // ...and start a viewer. Process.Start(filename); }
/// <summary> /// Saves the receipt as a pdf file in the predetermined location /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void savePdf_Click(object sender, RoutedEventArgs e) { if (receipt == null) { MessageBox.Show("Receipt is not loaded!"); } else { var document = createPdf(); document.UseCmykColor = true; // Create a renderer for PDF that uses Unicode font encoding var pdfRenderer = new PdfDocumentRenderer(true); // Set the MigraDoc document pdfRenderer.Document = document; // Create the PDF document pdfRenderer.RenderDocument(); Directory.CreateDirectory(Environment.GetEnvironmentVariable("USERPROFILE") + "/Documents/InvoiceX/Receipts/"); // Save the PDF document... var filename = Environment.GetEnvironmentVariable("USERPROFILE") + "/Documents/InvoiceX/Receipts/Receipt" + txtBox_receiptNumber.Text + ".pdf"; ; pdfRenderer.Save(filename); Process.Start(filename); } }
public MemoryStream PrintSettlement(int settlementId) { Document document = CreateDocument(); Settlement settlement = settlementDL.GetSettlement(settlementId, null)[0]; //TODO check for missing settlement Cicle cicle = new CicleBL(settlementDL.ConnectionString).GetCicle(settlement.CicleId)[0]; //TODO check for missing cicle Producer producer = new ProducerBL(settlementDL.ConnectionString).GetProducer(settlement.ProducerId)[0]; //TODO check for missing cicle List <WeightTicket> tickets = new WeightTicketsDL(settlementDL.ConnectionString).GetWeightTicketsInSettlementFullDetails(settlementId); List <SettlementPayment> payments = settlementDL.GetSettlementPayments(settlementId); //Add logo, date, producer data and cicle AddLogoDateProducerNameAddressAndCicle(document, settlement.Date, producer, cicle.Name); document.LastSection.AddParagraph(); //Print weightickets table AddWeightTicketsTable(tickets, document); document.LastSection.AddParagraph(); //Print payments AddPaymentsTableAndSummaryTable(payments, document, settlement); document.LastSection.AddParagraph(); //Print producer signature section Paragraph currentParagraph = document.LastSection.AddParagraph(); currentParagraph.Format.Alignment = ParagraphAlignment.Center; currentParagraph.AddText("______________________________________"); currentParagraph = document.LastSection.AddParagraph(); currentParagraph.Format.Alignment = ParagraphAlignment.Center; currentParagraph.AddText(producer.Name + " " + producer.PaternalSurname + " " + producer.MaternalSurname); PdfDocumentRenderer renderer = new PdfDocumentRenderer(true); renderer.Document = document; renderer.RenderDocument(); MemoryStream stream = new MemoryStream(); renderer.Save(stream, false); return(stream); }
public IHttpActionResult GetDownload(int id) { /* Get Invoice PDF */ Invoice invoice = UnitOfWork.Invoices.Get(id); InvoicePdf pdf = new InvoicePdf(invoice); PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false); pdfRenderer.Document = pdf.CreateDocument(); pdfRenderer.RenderDocument(); MemoryStream stream = new MemoryStream(); pdfRenderer.Save(stream, false); /* Send PDF file */ var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(stream) }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); var response = ResponseMessage(result); return(response); }
private void savePdf_Click(object sender, RoutedEventArgs e) { if (!isCreated) { MessageBox.Show("Statement is not completed!"); } else { var document = createPdf(); document.UseCmykColor = true; // Create a renderer for PDF that uses Unicode font encoding var pdfRenderer = new PdfDocumentRenderer(true); // Set the MigraDoc document pdfRenderer.Document = document; // Create the PDF document pdfRenderer.RenderDocument(); // Save the PDF document... var customer = (Customer)comboBox_customer.SelectedItem; Directory.CreateDirectory(Environment.GetEnvironmentVariable("USERPROFILE") + "/Documents/InvoiceX/Statements/"); // Save the PDF document... var filename = Environment.GetEnvironmentVariable("USERPROFILE") + "/Documents/InvoiceX/Statements/Statement" + customer.idCustomer + ".pdf"; ; pdfRenderer.Save(filename); Process.Start(filename); } }
private void btnCreateCustomersBalanceSheet_Click(object sender, RoutedEventArgs e) { var document = createPdfBalanceSheet(); document.UseCmykColor = true; // Create a renderer for PDF that uses Unicode font encoding var pdfRenderer = new PdfDocumentRenderer(true); // Set the MigraDoc document pdfRenderer.Document = document; // Create the PDF document pdfRenderer.RenderDocument(); Directory.CreateDirectory(Environment.GetEnvironmentVariable("USERPROFILE") + "/Documents/InvoiceX/Customers Balance Report/"); DateTime date = DateTime.Now; // Save the PDF document... var filename = Environment.GetEnvironmentVariable("USERPROFILE") + "/Documents/InvoiceX/Customers Balance Report/Report" + date.Day + "-" + date.Month + "-" + date.Year + ".pdf"; ; try { pdfRenderer.Save(filename); Process.Start(filename); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void ExportToPdf(string Type, string Head, DataGrid Grid, DataRowView GridRow, int RowNum) { try { DataTable dt = default(DataTable); if (Type == "One") { dt = DataGridRow_To_DataTable(Grid, GridRow, Head, RowNum); } else { dt = DataGrid_To_DataTable(Grid, Head); } PDFform pdfForm = new PDFform(dt, Head, Type); Document document = pdfForm.CreateDocument(); document.UseCmykColor = true; PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true); pdfRenderer.Document = document; pdfRenderer.RenderDocument(); string FilePath = System.IO.Path.GetTempPath() + "\\" + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + ".pdf"; pdfRenderer.Save(FilePath); System.Diagnostics.Process.Start(FilePath); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
public bool MigraDocSample(string indir, string outdir, List <string> files, int tryCount) { try { var document = new Document(); var section = document.AddSection(); var resultName = Path.GetFileNameWithoutExtension(files[0]); foreach (var file in files) { if (document.Sections.Count != 1) { section.AddPageBreak(); } var img = section.AddImage(file); img.Height = document.DefaultPageSetup.PageHeight; img.Width = document.DefaultPageSetup.PageWidth; } var render = new PdfDocumentRenderer(); render.Document = document; render.RenderDocument(); render.Save(Path.Combine(outdir, resultName + ".pdf")); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Initializate collections in case if we need name of one of them /// </summary> /// <param name="transFunc">Use delegate for translation method wich work with localResource file</param> /// <param name="paymentMethods"></param> /// <param name="solicitors"></param> /// <param name="mailings"></param> /// <param name="departments"></param> /// <param name="categoryTree"></param> public byte[] CreateDocument(FilterTransactionReport filter, TransactionGrouped grouped, int countTrans) { // Create a new MigraDoc document _document = new Document { Info = { Title = filter.Name } }; DefineStyles(); if (filter.view == TransFilterView.Details) { var colsCount = CreatePage(filter, countTrans); if (string.Equals(filter.subtotalBy, "None", StringComparison.InvariantCultureIgnoreCase)) { FillContent(colsCount, grouped.GroupedObj, filter); } else { FillGroupedContent(colsCount, grouped.GroupedObj, filter); } } if (filter.view == TransFilterView.Total) { if (string.Equals(filter.totalOnlyBy, "totalOnly", StringComparison.InvariantCultureIgnoreCase)) { CreatePage(filter, countTrans); if (string.Equals(filter.subtotalBy, "None", StringComparison.InvariantCultureIgnoreCase)) { FillTotalContent(grouped, filter); } if (!string.Equals(filter.subtotalBy, "None", StringComparison.InvariantCultureIgnoreCase)) { FillSubGroupedTotalContent(grouped, filter); } } else { if (filter.ReportType == TransFilterType.Payment) { FillMatrixRows((MatrixDTO)grouped, filter, countTrans); } } } // FillContent(colsCount); PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true); pdfRenderer.Document = _document; pdfRenderer.RenderDocument(); using (MemoryStream ms = new MemoryStream()) { pdfRenderer.Save(ms, false); byte[] buffer = new byte[ms.Length]; ms.Seek(0, SeekOrigin.Begin); ms.Flush(); ms.Read(buffer, 0, (int)ms.Length); ms.Close(); return(buffer); } }
static void Main(string[] args) { // try // { // Create an invoice form with the sample invoice data. var invoice = new InvoiceForm("../../../../assets/xml/invoice.xml"); // Create the document using MigraDoc. var document = invoice.CreateDocument(); document.UseCmykColor = true; #if DEBUG MigraDoc.DocumentObjectModel.IO.Xml.DdlWriter.WriteToFile(document, "MigraDoc.xml"); MigraDoc.DocumentObjectModel.Document document3 = null; using (StreamReader sr = File.OpenText("MigraDoc.xml")) { var errors = new MigraDoc.DocumentObjectModel.IO.DdlReaderErrors(); var reader = new MigraDoc.DocumentObjectModel.IO.Xml.DdlReader(sr, errors); document3 = reader.ReadDocument(); using (StreamWriter sw = new StreamWriter("MigraDoc.xml.error")) { foreach (MigraDoc.DocumentObjectModel.IO.DdlReaderError error in errors) { sw.WriteLine("{0}:{1} {2} {3}", error.SourceLine, error.SourceColumn, error.ErrorLevel, error.ErrorMessage); } } } #endif // Create a renderer for PDF that uses Unicode font encoding. var pdfRenderer = new PdfDocumentRenderer(true); // Set the MigraDoc document. pdfRenderer.Document = document3; // Create the PDF document. pdfRenderer.RenderDocument(); // Save the PDF document... var filename = "Invoice.pdf"; #if DEBUG // I don't want to close the document constantly... filename = "Invoice-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf"; #endif pdfRenderer.Save(filename); // ...and start a viewer. Process.Start(filename); //} //catch (Exception ex) //{ // Console.WriteLine(ex.Message); //Console.ReadLine(); //} }
public virtual void Save(string filename) { PdfDocumentRenderer pdf = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.None); pdf.Document = Document; pdf.RenderDocument(); pdf.Save(filename); }
public static void Save(Document document, string fileName) { PdfDocumentRenderer renderer = new PdfDocumentRenderer(false); renderer.Document = document; renderer.RenderDocument(); renderer.Save(fileName); }
private void SaveDocumentAsPdf(string fileName) { var renderer = new PdfDocumentRenderer(true); renderer.Document = ThisDocument; renderer.RenderDocument(); renderer.Save(fileName.EndsWith(".pdf") ? fileName : fileName + ".pdf"); }
public void Create(Stream outputStream) { var renderer = new PdfDocumentRenderer(true); renderer.Document = CreateDocument(); renderer.RenderDocument(); renderer.Save(outputStream, false); }
static void Main(string[] args) { try { // Create an invoice form with the sample invoice data. var invoice = new InvoiceForm("../../../../assets/xml/invoice.xml"); // Create the document using MigraDoc. var document = invoice.CreateDocument(); document.Document.UseCmykColor = true; #if DEBUG // For debugging only... MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document.Document, "MigraDoc.mdddl"); //var document2 = MigraDoc.DocumentObjectModel.IO.DdlReader.DocumentFromFile("MigraDoc.mdddl"); //document = document2; // With PDFsharp 1.50 beta 3 there is a known problem: the blank before "by" gets lost while persisting as MDDDL. MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document.Document.Clone(), "MigraDoc2.mdddl"); #endif #if true // Create a renderer for PDF that uses Unicode font encoding. var pdfRenderer = new PdfDocumentRenderer(true); // Set the MigraDoc document. pdfRenderer.Document = document.Document /*.Clone()*/; // $THHO TODO Investigate why Clone() leads to an unusable document. // Create the PDF document. pdfRenderer.RenderDocument(); // Save the PDF document... var filename = "Invoice.pdf"; #if DEBUG // I don't want to close the document constantly... filename = "Invoice-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf"; #endif pdfRenderer.Save(filename); // ...and start a viewer. Process.Start(filename); #else // Create a renderer for PDF that uses Unicode font encoding. // Save the PDF document... var filename = "Invoice.pdf"; #if DEBUG // I don't want to close the document constantly... filename = "Invoice-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf"; #endif document.MakePdf(filename, true); #endif } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
//Private OrderFormDoc As Document public override void Make_PDF_Invoice(int InvoiceID) { this.InvoiceID = InvoiceID; try { if (File.Exists(PDFfilename)) { File.Delete(PDFfilename); } } catch (Exception) { } // Create a renderer for PDF that uses Unicode font encoding PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true); // Create a invoice form with the sample invoice data InvoiceForm_Dk InvoiceObj = new InvoiceForm_Dk(this.InvoiceID, Logo, Signatur, SignaturImage, IsCopy); //InvoiceObj.Logo = Logo //InvoiceObj.Signatur = Signatur //InvoiceObj.SignaturImage = SignaturImage //InvoiceObj.IsCopy = IsCopy // Create a MigraDoc document Document InvDocument = InvoiceObj.CreateDocument(); InvDocument.UseCmykColor = true; // Set the MigraDoc document pdfRenderer.Document = InvDocument; // Create the PDF document pdfRenderer.RenderDocument(); // Save the PDF document... pdfRenderer.Save(PDFfilename); //' If Invoice is EAN then make OrderForm / Følgeseddel //Inv = New InvoiceHeader(Me.InvoiceID) //If Inv.isLoaded AndAlso Inv.IsEAN Then IsEAN = True //If IsEAN Then // Try // If File.Exists(PDFOrderfilename) Then File.Delete(PDFOrderfilename) // Catch ex As Exception // End Try // Dim pdfRendererOrder As New PdfDocumentRenderer(True) // OrderForm = New OrderForm_Dk(Me.InvoiceID, Logo, Signatur, SignaturImage, IsCopy) // OrderFormDoc = OrderForm.CreateDocument // pdfRendererOrder.Document = OrderFormDoc // pdfRendererOrder.RenderDocument() // pdfRendererOrder.Save(PDFOrderfilename) //End If }
private void печатьToolStripMenuItem_Click(object sender, EventArgs e) { if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (!webControl1.IsLive) { return; } Graphics g = webControl1.CreateGraphics(); File.Delete(AppDomain.CurrentDomain.BaseDirectory + @"\temp.png"); int bmpHeight; int bmpWidth; using (Bitmap bmp = new Bitmap(webControl1.Width, webControl1.Height)) { webControl1.DrawToBitmap(bmp, new Rectangle(0, 0, webControl1.Width, webControl1.Height)); bmp.Save(AppDomain.CurrentDomain.BaseDirectory + @"\temp.png", System.Drawing.Imaging.ImageFormat.Png); bmpHeight = bmp.Height; bmpWidth = bmp.Width; } document = new Document(); Style style = document.Styles["Normal"]; style.Font.Name = "Times New Roman"; style.Font.Size = 10; Section page = document.AddSection(); PageSetup p = new PageSetup(); p.OddAndEvenPagesHeaderFooter = true; p.StartingNumber = 1; p.BottomMargin = "5mm"; p.LeftMargin = "5mm"; p.RightMargin = "5mm"; p.TopMargin = "5mm"; p.PageFormat = PageFormat.A4; if (bmpHeight > 700 | bmpWidth > 1070 && bmpHeight <= 1050 && bmpWidth <= 1530) { p.PageFormat = PageFormat.A3; } else if (bmpHeight > 1050 | bmpWidth > 1530 && bmpHeight <= 1530 && bmpWidth <= 2100) { p.PageFormat = PageFormat.A2; } p.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape; page.PageSetup = p; Paragraph paragraph = page.AddParagraph(this.Text); paragraph.Style = "Normal"; paragraph = page.AddParagraph(""); paragraph.Style = "Normal"; MigraDoc.DocumentObjectModel.Shapes.Image map = paragraph.AddImage(@"temp.png"); paragraph.Style = "Normal"; paragraph = page.AddParagraph(toolStripStatusLabel1.Text); renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always); renderer.Document = document; renderer.RenderDocument(); renderer.Save(saveFileDialog1.FileName); Process.Start(saveFileDialog1.FileName); } }
public void Save(string filePath, Document document) { PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always); pdfRenderer.Document = document; pdfRenderer.RenderDocument(); pdfRenderer.Save(filePath); }
public void CreateInvoice(Order order) { if (order.OrderDetailDt == null) { return; } currentOrder = order; if (currentOrder == null) { return; } CreateDocument(); document.UseCmykColor = true; #if DEBUG // for debugging only... MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl"); //document = MigraDoc.DocumentObjectModel.IO.DdlReader.DocumentFromFile("MigraDoc.mdddl"); #endif const bool unicode = true; const PdfFontEmbedding embedding = PdfFontEmbedding.Always; // Create a renderer for PDF that uses Unicode font encoding PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding); // Set the MigraDoc document pdfRenderer.Document = document; // Create the PDF document pdfRenderer.RenderDocument(); // Save the PDF document... //string filename = "Invoice.pdf"; //string filename = string.Format("Invoice - {0}-{1} - {2}.pdf", // currentOrder.OrderDate.ToString("yyyy.MM.dd"), DateTime.Now.ToString("HH.mm.ss"), currentOrder.OrderID.ToString().ToUpper()); string filename = string.Format("{0}.pdf", currentOrder.GetReportName()); #if DEBUG // I don't want to close the document constantly... //filename = "Invoice-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf"; //filename = string.Format("Invoice - {0}-{1} - {2}.pdf", // currentOrder.OrderDate.ToString("yyyy.MM.dd"), DateTime.Now.ToString("HH.mm.ss"), currentOrder.OrderID.ToString().ToUpper()); filename = string.Format("{0}.pdf", currentOrder.GetReportName()); #endif filename = string.Format("{0}\\{1}", ApplicationOperator.GetGeneralSetting().ReportPathSetting.ReportPath, filename); pdfRenderer.Save(filename); // ...and start a viewer. Process.Start(filename); }
public virtual Stream GetStream() { MemoryStream stream = new MemoryStream(); PdfDocumentRenderer pdf = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.None); pdf.Document = Document; pdf.RenderDocument(); pdf.Save(stream, false); return(stream); }
private static void OpenPdf(Document doc) { var filename = "c:\\temp\\test.pdf"; PdfDocumentRenderer pdf = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.None); pdf.Document = doc; pdf.RenderDocument(); pdf.Save(filename); ShellExecute(filename, ""); }