Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# iTextSharp PDF页脚在Adobe Reader中不可见_C#_Pdf_Itext_Footer - Fatal编程技术网

C# iTextSharp PDF页脚在Adobe Reader中不可见

C# iTextSharp PDF页脚在Adobe Reader中不可见,c#,pdf,itext,footer,C#,Pdf,Itext,Footer,我使用下面显示的代码将页脚文本添加到每个页面的现有字节中,这在Chrome和Foxit PhantomPDF中都可见,但在Adobe PDF reader中不可见 除了页脚,我还添加了页眉,这些页眉即使在Adobe中也是可见的 private byte[] AddPageHeaderFooter(byte[] pdf, float marginLeft, float marginRight, float marginTop, float marginBottom, DataSet pro

我使用下面显示的代码将页脚文本添加到每个页面的现有字节中,这在Chrome和Foxit PhantomPDF中都可见,但在Adobe PDF reader中不可见

除了页脚,我还添加了页眉,这些页眉即使在Adobe中也是可见的

private byte[] AddPageHeaderFooter(byte[] pdf, float marginLeft, float marginRight, float marginTop,
    float marginBottom, DataSet prospectDetails, ref int startingPageNumber, string logoPath, bool isLandscape = false)
{
    var dataRow = prospectDetails.Tables[0].Rows[0];
    var prospectDate = Convert.ToDateTime(dataRow[0]);

    using (var stream = new MemoryStream())
    {
        stream.Write(pdf, 0, pdf.Length);
        var reader = new PdfReader(pdf);
        var document = new Document(reader.GetPageSizeWithRotation(1), marginLeft, marginRight, marginTop,
            marginBottom);
        var writer = PdfWriter.GetInstance(document, stream);
        document.Open();
        var contentByte = writer.DirectContent;
        var pageIndex = startingPageNumber;
        for (var page = 1; page <= reader.NumberOfPages; page++)
        {
            document.NewPage();
            pageIndex++;
            var importedPage = writer.GetImportedPage(reader, page);
            if (isLandscape)
                contentByte.AddTemplate(importedPage, 0, -1f, 1f, 0, 0,
                    reader.GetPageSizeWithRotation(page).Height);
            else
                contentByte.AddTemplate(importedPage, 0, 0);
            contentByte.BeginText();
            var baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

            // Code to add header 

            // Footer
            // Not visible parts **START**
            contentByte.SetFontAndSize(baseFont, 7);
            var prospectDateString = string.Format("{0:ddd, MMM d, yyyy}", prospectDate);
            contentByte.ShowTextAligned(PdfContentByte.ALIGN_CENTER,
                "FOOTER LINE 1",
                isLandscape ? 398 : 305f, 50, 0);
            contentByte.ShowTextAligned(PdfContentByte.ALIGN_CENTER,
                "FOOTER LINE 2", isLandscape ? 398 : 305f, 42, 0);
            contentByte.ShowTextAligned(PdfContentByte.ALIGN_LEFT,
                prospectDateString.Substring(5, prospectDateString.Length - 5), document.Left, marginBottom, 0);
            contentByte.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "-     " + pageIndex + "     -",
                isLandscape ? 398 : 305f, marginBottom, 0);
            contentByte.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, string.Format("{0:T}", prospectDate),
                document.Right, marginBottom, 0);
            contentByte.EndText();
            contentByte.SaveState();
            // Not visible parts **END**

            // Footer line
            // Not visible parts **START**
            contentByte.SetColorStroke(new PdfSpotColor("black", new BaseColor(0, 0, 0)), 100);
            contentByte.SetLineWidth(0.25f);
            contentByte.Rectangle(marginLeft, 58, isLandscape ? 732 : 552, 0.25f);
            contentByte.FillStroke();
            // Not visible parts **END**

            contentByte.RestoreState();
        }
        startingPageNumber = pageIndex;
        document.Close();
        return stream.ToArray();
    }
}
private byte[]AddPageHeaderFooter(byte[]pdf,float-marginLeft,float-marginRight,float-marginTop,
float marginBottom、数据集prospectDetails、ref int startingPageNumber、字符串logoPath、bool isLandscape=false)
{
var dataRow=prospectDetails.Tables[0]。行[0];
var prospectDate=Convert.ToDateTime(数据行[0]);
使用(var stream=new MemoryStream())
{
stream.Write(pdf,0,pdf.Length);
var阅读器=新的pdf阅读器(pdf);
var document=新文档(reader.GetPageSizeWithRotation(1)、marginLeft、marginRight、marginTop、,
marginBottom);
var writer=PdfWriter.GetInstance(文档、流);
document.Open();
var contentByte=writer.DirectContent;
var pageIndex=起始页码;

对于(var page=1;page请共享一个用于分析的示例结果PDF。实际上,我要求提供一个用于分析的示例结果PDF。你可以在某些查看器中看到文本,而在其他查看器中看不到文本,因此显而易见的途径是检查PDF内部。这显然不适用于屏幕截图…@mkl我没有权限共享该文档,即problem@mkl您可以在我可以阅读和检查您提到的内部结构的地方共享任何链接吗?尝试查找一个中性PDF(您可以共享的)我会检查内部结构和命令流,寻找出错的线索;为此,我会使用iText RUPS或PDFBox调试器等工具,并在另一个窗口中打开PDF规范。