6 Replies Latest reply: Feb 8, 2010 6:08 AM by joeln3 RSS

    How to : Replace an image

    joeln3 Community Member

      Hello all,

       

      I wan to edit an image which is in my PDF. Here is the workflow to edit my image :

       

      1. Extract the PDEImage and add it to a new PDDoc.

      2. Save the PDDoc as a TIFF.

      3. Edit the TIFF image

      4. Save the TIFF as a PDF (the PDF has one PDEElement which is my new PDEImage)

      5. Extract the new PDEImage and replace the XObject of my initial Image in my PDF by the new one (the one extracted from the new PDF file).

       

      Actually I just replace the XObject to skip the operations from the PDELayer because for internal reason I cannot edit the PDELayer (actually once the PDELayer is used to edit the content of the PDF then all content stream is re-created and it will destroy my content structure).

       

      Unfortunately sometimes this workflow doesn't work correctly especially when the CTM is different in my two PDF files.

       

      Does someone know a way to edit an image (using a temporary one) without using the PDE Layer?

       

      Thanks in advance,

      Joe

        • 1. Re: How to : Replace an image
          lrosenth Adobe Employee

          If it is just a simple raster image (Image XObject vs. Form XObject) - then you could certainly use the Cos APIs to do the replacement of the key in the Resources dictionary of the image to the new one.  (ie. CosDictPut( resDict, imageResourceName))

          • 2. Re: How to : Replace an image
            joeln3 Community Member

            Yes Leoanrd it's what I do.

             

            But the problem appears with some images which are rotated (90°) sometimes when I change the XObject.

            • 3. Re: How to : Replace an image
              lrosenth Adobe Employee

              Perhaps you aren't taking that into account when you create your intermediate version?

              • 4. Re: How to : Replace an image
                joeln3 Community Member

                The TIFF is correct and the preview is also correct in my application.

                 

                1. When I create my TIFF image I use the AVConversionFromPDF with my first intermediate PDF with only my PDEImage

                2. After I use the AVConversionToPDF with my TIFF and I retrieve the PDEImage

                 

                The differences between the two "intermediate" PDF files are : MediaBox and CTM. So I guess that the problem comes from this difference. But maybe not...

                 

                I tried this workflow without changing my first intermediate PDF and it works so I'm just wondering how I can create my second intermediate PDF file with the same parameters than my first one.

                • 5. Re: How to : Replace an image
                  lrosenth Adobe Employee

                  Rather than using PDEImage in the first case, what if you construct the temp PDF page yourself using Cos?  What does the output image look like?

                  • 6. Re: How to : Replace an image
                    joeln3 Community Member

                    Leonard,

                     

                    Using the Cos to create the PDF (so with a new mediaBox and customized CTM) generates a strange output image in the PDF file. But once this image is edited and inserted in the original PDF it looks good.

                     

                    I think that some PDF generators create bad images and edit them with the CTM to have a correct display(I'm sure that it's not the best way to insert image ine a PDF).

                     

                    Thanks for your help.

                    Joe