pdf creation code using gd picture 8 using image

Discussions about PDF management.
Post Reply
rackteam
Posts: 5
Joined: Sat Jul 30, 2011 8:27 am

pdf creation code using gd picture 8 using image

Post by rackteam » Mon Aug 01, 2011 8:30 am

hi

i have a code which creates pdf using image (byte array[]) and from existing pdf written in gd picture 6
and i want to convert this code into gd picture 8

the following code is written in gdpicture 6:

Code: Select all

try
            {
                int ExportPDFID = ObjGdPictureImaging.PdfNewPdf(PdfFilePath);
                DataSet DsDocumentPages = new DataSet();
                using (ScanManagementService.ScanManagementClient ObjScanManagementClient = new ScanManagementService.ScanManagementClient())
                {
                    DsDocumentPages = ObjScanManagementClient.ScanManagement_LoadDocumentPages(UserSecurity.GetConnString, UserSecurity.selectedfilecabinetname, DocumentId);
                    ObjScanManagementClient.Close();
                }
                if ((DsDocumentPages.Tables.Count > 0) && (DsDocumentPages.Tables[0].Rows.Count > 0))
                {
                    for (int iCount = 0; iCount < DsDocumentPages.Tables[0].Rows.Count; iCount++)
                    {
                        string FilePath = DsDocumentPages.Tables[0].Rows[iCount]["FilePath"].ToString() + DsDocumentPages.Tables[0].Rows[iCount]["FileName"].ToString();
                        using (FileTransferService.FileTransferClient FT = new FileTransferService.FileTransferClient())
                        {
                            byte[] ImageData = FT.FileDownload(UserSecurity.selectedbankname, UserSecurity.selectedfilecabinetname, DsDocumentPages.Tables[0].Rows[iCount]["FileName"].ToString());
                            FT.Close();
                            if (DsDocumentPages.Tables[0].Rows[iCount]["FileName"].ToString().ToLower().Contains(".pdf"))
                            {
                                if (ObjGdViewer.DisplayFromByteArray(ref ImageData) == GdPictureStatus.OK)
                                {
                                    int ImageID = ObjGdViewer.PdfRenderPageToGdPictureImage(300, 1);
                                    ObjGdPictureImaging.PdfAddImageFromGdPictureImage(ExportPDFID, ImageID);
                                    ObjGdPictureImaging.ReleaseGdPictureImage(ImageID);
                                }
                            }
                            else
                            {
                                int ImageID = ObjGdPictureImaging.CreateGdPictureImageFromByteArray(ref ImageData);
                                ObjGdPictureImaging.PdfAddImageFromGdPictureImage(ExportPDFID, ImageID);
                                ObjGdPictureImaging.ReleaseGdPictureImage(ImageID);
                            }
                        }
                    }

                    for (int iCount = 1; iCount <= DsDocumentPages.Tables[0].Rows.Count; iCount++)
                    {
                        ObjGdPictureImaging.PdfNewPage(ExportPDFID, ObjGdPictureImaging.PdfGetImageWidth(ExportPDFID, iCount), ObjGdPictureImaging.PdfGetImageHeight(ExportPDFID, iCount));
                        ObjGdPictureImaging.PdfDrawImage(ExportPDFID, iCount, 0, 0, ObjGdPictureImaging.PdfGetImageWidth(ExportPDFID, iCount), ObjGdPictureImaging.PdfGetImageHeight(ExportPDFID, iCount));
                    }
                    ObjGdPictureImaging.PdfEndPdf(ExportPDFID);
                }
                //Insert Activity Log
                //gFunctions.SaveActivityLog("Scanned Document  has been exported in multiPage as pdf successfully");
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }

i'm able to convert "PdfRenderPageToGdPictureImage()","PdfRenderPageToGdPictureImage()" methos with help of gdpicturepdf class of version 8

but i facing problem in 'PdfNewPage()'and 'PdfDrawImage()' method
i found two methods for above to methods those are : InsertPage() and DrawImage()
but pdf is not created.

here is the code which i have converted in gd picture 8:

Code: Select all

try
            {
                //int ExportPDFID = ObjGdPictureImaging.PdfNewPdf(PdfFilePath);
                int ExportPDFID = ObjGdPictureImaging.PdfOCRStart(PdfFilePath,true,"","","","","");
                GdPicturePDF gdPDF = new GdPicturePDF();
                gdPDF.SetLicenseNumber(ConfigurationSettings.AppSettings["LicenceKey"].ToString());
                DataSet DsDocumentPages = new DataSet();
                
                using (ScanManagementService.ScanManagementClient ObjScanManagementClient = new ScanManagementService.ScanManagementClient())
                {
                    DsDocumentPages = ObjScanManagementClient.ScanManagement_LoadDocumentPages(UserSecurity.GetConnString, UserSecurity.selectedfilecabinetname, DocumentId);
                    ObjScanManagementClient.Close();
                }
                if ((DsDocumentPages.Tables.Count > 0) && (DsDocumentPages.Tables[0].Rows.Count > 0))
                {
                    for (int iCount = 0; iCount < DsDocumentPages.Tables[0].Rows.Count; iCount++)
                    {
                        string FilePath = DsDocumentPages.Tables[0].Rows[iCount]["FilePath"].ToString() + DsDocumentPages.Tables[0].Rows[iCount]["FileName"].ToString();
                        using (FileTransferService.FileTransferClient FT = new FileTransferService.FileTransferClient())
                        {
                            byte[] ImageData = FT.FileDownload(UserSecurity.selectedbankname, UserSecurity.selectedfilecabinetname, DsDocumentPages.Tables[0].Rows[iCount]["FileName"].ToString());
                            FT.Close();
                            if (DsDocumentPages.Tables[0].Rows[iCount]["FileName"].ToString().ToLower().Contains(".pdf"))
                            {
                                if (ObjGdViewer.DisplayFromByteArray(ref ImageData) == GdPictureStatus.OK)
                                {
                                    
                                    //gdPDF.SelectPage(iCount);
                                    int ImageID= gdPDF.RenderPageToGdPictureImage(300, true);
                                    ObjGdPictureImaging.PdfAddGdPictureImageToPdfOCR(ExportPDFID, ImageID, "eng", "", "");
                                    //int ImageID = ObjGdViewer.PdfRenderPageToGdPictureImage(300, 1);
                                    //ObjGdPictureImaging.PdfAddImageFromGdPictureImage(ExportPDFID, ImageID);
                                    ObjGdPictureImaging.ReleaseGdPictureImage(iCount);
                                }
                            }
                            else
                            {
                                gdPDF.SelectPage(iCount);
                                int ImageID = ObjGdPictureImaging.CreateGdPictureImageFromByteArray(ref ImageData);
                                gdPDF.AddImageFromGdPictureImage(ImageID,true,true );
                                //GdPImaging.PdfAddImageFromGdPictureImage(ExportPDFID, ImageID);
                                ObjGdPictureImaging.ReleaseGdPictureImage(ImageID);
                            }
                        }
                    }

                    for (int iCount = 1; iCount <= DsDocumentPages.Tables[0].Rows.Count; iCount++)
                    {
                       
                        gdPDF.SelectPage(iCount);
                        gdPDF.InsertPage(gdPDF.GetPageWidth(), gdPDF.GetPageHeight(), iCount);
                        gdPDF.DrawImage("", 0, 0, gdPDF.GetPageWidth(), gdPDF.GetPageHeight());

                        //ObjGdPictureImaging.PdfNewPage(ExportPDFID, ObjGdPictureImaging.PdfGetImageWidth(ExportPDFID, iCount), ObjGdPictureImaging.PdfGetImageHeight(ExportPDFID, iCount));
                        //ObjGdPictureImaging.PdfDrawImage(ExportPDFID, iCount, 0, 0, ObjGdPictureImaging.PdfGetImageWidth(ExportPDFID, iCount), ObjGdPictureImaging.PdfGetImageHeight(ExportPDFID, iCount));
                    }
                    ObjGdPictureImaging.PdfOCRStop(ExportPDFID);
                }
                //Insert Activity Log
                //gFunctions.SaveActivityLog("Scanned Document  has been exported in multiPage as pdf successfully");
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
but this is not working for me
plz reply.............

with regards
rackteam

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: pdf creation code using gd picture 8 using image

Post by Loïc » Tue Aug 02, 2011 2:09 am

Hi,

Your code has no sense at all. What are you trying to do ? Converting PDF to PDF with OCR ?

Kind regards,

Loïc

rackteam
Posts: 5
Joined: Sat Jul 30, 2011 8:27 am

Re: pdf creation code using gd picture 8 using image

Post by rackteam » Tue Aug 02, 2011 7:14 am

thanks for your reply

actually I want to convert byte array of image to pdf doc but I am not able to get this method in GDpicturepdf class
that why I was using gdpicture ocr method

Please let me know if there is any function or method exists in gd picture 8 by that i can convert byte array to pdf

Please do needful asap as I am running short of time

If possible please provide me the code snippet for it.
It will be more helpful for me for coding.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: pdf creation code using gd picture 8 using image

Post by Loïc » Wed Aug 03, 2011 12:01 am

Hi,

OK here a snippet to save an image stored in a byte array to PDF:

Code: Select all

      Dim oGdPicturePDF As New GdPicturePDF
      Dim oGdPictureImaging As New GdPictureImaging

      Dim ImageID As Integer = oGdPictureImaging.CreateGdPictureImageFromByteArray(arBytes) 'arBytes must includes your image data

      oGdPicturePDF.NewPDF()
      oGdPicturePDF.AddImageFromGdPictureImage(ImageID, False, True)
      oGdPicturePDF.SaveToFile("mypdf.pdf")
      oGdPictureImaging.ReleaseGdPictureImage(ImageID)
      oGdPicturePDF.CloseDocument()
Hope this helps !

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests