I've been experimenting with the page insertion in PDF lately and I can't figure out why the pages that are added to an existing PDF are oversized. It does not happen when I append image. You can see the the actual view after insertion (text have been redacted) in the os.png attachment.
Following is the code snippet used:
Code: Select all
private static void Insert(GdPictureImaging gdp)
{
var position = 3;
var searchable = true;
var idx = 1;
var inserts = Directory.GetFiles(@".\add");
var pdf = new GdPicturePDF();
pdf.LoadFromFile(@".\base.pdf", true);
if (position > 0) {
idx = position;
}
else
idx = pdf.GetPageCount();
foreach (var insert in inserts)
{
var id = gdp.CreateGdPictureImageFromFile(insert);
if (position == -1) {
pdf.AddImageFromGdPictureImage(id, PdfAdvancedImageCompression.PdfAdvancedImageCompressionColorDetection);
pdf.SelectPage(++idx);
}
else
{
var res = pdf.AddImageFromGdPictureImage(id, false, false);
var width = (float)gdp.GetWidth(id);
var height = (float)gdp.GetHeight(id);
pdf.InsertPage(width, height, idx);
pdf.SelectPage(idx++);
pdf.DrawImage(res, 0, 0, width, height);
}
if (searchable)
pdf.OcrPage("eng+fra", @".\data", string.Empty, 200f);
}
pdf.SaveToFile(@".\base.pdf");
pdf.Dispose();
}
Thanks for your help!