Insert a small pdf file into a larger sheet as an image


#1

I need to insert a series of different small pdf “Snippets” into a larger pdf page that I am creating.

I am using this code. I am not sure that the a and d values of the matrix are correct.

Also,

I need to insert the pdf snippet rotated.

here is my attempt to insert a small pdf snippet into a larger pdf file.

    public static void ExecInsertImageTest()
    {
        Aspose.Pdf.Document doc = new Document();
        Aspose.Pdf.Page p = doc.Pages.Add();
        p.PageInfo.Height = 11.0f * 72.0f;
        p.PageInfo.Width = 8.5f * 72.0f;
        p.PageInfo.Margin.Bottom = 0.0f;
        p.PageInfo.Margin.Top = 0.0f;
        p.PageInfo.Margin.Left = 0.0f;
        p.PageInfo.Margin.Right = 0.0f;
        FileStream ifs = new FileStream("SnippetFileName.pdf", FileMode.Open);
        p.Resources.Images.Add(ifs);
        p.Contents.Add(new Aspose.Pdf.Operators.GSave());
        Aspose.Pdf.Rectangle rect = new Aspose.Pdf.Rectangle(447.3f, 703.1475, 594.36f,768.338f);
        Aspose.Pdf.Matrix ma = new Aspose.Pdf.Matrix(new double[]
        {
            147.06f, 0f, 0f, 65.1905f,
            447.3f, 703.145f
        });
        p.Contents.Add(new Aspose.Pdf.Operators.ConcatenateMatrix(ma));
        Aspose.Pdf.XImage xi = p.Resources.Images[p.Resources.Images.Count];
        p.Contents.Add(new Aspose.Pdf.Operators.Do(xi.Name));
        p.Contents.Add(new Aspose.Pdf.Operators.GRestore());
        doc.Save("Example File.pdf");
    }

Title Block ssmall.pdf (100.3 KB)


#2

@csludtke

Thank you for contacting support.

You may first Convert PDF Page to image and later Add Image Stamp in PDF File as per your requirements.

We hope this will be helpful. Please feel free to contact us if you need any further assistance.


#3

The application I am working on leverages small pdf “Snippets” that contain text, Images and Hyperlinks.

The Application creates larger pdf files utilizing multiple numbers of these “Snippets”.

If I convert the snippets to images (such as jpeg, png or bitmap), I will lose the following functionality.

Ability to leverage hyperlink data that exists within each snippet.
The ability to highlight and copy text from Adobe Reader that exists within the Snippet.

Does Aspose have any functionality that will allow me to insert the contents of 1 or more small pdfs into a larger pdf and manage the location of the contents of the small pdf within the larger pdf page?


#4

I was able to meet my requirements using the PdfPageStamp object.

    private static void WImage(string fileName i, Page p)
    {

        Aspose.Pdf.PdfPageStamp importedPdfPageStamp = new Aspose.Pdf.PdfPageStamp(fileName, 1)
            XIndent = 200,
            YIndent = 400,
            Width = 100,
            Height = 100,
            RightMargin = 0.0f,
            LeftMargin = 0.0f,
            TopMargin = 0.0f,
            BottomMargin = 0.0f,
            OutlineWidth = 0.0f,
            OutlineOpacity = 1.0,
            Background = true
        };
        importedPdfPageStamp.Put(p);

}

Thanks!


#5

@csludtke

Thank you for your kind feedback.

We are glad to know that you have been able to achieve required results. Please feel free to contact us if you need any further assistance. We will be more than happy to help you.