C++ 를 통해 PDF 문서에서 첨부 파일 추출

C++ 를 사용하여 프로그래밍 방식으로 PDF에서 첨부 파일을 추출하는 방법

C++ 라이브러리를 사용하여 첨부 파일을 추출하는 방법

PDF 파일에서 첨부 파일을 추출하기 위해 cpp 플랫폼을 위한 기능이 풍부하고 강력하며 사용하기 쉬운 문서 조작 API인 Aspose.PDF for C++ API를 사용합니다.NuGet 패키지 관리자를 열고 Aspose.pdf를 검색하여 설치합니다.패키지 관리자 콘솔에서 다음 명령을 사용할 수도 있습니다.

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

PDF에서 첨부 파일 추출 C++


사용자 환경에서 코드를 테스트하려면 Aspose.PDF for C++ 가 필요합니다.

1.임베디드 파일 컬렉션 가져오기. 1.포함된 파일 수를 가져옵니다. 1.컬렉션을 순회하며 모든 첨부 파일을 가져오세요. 1.매개 변수 개체에 매개 변수가 포함되어 있는지 확인하십시오. 1.첨부 파일을 가져와서 파일 또는 스트림에 씁니다.

PDF 문서에서 첨부 파일 추출


	// Open document
	auto pdfDocument = new Document(_dataDir + u"GetAlltheAttachments.pdf");

	// Get embedded files collection
	auto embeddedFiles = pdfDocument->get_EmbeddedFiles();

	// Get count of the embedded files
	Console::WriteLine(u"Total files : {0}", embeddedFiles->get_Count());

	int count = 1;

	// Loop through the collection to get all the attachments
	for (auto fileSpecification : embeddedFiles)
	{
	Console::WriteLine(u"Name: {0}", fileSpecification->get_Name());
	Console::WriteLine(u"Description: {0}", fileSpecification->get_Description());
	Console::WriteLine(u"Mime Type: {0}", fileSpecification->get_MIMEType());

	// Check if parameter object contains the parameters
	if (fileSpecification->get_Params() != nullptr)
	{
	Console::WriteLine(u"CheckSum: {0}",
		fileSpecification->get_Params()->get_CheckSum());
	Console::WriteLine(u"Creation Date: {0}",
		fileSpecification->get_Params()->get_CreationDate());
	Console::WriteLine(u"Modification Date: {0}",
		fileSpecification->get_Params()->get_ModDate());
	Console::WriteLine(u"Size: {0}", fileSpecification->get_Params()->get_Size());
	}

	// Get the attachment and write to file or stream
	auto fileContent = MakeArray<uint8_t>(fileSpecification->get_Contents()->get_Length());
	fileSpecification->get_Contents()->Read(fileContent, 0, fileContent->get_Length());
	auto fileStream = System::IO::File::OpenWrite(_dataDir + u"test" + count + u"_out.txt");
	fileStream->Write(fileContent, 0, fileContent->get_Length());
	fileStream->Close();
	count += 1;
	}