问题
When I copy document
var document = new Document();
var writer = PdfWriter.GetInstance(document, memoryStream);
document.Open();
var cb = writer.DirectContent;
var reader = new PdfReader(this_file_name);
document.SetPageSize(reader.GetPageSizeWithRotation(1));
document.NewPage();
var page = writer.GetImportedPage(reader, 1);
cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
document.CloseDocument(); writer.Close();
When I open new document - it's empty. I try change pdf version and compression level - no results. I can't use PdfStamper, bacause after copy document need insert some text and image.this bad file
回答1:
That PDF is a good example of why it is never a good idea to assume that 0,0
corresponds to the "lower left corner". PDFs are actually free to redefine their coordinate space as they see fit. That PDF has this specific entry for page 1:
/MediaBox [0, -1693.08, 2396.52, 0]
This offsets the y
parameter by 1693.08 units "downwards". Luckily this is pretty easy to fix. You're setting the page size correctly but you also want to use that page size's coordinates when placing the template:
var s = reader.GetPageSizeWithRotation(1);
cb.AddTemplate(page, s.Left, s.Bottom);
来源:https://stackoverflow.com/questions/33100786/blank-page-when-copy-document