Hi,
I’ve got a strange behaviour if you try something like this:
public void Convert(string srcDoc, string destDoc)
{
Document doc = new Document(srcDoc);<span style="color:blue;">byte</span>[] outImg; <span style="color:#2b91af;">MemoryStream</span> outStrm; <span style="color:#2b91af;">MemoryStream</span> imgStream; <span style="color:#2b91af;">Page</span> pg; <span style="color:green;">//doc.OptimizeResources();</span> <span style="color:blue;">for</span> (<span style="color:blue;">int</span> p = 1; p <= doc.Pages.Count; p++) { pg = doc.Pages[p]; <span style="color:blue;">for</span> (<span style="color:blue;">int</span> i = 1; i <= pg.Resources.Images.Count; i++) { <span style="color:#2b91af;">XImage</span> img = pg.Resources.Images[i]; <span style="color:blue;">using</span> (imgStream = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>()) { img.Save(imgStream, <span style="color:#2b91af;">ImageFormat</span>.Jpeg); imgStream.Position = 0; outImg = imgStream.ToArray(); <span style="color:green;">//outImg = SetJPEGCompression(imgStream.ToArray(), 40);</span> <span style="color:blue;">using</span> (outStrm = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>(outImg)) { pg.Resources.Images.Replace(i, outStrm); outStrm.Flush(); outStrm.Close(); } } } } <span style="color:green;">//doc.OptimizeResources();</span> doc.Pages.Flatten(); doc.Save(destDoc); }</pre><pre style="font-family: Consolas; font-size: 13px; background-color: white; background-position: initial initial; background-repeat: initial initial; ">In the attached PDF are images in the header and the footer. </pre><pre style="font-family: Consolas; font-size: 13px; background-color: white; background-position: initial initial; background-repeat: initial initial; ">If I do the replace of the image, the first page is okay, but on the other pages the header and footer is missing and an error is thrown by acrobot reader.</pre><pre style="font-family: Consolas; font-size: 13px; background-color: white; background-position: initial initial; background-repeat: initial initial; ">The other images are okay.</pre><pre style="font-family: Consolas; font-size: 13px; background-color: white; background-position: initial initial; background-repeat: initial initial; "><br></pre><pre style="font-family: Consolas; font-size: 13px; background-color: white; background-position: initial initial; background-repeat: initial initial; ">The second problem is if you do the "<span style="color: green; background-color: white; ">doc.OptimizeResources();" </span><span style="background-color: white; ">before you replace the images the problem still remains.</span></pre><pre style="font-size: 13px; background-color: white; "><font face="Consolas">If you do the </font><span style="font-family: Consolas; background-color: white; ">"</span><span style="background-color: white; "><font face="Consolas"><font color="#008000">doc.OptimizeResources();" </font>twice (before and after the images are replaced) a null-reference-exception is thrown.</font></span></pre><pre style="font-size: 13px; background-color: white; "><span style="background-color: white; "><font face="Consolas"><br></font></span></pre><pre style="font-size: 13px; background-color: white; "><font face="Consolas">Thanks,</font></pre><pre style="font-size: 13px; background-color: white; "><font face="Consolas">Thomas</font></pre><pre style="font-size: 13px; background-color: white; "><span style="background-color: white; "><font face="Consolas"><br></font></span></pre><pre style="font-family: Consolas; font-size: 13px; background-color: white; background-position: initial initial; background-repeat: initial initial; "><br></pre><pre style="font-family: Consolas; font-size: 13px; background-color: white; background-position: initial initial; background-repeat: initial initial; "><br></pre></div>