pdfにテキストをスタンプするだけで、itextsharpは破損したファイルを作成します。文書が何ページのルートがありません:「iTextSharp.text.exceptions.InvalidPdfException」 追加情報タイプのItextsharpはテキストをスタンプした後に破損したpdfを作成します
例外を次のようにエラーがスローされますPDFファイルの読み取りしようとしたときに(意味を:それは無効なPDFです)。コードは、PDFファイルがApacheのFOP 1.1とitextsharpで作成されたPDFやスタンプ、テキストコンテンツ
using (PdfReader pdfReader = new PdfReader(System.IO.File.ReadAllBytes(pdfPath))) using (Stream pdfStream = new FileStream(pdfPath, FileMode.Open, FileAccess.ReadWrite)) { PdfReaderContentParser parserReason = new PdfReaderContentParser(pdfReader); PdfStamper pdfStamper = new PdfStamper(pdfReader, pdfStream); PdfContentByte pdfContentByte = pdfStamper.GetOverContent(pdfReader.NumberOfPages); BaseFont baseFont = BaseFont.CreateFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED); pdfContentByte.SetColorFill(BaseColor.BLACK); pdfContentByte.SetFontAndSize(baseFont, 12); pdfContentByte.BeginText(); TextMarginFinder finderReason = parserReason.ProcessContent(pdfReader.NumberOfPages, new iTextSharp.text.pdf.parser.TextMarginFinder()); pdfContentByte.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Some text : " + annotation, finderReason.GetLlx(), finderReason.GetLly() - 20f, 0); pdfContentByte.EndText(); pdfStamper.Close(); }
を編集するために使用された後は、file.Theの問題がすべてで起きていない編集するために使用される
pdfファイルの場合のみです。 You can find the PDF which creates the issue here
問題のPDFを投稿すると、ページルートがないかどうかを確認するのにも役立ちます。 – confusedandamused
ありがとう@confusedandamused。私はファイルをアップロードし、私の質問をリンクで更新しました。 –