สารสกัดจากเอกสารแนบ PDF ผ่าน C++

วิธีการแยกไฟล์แนบจาก PDF โดยทางโปรแกรมด้วย C++

วิธีการแยกสิ่งที่แนบมาโดยใช้ C++ ห้องสมุด

เพื่อที่จะดึงสิ่งที่แนบมาในไฟล์ PDF เราจะใช้ Aspose.PDF for C++ API ซึ่งเป็นคุณลักษณะที่อุดมไปด้วยที่มีประสิทธิภาพและง่ายต่อการใช้ API การจัดการเอกสาร cpp แพลตฟอร์มเปิดตัวจัดการแพคเกจ 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;
	}