Zip file not able to open in PDF

When ever any zip files attach to PDF, that I am not able to save/open. While opening getting error in attached image, any java code can help in removing this error so I can download successfully.

image.png (11.6 KB)

@sinar3x

It seems that the issue you’re experiencing with opening ZIP file attachments in a PDF is related to limitations in Adobe Reader rather than a problem with the Aspose API itself. Users have reported similar issues, and it may be beneficial to check related discussions on forums where solutions have been suggested, such as ensuring the file is properly transformed for compatibility with Adobe Reader.

If you want to remove the ZIP attachments from the PDF to avoid this error, you can use the following Java code snippet. This code demonstrates how to delete all attachments from a PDF document using Aspose.PDF:

package com.aspose.pdf.examples.AsposePdfExamples.Attachments;

import com.aspose.pdf.Document;
import com.aspose.pdf.examples.Utils;

public class DeleteAllAttachmentsFromPDF {

    public static void main(String[] args) {
        runExamples();
    }

    public static void runExamples() {
        // The paths to resources and output directories.
        String testID = "com/aspose/pdf/examples/AsposePdf/Attachments/deleteallattachments/";
        String dataDir = Utils.getDataDir(testID);
        String outputDir = Utils.getOutDir(testID);

        System.out.println("============================");
        System.out.println("Example deleteAllAttachmentsFromPDF start");
        deleteAllAttachmentsFromPDF(dataDir, outputDir);
        System.out.println("Example deleteAllAttachmentsFromPDF end");
    }

    private static void deleteAllAttachmentsFromPDF(String dataDir, String outputDir) {
        // Open a document
        Document pdfDocument = new Document(dataDir + "input.pdf");
        // Delete all attachments
        pdfDocument.getEmbeddedFiles().delete();
        // Save the updated file
        pdfDocument.save(outputDir + "output.pdf");
    }
}

This code will open a specified PDF file, remove all embedded files (attachments), and save the modified document. Make sure to replace "input.pdf" with the path to your actual PDF file.

If you continue to face issues, consider checking the Adobe Reader forums for additional insights or potential fixes related to ZIP file handling.

Sources:
[1]: PDF ZIP Attachments - cannot Save Zip Attachment in Adobe Reader
[2]: DeleteAllAttachmentsFromPDF.java

I don’t know much about this type of zip file. But I would like to learn more. Thank you so much!

@ClarkLawson

Are you adding the .zip attachments in PDF yourself or just receiving such files from external sources? Can you please share the sample code snippet and the sample file for our reference so that we can test the scenario in our environment and address it accordingly.

I am adding the zip attachments by referring Aspose code

image.png (255.7 KB)

@sinar3x

Can you please share your sample source PDF and .zip files for our reference? We will test the scenario in our environment and address it accordingly.

Hi Ali,

You can use any zip and attach in pdf using some sample code and see zip attachment can be open/save in your local.

@sinar3x

We tested in our environment using below code snippet and we were able to open the .zip attachment from the generated PDF document:

image.png (40.2 KB)

Document pdfDocument = new Document();
pdfDocument.Pages.Add();

// Setup new file to be added as attachment
FileSpecification fileSpecification = new FileSpecification(dataDir + "const.zip", "Sample file");

// Add attachment to document's attachment collection
pdfDocument.EmbeddedFiles.Add(fileSpecification);

dataDir = dataDir + "AddAttachment_out.pdf";

// Save new output
pdfDocument.Save(dataDir);

Can you send me generated pdf file having attached zip, may be something to do with my settings in Acrobat Reader.

@sinar3x

If you are facing an error similar to below image:

image.jpg (56.0 KB)

You can try updating the registry settings as suggested at below link: