HTML JPG PDF XML DOCX
  Product Family
PDF

Work with images in PDF in Go SDK

Manipulate images in PDF Document using server-side Go API.

Get Started

How to work with images via Cloud Go SDK

In order to work with images in PDF via Cloud Go SDK , we’ll use Aspose.PDF Cloud Go SDK This Cloud Go SDK assists Go programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Go programming language via Aspose.PDF REST API. Use the following command from the Package Manager Console.

Package Manager Console Command


     
    go get -u github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25
     
     

Steps to create a image via Go SDK

Aspose.PDF Cloud developers can easily load & create image in PDF in just a few lines of code.

  1. Initialize the Aspose PDF API
  2. Upload the PDF Document to Cloud Storage
  3. Reads a local image file and uploads it to the Aspose.PDF Cloud storage.
  4. Inserts the uploaded image into the uploaded PDF file at a specific location.
  5. Download the result if needed it
 

This sample code shows creating a image in PDF documents


    func AppendImage() {
        localFolder := "C:\\Samples"
        storageDocumentName := "sample.pdf"
        localImagePath := "C:\\Samples\\sample.jpg"
        storageImageFile := "sample.jpg"
        storageTempFolder := "TempPdfCloud"
        outputFileName := "output_add_images.pdf"

        AppSID := "5********************" // Your Application SID
        AppKey := "*****************"     // Your Application Key

        pdfApi := asposepdfcloud.NewPdfApiService(AppSID, AppKey, "")

        args := map[string]interface{}{
            "folder":        storageTempFolder,
            "imageFilePath": filepath.Join(storageTempFolder, storageImageFile),
        }

        file, _ := os.Open(filepath.Join(localFolder, storageDocumentName))
        _, _, _ = pdfApi.UploadFile(filepath.Join(storageTempFolder, storageDocumentName), file, args)

        imageFile, _ := os.Open(localImagePath)
        _, _, _ = pdfApi.UploadFile(filepath.Join(storageTempFolder, storageImageFile), imageFile, args)

        pageNumber := int32(1)
        llx := 10.
        lly := 10.
        urx := 100.
        ury := 100.

        _, httpResponse, err := pdfApi.PostInsertImage(storageDocumentName, pageNumber, llx, lly, urx, ury, args)
        if err != nil {
            fmt.Println(err.Error())
        } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
            fmt.Println("AppendImage()): Failed to append image to the document.")
        } else {
            result_data, _, _ := pdfApi.DownloadFile(filepath.Join(storageTempFolder, storageDocumentName), args)
            fileName := path.Join(localFolder, outputFileName)
            f, _ := os.Create(fileName)
            _, _ = f.Write(result_data)
            fmt.Println("AppendImage(): image '" + storageImageFile + "' appended successfully to the document '" + outputFileName + "'.")
        }
    }
 

With our Go SDK you can

  • Add PDF document’s header & footer in text or image format.
  • Add tables & text or image stamps to PDF documents.
  • Append multiple PDF documents to an existing file.
  • Work with PDF attachments, annotations, & form fields.
  • Apply encryption or decryption to PDF documents & set a password.
  • Delete all stamps & tables from a page or entire PDF document.
  • Delete a specific stamp or table from the PDF document by its ID.
  • Replace single or multiple instances of text on a PDF page or from the entire document.
  • Extensive support for converting PDF documents to various other file formats.
  • Extract various elements of PDF files & make PDF documents optimized.
  • You can try out our free App to replace the images in PDF files online and test the functionality.

  •