/// <summary> /// Saves the PDF from the disk swap file /// </summary> /// <param name="b"></param> /// <param name="output"></param> public void SaveAsPDF(BitmapFile b, string output) { FileInfo fi = new FileInfo(output); // Following are the calls to the Gios PDF library PdfDocument myPdfDocument = new PdfDocument(PdfDocumentFormat.InCentimeters(m_PDF_Width, m_PDF_Height)); int horizontalStep = Convert.ToInt32(m_PDF_Width * m_PDF_DPI / 2.54); int verticalStep = Convert.ToInt32(m_PDF_Height * m_PDF_DPI / 2.54); int origin = 0; List <string> tmpFiles = new List <string>(); int tmpFileCount = 0; while (origin < b.Y) { Bitmap tmp = b.GetBitmap(0, origin, horizontalStep, verticalStep); string temp_file = fi.DirectoryName + "\\_tempPDFComponent_" + tmpFileCount.ToString().PadLeft(5, '0') + ".jpg"; tmp.Save(temp_file, ImageFormat.Jpeg); tmpFiles.Add(temp_file); PdfPage newPdfPage = myPdfDocument.NewPage(); PdfImage myImage = myPdfDocument.NewImage(temp_file); newPdfPage.Add(myImage, 0.0, 0.0, m_PDF_DPI); newPdfPage.SaveToDocument(); origin += verticalStep; tmpFileCount++; tmp.Dispose(); } myPdfDocument.SaveToFile(output); foreach (string f in tmpFiles) { try { File.Delete(f); } catch (Exception) { } } }
/// <summary> /// Virtial Draw, defined in children /// </summary> /// <param name="source"></param> public override void Draw(string source, BitmapFile bmp, int count) { Bitmap b = null; Graphics g = null; int originalX = x; x = 0; // paste is done to the zero coordinates int originalY = y; y = 0; int originalTextX = Text_x; Text_x -= originalX; int originalTextY = Text_y; Text_y -= originalY; int originalCalloutX = Callout_x; Callout_x -= originalX; int originalCalloutY = Callout_y; Callout_y -= originalY; try { b = bmp.GetBitmap(originalX, originalY, dx + 1, dy + 1); g = Graphics.FromImage(b); Draw(source, g, b); if (count >= 0) { b.Save("C:\\temp\\_debug_" + count.ToString("000") + ".jpg", ImageFormat.Jpeg); } bmp.SetBitmap(b, originalX, originalY); } catch (Exception ex) { throw new Exception("Error in Draw routine: " + ex.Message); } finally { x = originalX; y = originalY; Text_x = originalTextX; Text_y = originalTextY; Callout_x = originalCalloutX; Callout_y = originalCalloutY; if (g != null) { g.Dispose(); } if (b != null) { b.Dispose(); } } }