Last active
March 27, 2021 12:23
-
-
Save aspose-com-gists/c6dbbba95ae31ff9c526b37ca170b929 to your computer and use it in GitHub Desktop.
Convert CSV to PDF and PDF to CSV format using C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Convert CSV to PDF and PDF to CSV format using C++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Create CSV LoadOptions object | |
intrusive_ptr<ILoadOptions> loadOptions = Factory::CreateILoadOptions(LoadFormat_CSV); | |
// Load the input Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("Sample1.csv")), loadOptions); | |
// Save as PDF file | |
workbook->Save(outDir->StringAppend(new String("Sample1_out.pdf")), SaveFormat_Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load PDF file | |
auto pdfDocument = MakeObject<Document>(u"SourceDirectory\\Sample2_csv.pdf"); | |
// Initialize ExcelSaveOptions class object | |
auto options = MakeObject<ExcelSaveOptions>(); | |
options->ConversionEngine = ExcelSaveOptions::ConversionEngines::NewEngine; | |
// Set save format as CSV | |
options->set_Format(ExcelSaveOptions::ExcelFormat::CSV); | |
// Create an instance of the Document class to represent the CSV file. | |
auto newPdfDocument = MakeObject<Document>(); | |
for (int i = 1; i <= pdfDocument->get_Pages()->get_Count(); i++) | |
{ | |
// Get first 2 pages | |
if (i <= 2) | |
{ | |
// Add the page to the new Document instance | |
newPdfDocument->get_Pages()->Add(pdfDocument->get_Pages()->idx_get(i)); | |
} | |
} | |
// Save as CSV file | |
newPdfDocument->Save(u"OutputDirectory\\Sample2_csv_out.csv", options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load PDF file | |
auto pdfDocument = MakeObject<Document>(u"SourceDirectory\\Sample2_csv.pdf"); | |
// Initialize ExcelSaveOptions class object | |
auto options = MakeObject<ExcelSaveOptions>(); | |
options->ConversionEngine = ExcelSaveOptions::ConversionEngines::NewEngine; | |
// Set save format as CSV | |
options->set_Format(ExcelSaveOptions::ExcelFormat::CSV); | |
for (int i = 1; i <= pdfDocument->get_Pages()->get_Count(); i++) | |
{ | |
// Create an instance of the Document class to represent the CSV file. | |
auto newPdfDocument = MakeObject<Document>(); | |
// Add the page to the new Document instance | |
newPdfDocument->get_Pages()->Add(pdfDocument->get_Pages()->idx_get(i)); | |
// Save as CSV file | |
newPdfDocument->Save(u"OutputDirectory\\Sample2_csv_out_" + System::Convert::ToString(i) + u".csv", options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load PDF file | |
auto pdfDocument = MakeObject<Document>(u"SourceDirectory\\Sample2_csv.pdf"); | |
// Initialize ExcelSaveOptions class object | |
auto options = MakeObject<ExcelSaveOptions>(); | |
options->ConversionEngine = ExcelSaveOptions::ConversionEngines::NewEngine; | |
// Set save format as CSV | |
options->set_Format(ExcelSaveOptions::ExcelFormat::CSV); | |
// Save as CSV file | |
pdfDocument->Save(u"OutputDirectory\\Sample2_csv_out.csv", options); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment