private void outputDocGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { Cursor = Cursors.WaitCursor; using (var db = new PastryShopDbContext()) { var senderGrid = (DataGridView)sender; if (senderGrid.Columns[e.ColumnIndex].Name == "show" && senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && !senderGrid.Rows[e.RowIndex].IsNewRow) { var docId = int.Parse(senderGrid.Rows[e.RowIndex].Cells["id"].Value.ToString()); var outputDoc = db.OutputDocuments .Include("Lines.Dessert") .Include("Lines.OutputDocLineProducts.Product.ProductDetail") .FirstOrDefault(d => d.Id == docId); if (outputDoc != null) { PdfMaker pdfMaker = new PdfMaker(); DocumentModel docModel = DocumentModelMapper.CreateDocumentModel(outputDoc); pdfMaker.CreatePdfDocumet(docModel); } } } Cursor = Cursors.Default; }
public void MakePdf_BookNameIsChinese_OutputsPdf() { var maker = new PdfMaker(); using (var input = TempFile.WithFilename("北京.htm")) using (var output = TempFile.WithFilename("北京.pdf")) { File.WriteAllText(input.Path, "<html><body>北京</body></html>"); File.Delete(output.Path); RunMakePdf((worker, args, owner) => maker.MakePdf(input.Path, output.Path, "A5", false, PublishModel.BookletLayoutMethod.SideFold, PublishModel.BookletPortions.BookletPages, worker, args, owner)); //we don't actually have a way of knowing it did a booklet Assert.IsTrue(File.Exists(output.Path)); } using (var input = TempFile.WithFilename("എന്റെ ബുക്ക്.htm")) using (var output = TempFile.WithFilename("എന്റെ ബുക്ക്.pdf")) { File.WriteAllText(input.Path, "<html><body>എന്റെ ബുക്ക്</body></html>"); File.Delete(output.Path); RunMakePdf((worker, args, owner) => maker.MakePdf(input.Path, output.Path, "A5", false, PublishModel.BookletLayoutMethod.SideFold, PublishModel.BookletPortions.BookletPages, worker, args, owner)); //we don't actually have a way of knowing it did a booklet Assert.IsTrue(File.Exists(output.Path)); } }
public void Setup() { WeSayProjectTestHelper.InitializeForTests(); _filePath = Path.GetTempFileName(); _liftFilePath = Path.GetTempFileName(); _lexEntryRepository = new LexEntryRepository(_filePath); _addin = new PdfMaker(); _addin.LaunchAfterTransform = false; }
/// <summary> /// Runs PdfMaker.MakePdf() with the desired arguments. Note that the implementation (as of March 2015) /// uses an external program to generate the PDF from the HTML file, so it doesn't need to be run on /// a background thread. The process includes a (possibly overgenerous) timeout, so we don't try to /// impose one here. /// </summary> /// <remarks> /// Running this on a background thread would be okay, except that on Linux, the interaction between /// Mono and NUnit and the Bloom method result in the BackgroundWorker.RunWorkerCompleted event /// never being fired if tests other than those in this file are run along with these tests. This is /// almost certainly an obscure bug in Mono. Running the method directly as we do here sidesteps that /// problem. (See https://jira.sil.org/browse/BL-831.) /// </remarks> void RunMakePdf(PdfMaker maker, string input, string output, string paperSize, bool landscape, bool saveMemoryMode, bool rightToLeft, PublishModel.BookletLayoutMethod layout, PublishModel.BookletPortions portion) { // Passing in a DoWorkEventArgs object prevents a possible exception being thrown. Which may not // really matter much in the test situation since NUnit would catch the exception. But I'd rather // have a nice test failure message than an unexpected exception caught message. var eventArgs = new DoWorkEventArgs(null); maker.MakePdf(input, output, paperSize, landscape, saveMemoryMode, rightToLeft, layout, portion, null, eventArgs, null); }
public void MakePdf_BookStyleIsBooklet_OutputsPdf() { var maker = new PdfMaker(); using (var input = TempFile.WithExtension("htm")) using (var output = new TempFile()) { File.WriteAllText(input.Path, "<html><body>Hello</body></html>"); File.Delete(output.Path); maker.MakePdf(input.Path, output.Path, "A5", false, PublishModel.BookletLayoutMethod.SideFold, PublishModel.BookletPortions.BookletPages, new DoWorkEventArgs(null)); //we don't actually have a way of knowing it did a booklet Assert.IsTrue(File.Exists(output.Path)); } }
private void createDocButton_Click(object sender, EventArgs e) { if (!this.GridViewIsFilled()) { MessageBox.Show(this, "Задължителните полета не са попълнени!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (this.dessertDataGridView.RowCount < 2) { MessageBox.Show(this, "Таблицата за продукти е празна!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var idsToQuantities = new Dictionary <int, int>(); OutputDocumentLine ol = new OutputDocumentLine(); for (int i = 0; i < this.dessertDataGridView.RowCount - 1; i++) { var id = int.Parse(this.dessertDataGridView.Rows[i].Cells["Product"].Value.ToString()); var quantity = int.Parse(this.dessertDataGridView.Rows[i].Cells["Quantity"].Value.ToString()); if (idsToQuantities.Keys.Contains(id)) { MessageBox.Show(this, "Има повтарящи се продукти", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } idsToQuantities.Add(id, quantity); } var dlgResult = MessageBox.Show(this, "Сигурни ли сте, че искате да запишетe документа!", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlgResult == DialogResult.Yes) { try { DocumentModel docModel = this.CreateDocumentModel(idsToQuantities); PdfMaker pdfMaker = new PdfMaker(); pdfMaker.CreatePdfDocumet(docModel); this.dessertDataGridView.Rows.Clear(); this.Close(); } catch (Exception ex) { Cursor = Cursors.Default; MessageBox.Show(ex.Message); } } }
/* * protected override void Dispose(bool disposing) * { * if (disposing) * { * _db.Dispose(); * } * base.Dispose(disposing); * } */ public FileResult CreatePdf(int?id) { if (id != null) { PdfMaker pdfMaker = new PdfMaker(_repo.GetAdvertisement(id)); MemoryStream workStream = pdfMaker.GeneratePdf(new MemoryStream()); DateTime dTime = DateTime.Now; string strPdfFileName = string.Format("Ogłoszenie" + dTime.ToString("yyyyMMdd") + ".pdf"); return(File(workStream, "application/pdf", strPdfFileName)); } return(null); }
public void MakePdf_BookStyleIsNone_OutputsPdf() { var maker = new PdfMaker(); using (var input = TempFile.WithExtension("htm")) using (var output = new TempFile()) { File.WriteAllText(input.Path, "<html><body>Hello</body></html>"); File.Delete(output.Path); RunMakePdf((worker, args, owner) => maker.MakePdf(input.Path, output.Path, "a5", false, PublishModel.BookletLayoutMethod.SideFold, PublishModel.BookletPortions.AllPagesNoBooklet, worker, args, owner)); //we don't actually have a way of knowing it did a booklet Assert.IsTrue(File.Exists(output.Path)); } }
public void MakePdf_BookNameIsNonAscii_OutputsPdf() { var maker = new PdfMaker(); using (var input = TempFile.WithFilename("എന്റെ ബുക്ക്.html")) using (var output = TempFile.WithFilename("എന്റെ ബുക്ക്.pdf")) { File.WriteAllText(input.Path, "<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=utf-8\"><html><body>എന്റെ ബുക്ക്</body></html>"); File.Delete(output.Path); RunMakePdf(maker, input.Path, output.Path, "A5", false, false, false, PublishModel.BookletLayoutMethod.SideFold, PublishModel.BookletPortions.BookletPages); //we don't actually have a way of knowing it did a booklet Assert.IsTrue(File.Exists(output.Path), "Failed to convert trivial HTML file to PDF (Indic script filenames and content)"); var bytes = File.ReadAllBytes(output.Path); Assert.Less(1000, bytes.Length, "Generated PDF file is way too small! (Indic script filenames and content)"); Assert.IsTrue(bytes [0] == (byte)'%' && bytes [1] == (byte)'P' && bytes [2] == (byte)'D' && bytes [3] == (byte)'F', "Generated PDF file started with the wrong 4-byte signature (Indic script filenames and content)"); } }
public void MakePdf_BookNameIsChinese_OutputsPdf() { var maker = new PdfMaker(); using (var input = TempFile.WithFilename("北京.html")) using (var output = TempFile.WithFilename("北京.pdf")) { RobustFile.WriteAllText(input.Path, "<html><body>北京</body></html>"); RobustFile.Delete(output.Path); RunMakePdf(maker, input.Path, output.Path, "A5", false, false, false, PublishModel.BookletLayoutMethod.SideFold, PublishModel.BookletPortions.BookletPages); //we don't actually have a way of knowing it did a booklet Assert.IsTrue(File.Exists(output.Path), "Failed to convert trivial HTML file to PDF (Chinese filenames and content)"); var bytes = File.ReadAllBytes(output.Path); Assert.Less(1000, bytes.Length, "Generated PDF file is way too small! (Chinese filenames and content)"); Assert.IsTrue(bytes [0] == (byte)'%' && bytes [1] == (byte)'P' && bytes [2] == (byte)'D' && bytes [3] == (byte)'F', "Generated PDF file started with the wrong 4-byte signature (Chinese filenames and content)"); } }
public void MakePdf_BookStyleIsNone_OutputsPdf() { var maker = new PdfMaker(); using (var input = TempFile.WithExtension("html")) using (var output = new TempFile()) { File.WriteAllText(input.Path, "<html><body>Hello</body></html>"); File.Delete(output.Path); RunMakePdf(maker, input.Path, output.Path, "a5", false, false, false, PublishModel.BookletLayoutMethod.SideFold, PublishModel.BookletPortions.AllPagesNoBooklet); //we don't actually have a way of knowing it did a booklet Assert.IsTrue(File.Exists(output.Path), "Failed to convert trivial HTML file to PDF (AllPagesNoBooklet)"); var bytes = File.ReadAllBytes(output.Path); Assert.Less(1000, bytes.Length, "Generated PDF file is way too small! (AllPagesNoBooklet)"); Assert.IsTrue(bytes [0] == (byte)'%' && bytes [1] == (byte)'P' && bytes [2] == (byte)'D' && bytes [3] == (byte)'F', "Generated PDF file started with the wrong 4-byte signature (AllPagesNoBooklet)"); } }
private void Button_Click(object sender, RoutedEventArgs e) { Button myButton = (Button)sender; string value = myButton.CommandParameter.ToString(); string path = ""; SaveFileDialog openFileDialog = new SaveFileDialog(); openFileDialog.Filter = "Pliki PDF | *.pdf"; openFileDialog.DefaultExt = "pdf"; if (openFileDialog.ShowDialog() == true) { path = openFileDialog.FileName; } PdfMaker pdf = new PdfMaker(); pdf.createPdf(value, path); }
/// <summary> /// Runs PdfMaker.MakePdf() with the desired arguments. Note that the implementation (as of March 2015) /// uses an external program to generate the PDF from the HTML file, so it doesn't need to be run on /// a background thread. The process includes a (possibly overgenerous) timeout, so we don't try to /// impose one here. /// </summary> /// <remarks> /// Running this on a background thread would be okay, except that on Linux, the interaction between /// Mono and NUnit and the Bloom method result in the BackgroundWorker.RunWorkerCompleted event /// never being fired if tests other than those in this file are run along with these tests. This is /// almost certainly an obscure bug in Mono. Running the method directly as we do here sidesteps that /// problem. (See https://jira.sil.org/browse/BL-831.) /// </remarks> void RunMakePdf(PdfMaker maker, string input, string output, string paperSize, bool landscape, bool saveMemoryMode, bool rightToLeft, PublishModel.BookletLayoutMethod layout, PublishModel.BookletPortions portion) { // Passing in a DoWorkEventArgs object prevents a possible exception being thrown. Which may not // really matter much in the test situation since NUnit would catch the exception. But I'd rather // have a nice test failure message than an unexpected exception caught message. var eventArgs = new DoWorkEventArgs(null); maker.MakePdf(new PdfMakingSpecs() { InputHtmlPath = input, OutputPdfPath = output, PaperSizeName = paperSize, Landscape = landscape, SaveMemoryMode = saveMemoryMode, LayoutPagesForRightToLeft = rightToLeft, BooketLayoutMethod = layout, BookletPortion = portion }, null, eventArgs, null); }
/// <summary> /// The vent method raised when clikcing the download button /// </summary> /// <param name="sender">The object sender</param> /// <param name="e">The EventArgs</param> private void downloadBtn_Click(object sender, EventArgs e) { var pdfCreator = new PdfMaker(); pdfCreator.MakeDriveLog(_user); }