I'm using version 10 and trying to insert a tiff image in a pdf after a certain page. In another process I want to extract all the images from that pdf.
To insert the tiff image I use code below:
Code: Select all
string image_res_name = gdPicturePDF.AddImageFromGdPictureImage(imageId, false, false);
var pageHeight = gdPictureImaging.GetHeight(imageId);
var pageWidth = gdPictureImaging.GetWidth(imageId);
gdPictureImaging.ReleaseGdPictureImage(imageId);
gdPicturePDF.SetOrigin(PdfOrigin.PdfOriginBottomLeft);
gdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitPoint);
gdPicturePDF.InsertPage(pageWidth, pageHeight, pageIndex + 1);
gdPicturePDF.SelectPage(pageIndex + 1);
//Draw the image on the PDF page
gdPicturePDF.DrawImage(image_res_name, 0, 0, pageHeight, pageWidth);
//gdPicturePDF.AddImageFromGdPictureImage(imageId, false, true);
gdPicturePDF.SaveToFileInc(pdfFileOutputPath);
gdPicturePDF.CloseDocument();
In an other process I use code below to get all images from a pdf:
Code: Select all
gdPicturePDF.SelectPage(pageIndex + 1);
//Rendering the selected page to an image
int imageId = gdPicturePDF.RenderPageToGdPictureImageEx(200, false);
//checking if the image was rendered successfuly
if (imageId != 0)
{
//saving the image back to outputstream
gdPictureImaging.SaveAsStream(imageId, pngOutputStream, DocumentFormat.DocumentFormatPNG, 9);
gdPictureImaging.ReleaseGdPictureImage(imageId);
pngOutputStream.Position = 0;
result = true;
}
I have tried to rewrite code but then I'm facing another problem. I can use the code below to insert the tiff at the and, which i don't want but fro testing it was ok:
Code: Select all
gdPicturePDF.InsertPage(PdfPageSizes.PdfPageSizeA4, pageIndex + 1);
gdPicturePDF.SelectPage(pageIndex + 1);
//adding image as a resource and drawing it in a new page
gdPicturePDF.AddImageFromGdPictureImage(imageId, false, true);
if (gdPicturePDF.GetStat() == GdPictureStatus.OK)
{
//Save the new PDF to file
gdPicturePDF.SaveToFileInc(pdfFileOutputPath);
result = true;
}
//Clear resources
gdPicturePDF.CloseDocument();
gdPictureImaging.ReleaseGdPictureImage(imageId);
Due to the fact that I use a stream as input for reading the pdf which I get from my application, I've written al the gdPicture logic in a different project which will become a Library, rewriting code an rebuilding pdf files with remembering indexes, pages old en new pdf file is not realy an option.
I think I missed something, but can't figure out what.
Kind regards,
Bas