Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.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编写器内容被剪切_C#_Asp.net_Itextsharp - Fatal编程技术网

C# iTextSharp PDF编写器内容被剪切

C# iTextSharp PDF编写器内容被剪切,c#,asp.net,itextsharp,C#,Asp.net,Itextsharp,我使用iTextSharp将页脚注释添加到现有pdf中。问题是当我访问pdf文件并根据其内容创建另一个文件时,页面的方向会发生变化,内容会被切断。 我使用的代码是: //using itextsharp string oldFile = dtroldp + strfn; if (File.Exists(oldFile)) { string newFile = strpath + "sys_" + docid + strext; PdfReader reader = new Pd

我使用iTextSharp将页脚注释添加到现有pdf中。问题是当我访问pdf文件并根据其内容创建另一个文件时,页面的方向会发生变化,内容会被切断。 我使用的代码是:

//using itextsharp
string oldFile = dtroldp + strfn;
if (File.Exists(oldFile))
{
    string newFile = strpath + "sys_" + docid + strext;

    PdfReader reader = new PdfReader(oldFile);
    int numberOfPages = reader.NumberOfPages;
    FileStream fs = new FileStream(newFile, FileMode.Create, FileAccess.Write);

     Document document = new Document();

    // open the writer
    PdfWriter writer = PdfWriter.GetInstance(document, fs);
    writer.PageEvent = new PDFFooter();

    document.Open();

    for (int i = 1; i <= numberOfPages; i++)
    {
        document.SetPageSize(reader.GetPageSizeWithRotation(1));

        document.NewPage();
        PdfContentByte cb = writer.DirectContent;

        //// select the font properties
        BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.SetColorFill(BaseColor.BLACK);
        cb.SetFontAndSize(bf, 32);

        // write the text in the pdf content
        cb.BeginText();

        cb.EndText();

        PdfImportedPage page = writer.GetImportedPage(reader, i);

        cb.AddTemplate(page, 0, 0);
    }

    document.Close();

    fs.Close();
    writer.Close();
    reader.Close();
}
//使用itextsharp
字符串oldFile=dtroldp+strfn;
如果(File.Exists(oldFile))
{
字符串newFile=strpath+“sys_u”+docid+strext;
PdfReader reader=新PdfReader(旧文件);
int numberOfPages=reader.numberOfPages;
FileStream fs=newfilestream(newFile,FileMode.Create,FileAccess.Write);
文档=新文档();
//打开书写器
PdfWriter writer=PdfWriter.GetInstance(文档,fs);
writer.PageEvent=new PDFFooter();
document.Open();

对于(inti=1;i您的方法完全错误。请扔掉您的代码

使用
PdfReader
PdfStamper
不使用
Document
PdfWriter
向现有PDF添加内容。请先阅读此问题的答案:

在本例中,我们在绝对位置添加了一些水印。在您的情况下,您的页面大小不同,因此不应使用绝对位置。您应按照此问题的答案计算
x
y
值:

您需要知道以下问题的答案:


结合所有这些智慧,您应该能够使用适当的类和方法在适当的位置添加页脚。

请附上生成的PDF的屏幕截图。删除您的代码。阅读。阅读关于
PdfStamper的所有答案。
。感到惭愧,因为您没有先阅读文档,因为您正在这么做把它搞错了。