0

我编写了此代码以在现有 pdf 的第 2 页合并插入 pdf。有用。但问题是插入的pdf处于横向模式,即大小不同,但实际上它处于纵向模式,但插入后进入横向模式,不知道为什么。如何设置?

private static string AppendToDocument(string FirstSource, string SecondSource)
{
    String first_source =  FirstSource; 
    String second_source = SecondSource; 
    String pathout = "D:/Shared Data/test.pdf";
    //create a document object
    //var doc = new Document(PageSize.A4);
    //create PdfReader objects to read pages from the source files
    PdfReader reader = new PdfReader(first_source);
    PdfReader reader1 = new PdfReader(second_source);
    //create PdfStamper object to write to the pages read from readers 
    PdfStamper stamper = new PdfStamper(reader1, new FileStream(pathout, FileMode.Create));
    //get one page from htmlpdf.pdf
    PdfImportedPage page = stamper.GetImportedPage(reader, 1);
    //the page gotten from htmlpdf.pdf will be inserted at the second page in the first source doc
    stamper.InsertPage(2, reader1.GetPageSize(1));
    //insert the page
    PdfContentByte pb = stamper.GetUnderContent(2);
    pb.AddTemplate(page, 0, 0);
    //close the stamper
    stamper.Close();

    return pathout;
}

FirstSource并且SecondSource是物理路径。

4

0 回答 0