Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Le SDK Adobe Acrobat est un ensemble d’outils qui vous aide à développer des logiciels interagissant avec la technologie Acrobat. Le SDK contient des fichiers d’en-tête, des bibliothèques de types, des utilitaires simples, du code d’exemple et de la documentation.
En utilisant le SDK Acrobat, vous pouvez développer des logiciels qui s’intègrent à Acrobat et Adobe Reader de plusieurs manières :
Aspose.PDF for .NET offre beaucoup de la même fonctionnalité, vous libérant de la dépendance à l’automatisation d’Adobe Acrobat. Cet article montre comment générer des images miniatures à partir de documents PDF en utilisant d’abord le SDK Acrobat puis Aspose.PDF.
Pensez à l’API Acrobat comme ayant deux couches distinctes qui utilisent des objets de communication interapplication Acrobat (IAC) :
Comme notre intention est de convertir les pages PDF en images miniatures, nous nous concentrons davantage sur l’IAC. L’API IAC contient des objets tels que PDDoc, PDPage, PDAnnot, et d’autres, qui permettent à l’utilisateur de traiter la couche de document portable (PD). L’exemple de code suivant parcourt un dossier et convertit les pages PDF en images miniatures. En utilisant le SDK Acrobat, nous pourrions également lire les métadonnées PDF et récupérer le nombre de pages dans le document.
Pour générer les images miniatures pour chaque document, nous avons utilisé le SDK Adobe Acrobat 7.0 et le Framework Microsoft .NET 2.0.
Le SDK Acrobat combiné avec la version complète d’Adobe Acrobat expose une bibliothèque COM d’objets (malheureusement, le lecteur Adobe gratuit n’expose pas les interfaces COM) qui peuvent être utilisés pour manipuler et accéder aux informations PDF. En utilisant ces objets COM via COM Interop, chargez le document PDF, obtenez la première page et rendez cette page dans le presse-papiers. Ensuite, avec le Framework .NET, copiez cela dans un bitmap, redimensionnez et combinez l’image et enregistrez le résultat en tant que fichier GIF ou PNG.
Une fois Adobe Acrobat installé, utilisez regedit.exe et recherchez sous HKEY_CLASSES_ROOT l’entrée appelée AcroExch.PDDoc.
Le registre montrant l’entrée AcroExch.PDDDoc
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GenerateThumbnailImagesFromPDF()
{
// Acrobat objects
Acrobat.CAcroPDDoc pdfDoc;
Acrobat.CAcroPDPage pdfPage;
Acrobat.CAcroRect pdfRect;
Acrobat.CAcroPoint pdfPoint;
AppSettingsReader appSettings = new AppSettingsReader();
string pdfInputPath = appSettings.GetValue("pdfInputPath", typeof(string)).ToString();
string pngOutputPath = appSettings.GetValue("pngOutputPath", typeof(string)).ToString();
string templatePortraitFile = Application.StartupPath + @"\pdftemplate_portrait.gif";
string templateLandscapeFile = Application.StartupPath + @"\pdftemplate_landscape.gif";
// Get list of files to process from the input path
string[] files = Directory.GetFiles(pdfInputPath, "*.pdf");
for (int n = 0; n < files.Length; n++)
{
string inputFile = files[n];
string outputFile = Path.Combine(pngOutputPath, Path.GetFileNameWithoutExtension(inputFile) + ".png");
// Create PDF document
pdfDoc = (Acrobat.CAcroPDDoc)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.PDDoc", "");
if (pdfDoc.Open(inputFile) == 0)
{
throw new FileNotFoundException($"Unable to open PDF file: {inputFile}");
}
int pageCount = pdfDoc.GetNumPages();
pdfPage = (Acrobat.CAcroPDPage)pdfDoc.AcquirePage(0);
pdfPoint = (Acrobat.CAcroPoint)pdfPage.GetSize();
pdfRect = (Acrobat.CAcroRect)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.Rect", "");
pdfRect.Left = 0;
pdfRect.right = pdfPoint.x;
pdfRect.Top = 0;
pdfRect.bottom = pdfPoint.y;
pdfPage.CopyToClipboard(pdfRect, 0, 0, 100);
IDataObject clipboardData = Clipboard.GetDataObject();
if (clipboardData.GetDataPresent(DataFormats.Bitmap))
{
Bitmap pdfBitmap = (Bitmap)clipboardData.GetData(DataFormats.Bitmap);
int thumbnailWidth = 45;
int thumbnailHeight = 59;
string templateFile = pdfPoint.x < pdfPoint.y ? templatePortraitFile : templateLandscapeFile;
if (pdfPoint.x > pdfPoint.y)
{
// Swap width and height for landscape orientation
(thumbnailWidth, thumbnailHeight) = (thumbnailHeight, thumbnailWidth);
}
Bitmap templateBitmap = new Bitmap(templateFile);
Image pdfImage = pdfBitmap.GetThumbnailImage(thumbnailWidth, thumbnailHeight, null, IntPtr.Zero);
Bitmap thumbnailBitmap = new Bitmap(thumbnailWidth + 7, thumbnailHeight + 7, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
templateBitmap.MakeTransparent();
using (Graphics thumbnailGraphics = Graphics.FromImage(thumbnailBitmap))
{
thumbnailGraphics.DrawImage(pdfImage, 2, 2, thumbnailWidth, thumbnailHeight);
thumbnailGraphics.DrawImage(templateBitmap, 0, 0);
thumbnailBitmap.Save(outputFile, System.Drawing.Imaging.ImageFormat.Png);
}
Console.WriteLine("Generated thumbnail: {0}", outputFile);
pdfDoc.Close();
Marshal.ReleaseComObject(pdfPage);
Marshal.ReleaseComObject(pdfRect);
Marshal.ReleaseComObject(pdfDoc);
}
}
}
Aspose.PDF for .NET offre un support étendu pour traiter les documents PDF. Il prend également en charge la capacité de convertir les pages de documents PDF en une variété de formats d’image. La fonctionnalité décrite ci-dessus peut être facilement réalisée en utilisant Aspose.PDF for .NET.
Aspose.PDF présente des avantages distincts :
Si nous devons convertir des pages PDF en JPEG, le namespace Aspose.PDF.Devices fournit une classe nommée JpegDevice pour rendre les pages PDF en images JPEG. Veuillez consulter l’extrait de code suivant.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GenerateThumbnailImagesFromPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Retrieve names of all the PDF files in a particular directory
string[] fileEntries = Directory.GetFiles(dataDir, "*.pdf");
// Iterate through all the files entries in array
for (int counter = 0; counter < fileEntries.Length; counter++)
{
// Open PDF document
using (var document = new Aspose.Pdf.Document(fileEntries[counter]))
{
for (int pageCount = 1; pageCount <= document.Pages.Count; pageCount++)
{
using (FileStream imageStream = new FileStream(dataDir + @"\Thumbanils" + counter.ToString() + "_" + pageCount + ".jpg", FileMode.Create))
{
var resolution = new Aspose.Pdf.Devices.Resolution(300);
var jpegDevice = new Aspose.Pdf.Devices.JpegDevice(45, 59, resolution, 100);
// Convert a particular page and save the image to stream
jpegDevice.Process(document.Pages[pageCount], imageStream);
}
}
}
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.