Sorry Just had a meeting ..i am running in to go/ no go situation here. quite a lot of files there(SVN).. any specfic ones you'd like me to look at for multi threading?
i feel so close yet not fully there.. any help would be much appreciated here.. i have attached more files which were corrupted even though i used file stream instead of memory stream.. Atached are files File names Originals 1809472_Transcript_7_2008-02_06-06-02.pdf 1809475_Transcript_7_2008-02_05-51-03.pdf Files names after water marking - corrupted 1809472_Transcript_7_2008-02_06-06-02_3055364.pdf 1809472_Transcript_7_2008-02_06-06-02_3055365.pdf my current code - avoded memoery stream and using file stream that did not help either (:. Same orignal files would NOT be corrupt if i re processed them. This is why i am having hard time. not consitant here. public static void WaterMarkPdf(string sourceFile, string destinationFile, string waterMark) { PdfReader reader = new PdfReader(sourceFile); using (FileStream fStream = new FileStream(destinationFile, FileMode.Create, FileAccess.ReadWrite)) { PdfStamper pdfStamper = new PdfStamper(reader, fStream); // process every page in the pdf file for (int i = 1; i <= reader.NumberOfPages; i++) { Rectangle pageSize = reader.GetPageSizeWithRotation(i); PdfContentByte pdfPageContents = pdfStamper.GetUnderContent(i); PdfAnnotation annotation = PdfAnnotation.CreateText(pdfStamper.Writer, new Rectangle(200f, 400f, 300f, 500f), waterMark, "Digital Watermark", false, "Key"); //digital water marking annotation.Flags = PdfAnnotation.FLAGS_NOVIEW | PdfAnnotation.FLAGS_INVISIBLE | PdfAnnotation.FLAGS_HIDDEN; pdfStamper.AddAnnotation(annotation, i); pdfPageContents.BeginText(); BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, Encoding.ASCII.EncodingName, BaseFont.NOT_EMBEDDED); pdfPageContents.SetFontAndSize(baseFont, 10); pdfPageContents.SetRGBColorFill(225, 224, 223); // visible water marking Rectangle pdfCropBox = reader.GetCropBox(i); float posX = pdfCropBox.Width < pageSize.Width ? pdfCropBox.Width : pageSize.Width; float posY = pdfCropBox.Height < pageSize.Height ? pdfCropBox.Height : pageSize.Height; pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, waterMark, posX - 50, posY - 15, 0); pdfPageContents.EndText(); pdfStamper.Writer.CloseStream = false; pdfStamper.FormFlattening = true; } pdfStamper.Close(); } } Thanks Subrah Paulo Soares-3 wrote: > > https://itextsharp.svn.sourceforge.net/svnroot/itextsharp/trunk/src/core > >> -----Original Message----- >> From: subrah [mailto:subnibh...@gmail.com] >> Sent: Tuesday, November 17, 2009 4:32 PM >> To: itext-questions@lists.sourceforge.net >> Subject: Re: [iText-questions] Root Object is invalid or >> missing after PDF is manipulated with iTextSharp >> >> >> Hi Paulo, >> >> Thank you. Sorry if i am missing something. so where is the >> SVN repository >> url to check out the code for multi threading? Thanks >> Subrah >> >> >> Paulo Soares-3 wrote: >> > >> > Try the code in the SVN, it fixes a problem in heavy multithreading. >> > >> > Paulo >> > >> > ----- Original Message ----- >> > From: "subrah" <subnibh...@gmail.com> >> > To: <itext-questions@lists.sourceforge.net> >> > Sent: Monday, November 16, 2009 8:12 PM >> > Subject: Re: [iText-questions] Root Object is invalid or >> missing after PDF >> > is manipulated with iTextSharp >> > >> > >> > >> > Attached is the corrupt file. >> > if i try to read the corrupted file using pdfreader i get the error >> > message >> > saying "start ref not found". But the issue is that problem is not >> > consistant. I am able to water mark the same original file >> 2nd time using >> > the same code. So it's like randomly some file is not fully written. >> > >> > i am gussing this is because the pdfstamper is closing the >> memory stream >> > earlier than it should for some reason. However what i want >> to confirm is >> > that my understanding that the probelm is infact the memory >> stream is >> > right >> > or not?. Because i have implmented alternative technique to >> compltely >> > avoid >> > memory stream and pdf stamper but use pdfwriter and file >> stream which seem >> > to have fixed the issue in dev. But still need to get >> response from a >> > heavy >> > testing team. Any light thrwon on this subject will be of >> great help to >> > me. >> > >> > Thanks >> > Subrah >> > >> > >> > >> > Mark Storer-2 wrote: >> >> >> >> A: Most of the folks on the list lean toward Java. >> >> B: If no one knows the answer, no one answers. >> >> >> >> Perhaps you could post one of your corrupted PDFs? >> >> >> >> --Mark Storer >> >> Senior Software Engineer >> >> Cardiff.com >> >> >> >> #include <disclaimer> >> >> typedef std::Disclaimer<Cardiff> DisCard; >> >> >> >> >> >> >> >>> -----Original Message----- >> >>> From: subrah [mailto:subnibh...@gmail.com] >> >>> Sent: Monday, November 16, 2009 8:50 AM >> >>> To: itext-questions@lists.sourceforge.net >> >>> Subject: Re: [iText-questions] Root Object is invalid or >> missing after >> >>> PDF is manipulated with iTextSharp >> >>> >> >>> >> >>> >> >>> Hi All, >> >>> >> >>> I am wondering why nobody is interested in responding to my >> >>> question? I seem >> >>> to have found a fix but just wanted to confirm with experts >> >>> on this forum. >> >>> So any help is greatly appreciated. >> >>> >> >>> Thanks >> >>> Subrah >> >>> >> >>> >> >>> >> >>> subrah wrote: >> >>> > >> >>> > Hi >> >>> > Sorry resending this post as i was not registered user earlier. >> >>> > >> >>> > i am using latest iTextSharp library to edit the pdf >> >>> documents to put the >> >>> > water marking digitallly (hidden). So when i researched i >> >>> found that i can >> >>> > add a annotation to the pdf document and then set the flags to >> >>> > annotation.Flags = PdfAnnotation.FLAGS_NOVIEW | >> >>> > PdfAnnotation.FLAGS_INVISIBLE | PdfAnnotation.FLAGS_HIDDEN; >> >>> to make it >> >>> > invisible. >> >>> > >> >>> > so this is working fine as expected 90% of the time. >> >>> Remaning 10 % of the >> >>> > time i get an error when i open the document after adding >> >>> the annotation >> >>> > it says "Root object is invalid or missing" >> >>> > >> >>> > so looks like it corrupted the file trying to add the >> >>> annoation. do you >> >>> > have any suggestion? i can share the code i am using to add >> >>> the annotation >> >>> > if that helps. >> >>> > >> >>> > Full code >> >>> > public static byte[] EditPdf(string sourceFile, string >> >>> visibleWaterMark, >> >>> > string digitalWaterMark) >> >>> > { >> >>> > PdfReader reader = new PdfReader(sourceFile); >> >>> > using (MemoryStream memoryStream = new >> MemoryStream()) >> >>> > { >> >>> > PdfStamper pdfStamper = new PdfStamper(reader, >> >>> > memoryStream); >> >>> > // process every page in the pdf file >> >>> > for (int i = 1; i <= reader.NumberOfPages; i++) >> >>> > { >> >>> > Rectangle pageSize = >> >>> > reader.GetPageSizeWithRotation(i); >> >>> > PdfContentByte pdfPageContents = >> >>> > pdfStamper.GetUnderContent(i); >> >>> > PdfAnnotation annotation = >> >>> > PdfAnnotation.CreateText(pdfStamper.Writer, new >> >>> Rectangle(200f, 400f, >> >>> > 300f, 500f), digitalWaterMark, >> >>> > "Street Events >> >>> Digital Watermark", >> >>> > false, "Key"); >> >>> > //digital water marking >> >>> > annotation.Flags = >> PdfAnnotation.FLAGS_NOVIEW | >> >>> > PdfAnnotation.FLAGS_INVISIBLE | PdfAnnotation.FLAGS_HIDDEN; >> >>> > pdfStamper.AddAnnotation(annotation, i); >> >>> > pdfPageContents.BeginText(); >> >>> > BaseFont baseFont = >> >>> > BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, >> >>> Encoding.ASCII.EncodingName, >> >>> > BaseFont.NOT_EMBEDDED); >> >>> > >> pdfPageContents.SetFontAndSize(baseFont, 10); >> >>> > >> pdfPageContents.SetRGBColorFill(225, 224, 223); >> >>> > // visible water marking >> >>> > >> >>> > pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, >> >>> > visibleWaterMark, >> >>> > >> >>> pageSize.Width - 50, >> >>> > >> >>> pageSize.Height - 15, >> >>> > 0); >> >>> > pdfPageContents.EndText(); >> >>> > pdfStamper.FormFlattening = true; >> >>> > >> >>> > } >> >>> > >> >>> > pdfStamper.Close(); >> >>> > return memoryStream.ToArray(); >> >>> > } >> >>> > >> >>> > >> >>> > >> >>> > public static void SaveFile(string fileHandle, byte[] >> fileBytes) >> >>> > { >> >>> > using(FileStream fs = new FileStream(fileHandle, >> >>> > FileMode.Create)) >> >>> > { >> >>> > fs.Write(fileBytes, 0, fileBytes.Length); >> >>> > fs.Flush(); >> >>> > fs.Close(); >> >>> > } >> >>> > >> >>> > } >> >>> > >> >>> > //call >> >>> > FileInfo pdfFileInfo = new FileInfo(newFilePath); >> >>> > byte[] fileBytes = PdfWaterMarker.EditPdf(pdfFileInfo, >> >>> > string.Format("Client Id: {0}", clientSite.ClientId)); >> >>> > PdfWaterMarker.SaveFile(newFilePath, fileBytes); >> >>> > >> >>> > please let me know >> >>> > Thanks >> >>> > Subrah >> >>> > >> >>> > >> >>> >> >>> -- >> >>> View this message in context: >> >>> http://old.nabble.com/Root-Object-is-invalid-or-missing-after- >> >> PDF-is-manipulated-with-iTextSharp-tp26305073p26375297.html >> >> Sent from the iText - General mailing list archive at Nabble.com. > > > Aviso Legal: > > Esta mensagem é destinada exclusivamente ao destinatário. Pode conter > informação confidencial ou legalmente protegida. A incorrecta transmissão > desta mensagem não significa a perca de confidencialidade. Se esta > mensagem for recebida por engano, por favor envie-a de volta para o > remetente e apague-a do seu sistema de imediato. É proibido a qualquer > pessoa que não o destinatário de usar, revelar ou distribuir qualquer > parte desta mensagem. > > > > Disclaimer: > > This message is destined exclusively to the intended receiver. It may > contain confidential or legally protected information. The incorrect > transmission of this message does not mean the loss of its > confidentiality. If this message is received by mistake, please send it > back to the sender and delete it from your system immediately. It is > forbidden to any person who is not the intended receiver to use, > distribute or copy any part of this message. > > > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 > 30-Day > trial. Simplify your report design, integration and deployment - and focus > on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > iText-questions mailing list > iText-questions@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/itext-questions > > Buy the iText book: http://www.1t3xt.com/docs/book.php > Check the site with examples before you ask questions: > http://www.1t3xt.info/examples/ > You can also search the keywords list: > http://1t3xt.info/tutorials/keywords/ > http://old.nabble.com/file/p26396462/1809472_Transcript_7_2008-02_06-06-02_3055365.pdf 1809472_Transcript_7_2008-02_06-06-02_3055365.pdf http://old.nabble.com/file/p26396462/1809472_Transcript_7_2008-02_06-06-02_3055364.pdf 1809472_Transcript_7_2008-02_06-06-02_3055364.pdf http://old.nabble.com/file/p26396462/1809472_Transcript_3_2008-02_06-06-02.pdf 1809472_Transcript_3_2008-02_06-06-02.pdf http://old.nabble.com/file/p26396462/1809475_Transcript_3_2008-02_05-51-03.pdf 1809475_Transcript_3_2008-02_05-51-03.pdf -- View this message in context: http://old.nabble.com/Root-Object-is-invalid-or-missing-after-PDF-is-manipulated-with-iTextSharp-tp26305073p26396462.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.1t3xt.com/docs/book.php Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/