public void WriteSummaryResultsPage(string siteName, ListView lv, Image plotImage1, Image plotImage2, double aspectRatio) { pdfPage myPage = myDoc.addPage(predefinedPageSize.csSharpPDFFormat); int width = myPage.width - leftMargin - rightMargin; WritePageTitle(myPage, "Summary Results", siteName); pdfTable myTable = new pdfTable(myDoc, 1, pdfColor.Black, 5, new pdfTableStyle(myDoc.getFontReference(strFont), 12, pdfColor.Black, new pdfColor("d9d1b3")), new pdfTableStyle(myDoc.getFontReference(strFont), 12, pdfColor.Black, pdfColor.White), new pdfTableStyle(myDoc.getFontReference(strFont), 12, pdfColor.Black, pdfColor.White)); myTable.coordX = leftMargin; myTable.coordY = GetLineTop(myPage, 5); myTable.tableHeader.rowHeight = 25; myTable.tableHeader.addColumn(225, predefinedAlignment.csLeft); myTable.tableHeader[0].addText("Statistic"); myTable.tableHeader.addColumn(120, predefinedAlignment.csRight); myTable.tableHeader[1].addText("Current Scenario"); myTable.tableHeader.addColumn(120, predefinedAlignment.csRight); myTable.tableHeader[2].addText("Baseline Scenario"); int tableRowHt = 15; pdfTableRow myRow; for (int i = 0; i < lv.Items.Count; i++) { myRow = myTable.createRow(); myRow.rowHeight = tableRowHt; for (int j = 0; j < 3; j++) { myRow[j].addText(lv.Items[i].SubItems[j].Text); } myTable.addRow(myRow); } myPage.addTable(myTable); int plotWidth = width / 2; int plotHeight = (int)Math.Round((double)plotWidth * aspectRatio); int yPos = bottomMargin + 4 * lineHeight; myDoc.addImageReference(plotImage1, "pieChart1"); myPage.addImage(myDoc.getImageReference("pieChart1"), leftMargin, yPos, plotHeight, plotWidth); if (plotImage2 != null) { myDoc.addImageReference(plotImage2, "pieChart2"); myPage.addImage(myDoc.getImageReference("pieChart2"), leftMargin + plotWidth, yPos, plotHeight, plotWidth); } WriteFooter(myPage); }
private void Main(object link) { try { _novel = KitaabGhar.GetNovelInformation(link.ToString()); LogMessage("Information collected."); LogMessage(string.Format("Total pages: {0} ({1} - {2})", _novel.TotalPages, _novel.FirstIndex, _novel.LastIndex)); } catch (Exception ex) { LogMessage("Error: " + ex.Message); _running = false; return; } var directory = System.Web.Hosting.HostingEnvironment.MapPath(Path.Combine(DownloadLocation, _novel.Name)); if (directory == null) { LogMessage("Unable to get permission"); return; } var imageFormat = Path.Combine(directory, "{0}.gif"); Directory.CreateDirectory(directory); for (var i = _novel.FirstIndex; i <= _novel.LastIndex; i++) { LogMessage("Downloading page: " + i); var r = 0; Retry: if (!_running) { return; } try { //TODO retries if (r <= 3) { //TODO resume //if (!(true && File.Exists(string.Format(imageFormat, i)))) if (!File.Exists(string.Format(imageFormat, i))) { var tempImage = Http.DownloadImage(_novel.GetImageLink(i), _novel.GetRefLink(i), _novel.NewFormat); tempImage.Save(string.Format(imageFormat, i)); tempImage.Dispose(); } if (!_running) { return; } Progress((int)((double)((i - _novel.FirstIndex) * 100) / _novel.TotalPages)); } else { LogMessage("Unable to download within the provided number of retries."); } } catch (Exception ex) { LogMessage("Unable to download page: " + i); LogMessage("Trying to download page" + i + " again."); LogMessage("Error: " + ex.Message); r++; goto Retry; } } LogMessage("Download complete."); //TODO ApplicationSettings.CreatePdf if (true) { LogMessage("Creating PDF file."); try { using (var pdfFile = new pdfDocument(_novel.Name, "Abdullah Saleem")) { for (var i = _novel.FirstIndex; i <= _novel.LastIndex; i++) { var file = string.Format(imageFormat, i); LogMessage("Processing page: " + i); if (File.Exists(file)) { try { using (var image = Image.FromFile(file)) { pdfFile.addImageReference(file, i.ToString(CultureInfo.InvariantCulture)); var tempPage = pdfFile.addPage(image.Height, image.Width); tempPage.addImage( pdfFile.getImageReference(i.ToString(CultureInfo.InvariantCulture)), 0, 0); } LogMessage("Page " + i + " added."); } catch (Exception) { LogMessage("Page number " + i + "missing."); } } else { LogMessage("Page number " + i + "missing."); } } pdfFile.createPDF(Path.Combine(directory, _novel.Name + ".pdf")); LogMessage("PDF Created!"); //TODO ApplicationSettings.OpenPdf //if (false) //{ // Process.Start(Path.Combine(directory, _novel.Name + ".pdf")); //} } } catch (Exception ex) { LogMessage("Error occured while creating the PDF."); LogMessage("Error: " + ex.Message); } } //TODO: ApplicationSettings.DeleteImages if (true) { LogMessage("Deleting images."); for (var i = _novel.FirstIndex; i <= _novel.LastIndex; i++) { if (File.Exists(string.Format(imageFormat, i))) { try { File.Delete(string.Format(imageFormat, i)); } catch (Exception ex) { LogMessage("Error occured while deleting images."); LogMessage("Error: " + ex.Message); } } } } LogMessage("Completed."); }
private pdfPage getNewPage(ref double yPos) { yPos = topMargin; if (document == null) { document = new pdfDocument(myInterface.GetCompetitions()[0].Name, "Allberg Winshooter"); font = document.getFontReference(predefinedFont.csTimes); fontCompetitionHeader = document.getFontReference(predefinedFont.csTimesBold); fontHeader = document.getFontReference(predefinedFont.csTimesBold); } //double xsize = 210/conversionPixelsToMM; // A4 = 210*297mm (35,3*35,3 mm) //double ysize = 297/conversionPixelsToMM; bottomMargin = (int)((297 - 20)); //pdfPage myPage = document.addPage((int)ysize, (int)xsize); pdfPage myPage = document.addPage(predefinedPageSize.csA4Page); sharpPDF.Fonts.pdfAbstractFont headerFont = document.getFontReference(predefinedFont.csTimes); // Add copyright text addText(myPage, "WinShooter", leftMargin, (int)((bottomMargin + 3)), headerFont, 10); //addText(myPage, "©" + settings.PrinterSettings.Copyright, // leftMargin+155, (int)((bottomMargin+3)), headerFont, 10); // Add club logo Image image = settings.Logo; int logoHeight = image.Height; int logoWidth = image.Width; calculateLogoSize(image, 60, 200, out logoHeight, out logoWidth); int logoX = myPage.width - 20 - logoWidth; int logoY = myPage.height - 20 - logoHeight; try { sharpPDF.Elements.pdfImageReference imageRef = document.getImageReference("logo"); myPage.addImage(imageRef, logoX, logoY, logoHeight, logoWidth); } catch (sharpPDF.Exceptions.pdfImageNotLoadedException) { document.addImageReference((System.Drawing.Image)image, "logo"); sharpPDF.Elements.pdfImageReference imageRef = document.getImageReference("logo"); myPage.addImage(imageRef, logoX, logoY, logoHeight, logoWidth); } // Add Winshooter logo image = settings.GetWinshooterLogo(1000, 1000); logoHeight = image.Height; logoWidth = image.Width; calculateLogoSize(image, 50, 200, out logoHeight, out logoWidth); logoX = myPage.width - 20 - logoWidth; logoY = 10; try { sharpPDF.Elements.pdfImageReference imageRef = document.getImageReference("WinShooterLogo"); myPage.addImage(imageRef, logoX, logoY, logoHeight, logoWidth); } catch (sharpPDF.Exceptions.pdfImageNotLoadedException) { document.addImageReference((System.Drawing.Image)image, "WinShooterLogo"); sharpPDF.Elements.pdfImageReference imageRef = document.getImageReference("WinShooterLogo"); myPage.addImage(imageRef, logoX, logoY, logoHeight, logoWidth); } // TextStart = 20 + conversionPixelsToMM * logoHeight; return(myPage); }