Example #1
0
 private bool ConvertOthersToPDF(string imagePath)
 {
     try
     {
         PDPage pDPage = new PDPage();
         string str    = "temp.png";
         this.pdfFile.addPage(pDPage);
         if (Path.GetExtension(imagePath).ToLower() == ".bmp")
         {
             ImageToPDFConverter.BmpToPng(new Bitmap(Image.FromFile(imagePath)), str);
         }
         else if (Path.GetExtension(imagePath).ToLower() == ".png")
         {
             str = imagePath;
         }
         else
         {
             Image.FromFile(imagePath).Save(str, ImageFormat.Png);
         }
         PDImageXObject pDImageXObject = PDImageXObject.createFromFile(str, this.pdfFile);
         PDRectangle    pDRectangle    = new PDRectangle((float)(pDImageXObject.getWidth() + 40), (float)(pDImageXObject.getHeight() + 40));
         pDPage.setMediaBox(pDRectangle);
         PDPageContentStream pDPageContentStream = new PDPageContentStream(this.pdfFile, pDPage);
         pDPageContentStream.drawImage(pDImageXObject, 20f, 20f);
         pDPageContentStream.close();
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         throw new PDFToolkitException(exception.Message, exception);
     }
     return(true);
 }
Example #2
0
 private bool ConvertTiffToPDF(string imagePath)
 {
     try
     {
         string[] strArrays = ImageToPDFConverter.SplitTiff(imagePath);
         for (int i = 0; i < (int)strArrays.Length; i++)
         {
             string str    = strArrays[i];
             PDPage pDPage = new PDPage();
             this.pdfFile.addPage(pDPage);
             PDImageXObject pDImageXObject = PDImageXObject.createFromFile(str, this.pdfFile);
             PDRectangle    pDRectangle    = new PDRectangle((float)(pDImageXObject.getWidth() + 40), (float)(pDImageXObject.getHeight() + 40));
             pDPage.setMediaBox(pDRectangle);
             PDPageContentStream pDPageContentStream = new PDPageContentStream(this.pdfFile, pDPage);
             pDPageContentStream.drawImage(pDImageXObject, 20f, 20f);
             pDPageContentStream.close();
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         throw new PDFToolkitException(exception.Message, exception);
     }
     return(true);
 }
Example #3
0
 private bool ConvertJPGToPDF(string imagePath)
 {
     try
     {
         PDPage pDPage = new PDPage();
         this.pdfFile.addPage(pDPage);
         PDImageXObject pDImageXObject = PDImageXObject.createFromFile(imagePath, this.pdfFile);
         PDRectangle    pDRectangle    = new PDRectangle((float)(pDImageXObject.getWidth() + 40), (float)(pDImageXObject.getHeight() + 40));
         pDPage.setMediaBox(pDRectangle);
         PDPageContentStream pDPageContentStream = new PDPageContentStream(this.pdfFile, pDPage);
         pDPageContentStream.drawImage(pDImageXObject, 20f, 20f);
         pDPageContentStream.close();
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         throw new PDFToolkitException(exception.Message, exception);
     }
     return(true);
 }