Exemplo n.º 1
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);
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
        public static PDAppearanceDictionary GetRubberStampAppearance(PDFDocument document, PDFRectangle rect, string subType)
        {
            PDAppearanceDictionary pDAppearanceDictionary;
            string empty = string.Empty;

            empty = (!System.IO.File.Exists(subType) ? PDFHelper.GetResourceLocation(subType) : subType);
            if (empty == null)
            {
                Console.WriteLine("Cant find rubber stamp");
                pDAppearanceDictionary = null;
            }
            else
            {
                PDImageXObject pDImageXObject = PDImageXObject.createFromFileByContent(new java.io.File(empty), document.PDFBoxDocument);
                float          lowerLeftX     = rect.PDFBoxRectangle.getLowerLeftX();
                float          lowerLeftY     = rect.PDFBoxRectangle.getLowerLeftY();
                rect.PDFBoxRectangle.getWidth();
                rect.PDFBoxRectangle.getHeight();
                rect.PDFBoxRectangle.getHeight();
                rect.PDFBoxRectangle.getWidth();
                PDFormXObject pDFormXObject = new PDFormXObject(document.PDFBoxDocument);
                pDFormXObject.setResources(new PDResources());
                pDFormXObject.setBBox(rect.PDFBoxRectangle);
                pDFormXObject.setFormType(1);
                OutputStream outputStream = pDFormXObject.getStream().createOutputStream();
                PDFHelper.drawXObject(pDImageXObject, pDFormXObject.getResources(), outputStream, lowerLeftX, lowerLeftY, (float)pDImageXObject.getWidth(), (float)pDImageXObject.getHeight());
                outputStream.close();
                PDAppearanceStream     pDAppearanceStream      = new PDAppearanceStream(pDFormXObject.getCOSObject());
                PDAppearanceDictionary pDAppearanceDictionary1 = new PDAppearanceDictionary(new COSDictionary());
                pDAppearanceDictionary1.setNormalAppearance(pDAppearanceStream);
                pDAppearanceDictionary = pDAppearanceDictionary1;
            }
            return(pDAppearanceDictionary);
        }