English 中文(简体)
文档使用 extsharrp. text.pdf 合并多个 extsharp. text.pdf.PdfReader 对象后, 其外观被切除
原标题:document looks cut after using itextsharp.text.pdf to merge several itextsharp.text.pdf.PdfReader objects

I am using iTextSharp to create a List<PdfReader> _documents with several PDF documents. After using merge on this list to create single paged document and send it to the client I see that the PDF looks cut in Adobe Reader. When I highlight the picture like this I can see it s there :

""https://i.sstatic.net/5rRXe.jpg" alt="此处输入图像描述"/ >

如果我拯救它,它就完全实现。

如果我将 PdfReader 中的一个保存在单PDF文档列表中,而不合并,看起来不错。

""https://i.sstatic.net/7lZsF.jpg" alt="此处的内置图像描述"/ >

合并函数为 :

public void Merge(Stream outputStream)
{
    Document newDocument = null;

    try
    {
        newDocument = new Document();
        // Set margins and page size for the document 
        newDocument.SetMargins(50, 50, 50, 50);
        // There are a huge number of possible page sizes, including such sizes as 
        // EXECUTIVE, LEGAL, LETTER_LANDSCAPE, and NOTE 
        newDocument.SetPageSize(PageSize.A3 );

        PdfWriter pdfWriter = PdfWriter.GetInstance(newDocument, outputStream);

        newDocument.Open();
        PdfContentByte pdfContentByte = pdfWriter.DirectContent;

        if (EnablePagination)
        {
            _documents.ForEach(delegate(PdfReader doc)
            {
                _totalPages += doc.NumberOfPages;
            });
        }

        int currentPage = 1;
        foreach (PdfReader pdfReader in _documents)
        {
            for (int page = 1; page <= pdfReader.NumberOfPages; page++)
            {
                newDocument.NewPage();
                PdfImportedPage importedPage = pdfWriter.GetImportedPage(pdfReader, page);
                pdfContentByte.AddTemplate(importedPage, 0, 0);

                if (EnablePagination)
                {
                    pdfContentByte.BeginText();
                    pdfContentByte.SetFontAndSize(_baseFont, 9);
                    pdfContentByte.ShowTextAligned(PdfContentByte.ALIGN_CENTER,
                        string.Format("{0} of {1}", currentPage++, _totalPages), 520, 5, 0);
                    pdfContentByte.EndText();
                }
            }
        }
    }
    finally
    {
        outputStream.Flush();
        if (newDocument != null)
            newDocument.Close();
        outputStream.Close();
    }
}

I suspect it has something to do with newDocument.SetPageSize(PageSize.A3); but I am not sure and so far I can t find the solution.

最佳回答

只需尝试几个想法。 问题可能与缩放或缩放有关。 比较两个文档的横向缩放。 另外, 导入的 Page. PdfDocument. PageSize 需要与 pdfContentByte. PdfDocument.PageSize 比较, 并可能缩放 。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签