इस ट्यूटोरियल में, हम समझेंगे कि C++** का उपयोग करके **PUB) को PNG में कैसे बदलें। आप देखेंगे कि रूपांतरण दो चरणों में होता है। सबसे पहले, पब फ़ाइल को एक पीडीएफ फाइल में बदल दिया जाता है और फिर इंटरमीडिएट पीडीएफ फाइल को साधारण एपीआई कॉल के साथ सी ++ का उपयोग करके पीएनजी प्रारूप में प्रस्तुत किया जाता है।
C++ का उपयोग करके PUB को PNG में बदलने के चरण
- NuGet पैकेज मैनेजर टूल से Aspose.PUB for C++ और Aspose.PDF for C++ इंस्टॉल करें
- Aspose::Pub और Aspose::Pdf नामस्थानों का संदर्भ जोड़ें
- इनपुट पब फ़ाइल को Document क्लास इंस्टेंस के साथ लोड करें
- ConvertToPdf विधि के साथ इंटरमीडिएट पीडीएफ फाइल बनाएं
- प्रत्येक पृष्ठ को पुनरावृत्त करें और आउटपुट पीएनजी छवियां बनाएं
आप कोड की कुछ पंक्तियों में सरल API कॉल के साथ C++* का उपयोग करके कुशलतापूर्वक *PUB को PNG में निर्यात कर सकते हैं। आपको केवल फ़ाइल पथ निर्दिष्ट करने और विधि कॉल करने की आवश्यकता है, फिर एपीआई रूपांतरण प्रक्रिया के सभी छोटे विवरणों पर विचार करता है। प्रसंस्करण के बाद, आउटपुट पीएनजी छवियों को आपकी आवश्यकताओं के अनुसार सहेजा जाता है।
C++ का उपयोग करके PUB को PNG में बदलने के लिए कोड
#pragma once | |
#include <stdio.h> | |
#include <tchar.h> | |
#include <cstdint> | |
#include <iostream> | |
// TODO: reference additional headers your program requires here | |
#include "system/console.h" | |
#include "system/string.h" | |
#include "system/io/directory.h" | |
#include <Aspose.Pub.Cpp/Properties/AssemblyInfo.h> | |
#include <Aspose.Pub.Cpp/PubFactory.h> | |
#include <Aspose.Pub.Cpp/Document.h> | |
#include <Aspose.Pub.Cpp/Interfaces.h> | |
#include <Aspose.Pub.Cpp/License.h> | |
#include <Aspose.Pub.Cpp/MetaInfo.h> | |
#include <Aspose.PDF.Cpp/Page.h> | |
#include <Aspose.PDF.Cpp/Document.h> | |
#include <Aspose.PDF.Cpp/PageCollection.h> | |
#include <Aspose.PDF.Cpp/Resources.h> | |
#include <Aspose.PDF.Cpp/XImageCollection.h> | |
#include <Aspose.PDF.Cpp/XImage.h> | |
#include <Aspose.PDF.Cpp/License.h> | |
#include <Aspose.PDF.Cpp/License.h> | |
#include <Aspose.PDF.Cpp/Devices/PngDevice.h> | |
#include <Aspose.PDF.Cpp/Devices/Resolution.h> | |
#include <Aspose.PUB.Cpp/License.h> | |
#include <Aspose.PUB.Cpp/PubFactory.h> | |
#include <Aspose.PUB.Cpp/Utils/UtilityObjects.h> | |
#include <system/smart_ptr.h> | |
using namespace System; | |
using namespace Aspose::Pdf; | |
using namespace Aspose::Pub; | |
class ConvertPUBtoPNGEx { | |
public: | |
static void PUBtoPNG() | |
{ | |
// Initialize license object of Aspose.PUB to convert PUB to PDF | |
auto PUBlicense = System::MakeObject<Aspose::Pub::License>(); | |
// Set license | |
PUBlicense->SetLicense(u"Aspose.Total.NET.lic"); | |
// Initialize license object of Aspose.PDF API to convert PDF to PNG | |
auto PDFlicense = System::MakeObject<Aspose::Pdf::License>(); | |
// Set license | |
PDFlicense->SetLicense(u"Aspose.Total.NET.lic"); | |
System::String filePub = u"Sample.pub"; | |
System::String filePdf = u"Test.pdf"; | |
System::SharedPtr<IPubParser> parser = PubFactory::CreateParser(filePub); | |
System::SharedPtr<Aspose::Pub::Document> document = parser->Parse(); | |
PubFactory::CreatePdfConverter()->ConvertToPdf(document, filePdf); | |
// Load the intermediate PDF file created from PUB file | |
System::SharedPtr<Aspose::Pdf::Document> pdfDocument = MakeObject<Aspose::Pdf::Document>(filePdf); | |
// Iterate throught the PDF pages for image conversion | |
for (System::SharedPtr<Page> page : pdfDocument->get_Pages()) | |
{ | |
// Create an instance of the FileStream class for output PNG image | |
System::SharedPtr<System::IO::FileStream> imageStream = System::IO::File::Create(String::Format(u"page_{0}.png", page->get_Number())); | |
// Create an instance of the Resolution class to set resolution of PNG | |
System::SharedPtr<Aspose::Pdf::Devices::Resolution> resolution = MakeObject<Aspose::Pdf::Devices::Resolution>(300); | |
// Create an instance of the PngDevice class to render images | |
System::SharedPtr<Aspose::Pdf::Devices::PngDevice> pngDevice = MakeObject<Aspose::Pdf::Devices::PngDevice>(500, 700, resolution); | |
// Save the page as PNG image output | |
pngDevice->Process(page, imageStream); | |
// Close the stream | |
imageStream->Close(); | |
} | |
} | |
}; |
पिछले विषय में, हमने सी++ में पीडीएफ फाइल कैसे पढ़ें सीखा था। जबकि, इस लेख में हमने चर्चा की है कि कैसे C++ PUB फ़ाइल से PNG बनाएँ।