Muna amfani da fayiloli PDF akai-akai yayin da suke ba da tallafi mai ban mamaki ga Rubutu da abun ciki na hoto. Da zarar an sanya waɗannan abubuwan a cikin takaddar, ana adana shimfidar fayil ko da wane dandamali kuke amfani da su don kallon su. Amma, ƙila muna da buƙatu don cire hotunan PDF. Ana iya cika wannan ta amfani da aikace-aikacen duba PDF amma kuna buƙatar ratsa kowane shafi da hannu kuma ku adana kowane hoto daban-daban. Bugu da ƙari kuma, a wani yanayin, idan kuna da hoto na tushen PDF kuma kuna buƙatar yin PDF OCR, to da farko kuna buƙatar cire duk hotuna sannan kuyi aikin OCR. Wannan yana samun wahala sosai lokacin da kuke da babban saitin takardu amma mafita na shirye-shirye na iya zama abin dogaro da sauri. Don haka a cikin wannan labarin, za mu bincika zaɓuɓɓukan cire hotuna daga PDF ta amfani da Java Cloud SDK
- API ɗin Canjin JPG zuwa PDF
- Cire Hotunan PDF a cikin Java
- Ajiye hotunan PDF ta amfani da Umarnin CURL
API ɗin Canjin JPG zuwa PDF
Domin canza PDF zuwa JPG ko JPG zuwa PDF a aikace-aikacen Java, Aspose.PDF Cloud SDK don Java zaɓi ne mai ban mamaki. Har ila yau, yana ba ku damar cire hotuna daga PDF, cire rubutu daga PDF, cire haɗe-haɗe daga PDF kuma yana ba da dama na zaɓuɓɓuka don sarrafa PDF. Don haka don aiwatar da fasalin don adana hotunan PDF a cikin aikace-aikacen Java, da farko muna buƙatar ƙara bayanin Cloud SDK a cikin aikinmu. Don haka da fatan za a ƙara cikakkun bayanai masu zuwa a cikin pom.xml na nau’in ginin maven.
<repositories>
<repository>
<id>aspose-cloud</id>
<name>artifact.aspose-cloud-releases</name>
<url>http://artifact.aspose.cloud/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf-cloud</artifactId>
<version>21.11.0</version>
</dependency>
</dependencies>
Da zarar an ƙara bayanin SDK kuma ba ku da wani asusun da ke wanzu akan Aspose Cloud, da fatan za a ƙirƙiri asusun kyauta ta amfani da adireshin imel mai inganci. Sannan shiga ta amfani da sabon asusun da aka ƙirƙira kuma bincika/ƙirƙiri ID na abokin ciniki da Sirrin Abokin ciniki a Cloud Dashboard. Ana buƙatar waɗannan cikakkun bayanai don dalilai na tantancewa a cikin sassan masu zuwa.
Cire Hotunan PDF a cikin Java
Da fatan za a bi matakan da aka bayar a ƙasa don cire hotuna daga PDF kuma da zarar an gama aikin, ana adana hotunan a babban fayil daban akan ma’ajiyar girgije.
- Da farko muna buƙatar ƙirƙirar abu na PdfApi yayin samar da ClientID da sirrin Abokin ciniki azaman muhawara
- Na biyu, shigar da fayil ɗin PDF ta amfani da misalin Fayil
- Loda shigar da PDF zuwa ma’ajiyar gajimare ta amfani da hanyar uploadFile(…).
- Hakanan za mu yi amfani da siga na zaɓi don saita cikakkun bayanai Tsawo & Nisa don hotunan da aka ciro
- A ƙarshe kira hanyar putImagesExtractAsJpeg(…) wanda ke ɗaukar sunan PDF, PageNumber don cire hotuna, girman hotuna da sunan babban fayil akan ma’ajiyar girgije don adana hotunan da aka ciro.
try
{
// Samu ClientID da ClientSecret daga https://dashboard.aspose.cloud/
String clientId = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
String clientSecret = "4d84d5f6584160cbd91dba1fe145db14";
// ƙirƙirar misali na PdfApi
PdfApi pdfApi = new PdfApi(clientSecret,clientId);
// sunan shigar da takaddun PDF
String inputFile = "marketing.pdf";
// karanta abun ciki na shigar da fayil ɗin PDF
File file = new File("//Users//"+inputFile);
// loda PDF zuwa ma'ajiyar gajimare
pdfApi.uploadFile("input.pdf", file, null);
// Shafin PDF don cire hotuna
int pageNumber =1;
// nisa don hotunan da aka ciro
int width = 600;
// tsayin hotuna da aka fitar
int height = 800;
// babban fayil don adana hotunan da aka ciro
String folderName = "NewFolder";
// Cire hotunan PDF kuma a adana akan Ma'ajin Gajimare
pdfApi.putImagesExtractAsJpeg(inputFile, pageNumber, width, height, null, null, folderName);
// buga sakon nasara
System.out.println("PDF images Successsuly extracted !");
}catch(Exception ex)
{
System.out.println(ex);
}
Za a iya sauke samfurin fayil ɗin PDF da aka yi amfani da shi a cikin misalin sama daga input.pdf.
Ajiye hotunan PDF ta amfani da Umarnin CURL
Yanzu za mu kira API don hakar hotunan PDF ta amfani da umarnin cURL. Yanzu a matsayin abin da ake buƙata don wannan hanyar, da farko muna buƙatar samar da alamar samun damar JWT (dangane da shaidar abokin ciniki) yayin aiwatar da umarni mai zuwa.
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Da zarar muna da alamar JWT, da fatan za a aiwatar da umarni mai zuwa don adana hotunan PDF a cikin babban fayil daban akan ma’ajiyar Cloud.
curl -X PUT "https://api.aspose.cloud/v3.0/pdf/input_file.pdf/pages/1/images/extract/jpeg?width=0&height=0&destFolder=NewFolder" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"
Kammalawa
Bayan karanta wannan labarin, kun koyi hanya mai sauƙi amma abin dogaro don fitar da hotunan PDF ta amfani da snippet code na Java da kuma ta umarnin cURL. Kamar yadda muka lura, muna samun damar cire hotuna daga takamaiman shafi na fayil ɗin PDF, kuma muna ba da ƙarin iko akan tsarin hakar. Samfurin Takardu an wadatar da shi tare da ɗimbin batutuwa masu ban mamaki suna ƙara yin bayanin iyawar wannan API.
Hakanan, kamar yadda ake buga duk SDK ɗin mu a ƙarƙashin lasisin MIT, don haka kuna iya yin la’akari da zazzage cikakkiyar lambar tushe daga GitHub kuma gyara ta gwargwadon buƙatun ku. A kowane hali, kuna iya la’akari da kusantar mu don ƙuduri mai sauri ta hanyar [Tallafin tallafin samfur 9.
Labarai masu alaka
Da fatan za a ziyarci hanyoyin haɗin yanar gizon don ƙarin koyo game da: