Ikon canza [HTML] (https://docs.fileformat.com/web/html/) abun ciki zuwa [PDF] (https://docs.fileformat.com/pdf/) tsari ya zama makawa ga kasuwanci daban-daban kuma masu haɓakawa. Ko muna adana shafukan yanar gizo azaman PDFs don dalilai na ajiya, samar da rahotanni, ko raba abubuwan yanar gizo tare da masu amfani, canza HTML zuwa PDF yana taka muhimmiyar rawa. Wannan fasalin mai ƙarfi yana ba ku damar adana tsari, salo, da mu’amalar abun cikin gidan yanar gizon yayin da kuke canza shi zuwa tsarin da ake iya samun dama ga duniya baki ɗaya.
A cikin wannan labarin, za mu bincika fa’idodi da yawa waɗanda suka zo tare da amfani da Aspose.PDF Cloud SDK don canza HTML zuwa PDF. Za mu koyi yadda yake ba ku damar haɓaka ƙarfin sarrafa takaddun ku, daidaita ayyukan aiki, da sadar da ƙwarewar mai amfani ta musamman.
- API ɗin REST don Canjin HTML zuwa PDF
- Shafin yanar gizo zuwa PDF ta amfani da C# .NET
- HTML zuwa PDF Online ta amfani da Umarnin CURL
API ɗin REST don Canjin HTML zuwa PDF
Aspose.PDF Cloud SDK for .NET yana ba da cikakkun siffofi masu ƙarfi don HTML zuwa fassarar PDF, yana mai da shi babban zaɓi ga masu haɓakawa suna neman ingantaccen daftarin aiki. sarrafa bayani. Tare da wannan SDK, zaku iya jujjuya abun ciki na HTML ba tare da matsala ba zuwa takaddun PDF masu inganci yayin kiyaye shimfidar wuri, salo, da hanyoyin haɗin gwiwa. Wannan yana ba ku damar ƙirƙirar fayilolin PDF masu ban sha’awa da mu’amala kai tsaye daga tushen HTML, yana mai da shi manufa don samar da rahotanni, da daftari, kasidar samfur, da ƙari.
Yanzu, don fara amfani da wannan hanyar, muna buƙatar fara ƙara bayanin SDK a cikin aikinmu. Don haka, da fatan za a bincika ‘Aspose.PDF-Cloud’ a cikin manajan fakitin NuGet a cikin IDE Studio Visual kuma danna maɓallin ‘Ƙara Kunshin’. Hakanan kuna buƙatar samun takaddun shaidar abokin ciniki daga cloud dashboard. Idan ba ku da asusun da ke akwai, kawai ƙirƙiri asusun kyauta ta bin umarnin da aka kayyade a kan saurin farawa.
Shafin yanar gizo zuwa PDF ta amfani da C# .NET
Da fatan za a gwada amfani da snippet code mai zuwa don cika abin da ake buƙata don canza shafin yanar gizon zuwa PDF.
// Don ƙarin misalai, https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-dotnet/tree/master/Examples
// Samu bayanan abokin ciniki daga https://dashboard.aspose.cloud/
string clientSecret = "4d84d5f6584160cbd91dba1fe145db14";
string clientID = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
// ƙirƙirar misali na PdfApi
PdfApi pdfApi = new PdfApi(clientSecret, clientID);
// Shigar da sunan fayil na HTML
String inputHTML = "input1.html";
// Kira API don canza HTML ɗin da ke cikin .zip Rumbun ajiya akan girgije
// Mun kuma ayyana sunan fayil ɗin HTMl don canzawa da kuma cikakkun bayanan gefe
var result = pdfApi.GetHtmlInStorageToPdf("inputHTML.zip",htmlFileName: inputHTML,
height: 1000, width: 800, isLandscape: false,
marginLeft: 10, marginRight: 10, marginTop: 10, marginBottom: 10);
// Hanyar kira don ajiye fitarwa a kan tuƙi na gida
saveToDisk(result, "/Users/nayyer/Downloads/Converted.pdf");
// Hanya don adana abun ciki na rafi zuwa fayil akan faifan gida
public static void saveToDisk(Stream responseStream, String resultantFile)
{
var fileStream = File.Create(resultantFile);
responseStream.Seek(0, SeekOrigin.Begin);
responseStream.CopyTo(fileStream);
fileStream.Close();
}
An ba da cikakkun bayanai game da snippet code na sama.
PdfApi pdfApi = new PdfApi(clientSecret, clientID);
Da fari dai, ƙirƙiri wani abu na ajin PdfApi yayin ƙaddamar da bayanan abokin ciniki azaman mahawara ta shigarwa.
var result = pdfApi.GetHtmlInStorageToPdf("converted.zip", htmlFileName: "converted6.html",
height: 1000, width: 800, isLandscape: false,
marginLeft: 10, marginRight: 10, marginTop: 10, marginBottom: 10);
Kira API don canza HTML zuwa PDF. A matsayin gardama, mun wuce sunan .zip archive dauke da fayil ɗin HTML, sunan fayil ɗin HTML da za a canza, sakamakon girman PDF da cikakkun bayanan gefe.
saveToDisk(result, "/Users/nayyer/Downloads/htmlOutput.pdf");
A ƙarshe, muna kiran hanyar don adana sakamakon PDF zuwa faifan gida.
Idan muna buƙatar yin jujjuyawa da adana fayil ɗin sakamako zuwa ma’ajiyar girgije, da fatan za a kira API PutHtmlInStorageToPdf.
HTML zuwa PDF Online ta amfani da Umarnin CURL
Canza HTML zuwa PDF ta amfani da umarnin cURL a hade tare da Aspose.PDF Cloud yana ba da hanya mai dacewa kuma mai dacewa ga masu haɓakawa waɗanda ke neman yin jujjuya daftarin aiki ta hanyar shirye-shirye. Aspose.PDF Cloud yana ba da API RESTful wanda ke ba ku damar haɗa ayyukan HTML zuwa PDF cikin aikace-aikacenku ta amfani da buƙatun HTTP masu sauƙi. Wannan hanyar tana da fa’ida musamman ga waɗanda suka fi son yin aiki tare da kayan aikin layin umarni ko buƙatar sassauƙa wajen haɗa fasalin juzu’i zuwa wurare daban-daban.
Mataki na farko na wannan hanyar shine ƙirƙirar alamar samun damar JWT. Don haka, da fatan za a 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 an ƙirƙiri alamar JWT, da fatan za a aiwatar da umarni mai zuwa don canza fayil ɗin HTML ɗin da ke cikin ma’ajiyar gajimare zuwa tsarin PDF da loda fitar da sakamakon zuwa ma’ajiyar girgije iri ɗaya:
curl -v "https://api.aspose.cloud/v3.0/pdf/{resultantFile}/create/html?srcPath=converted.zip&htmlFileName={sourceHTML}" \
-X PUT \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-d {} -v
Sauya ‘sourceHTML’ tare da sunan shigar da daftarin aiki HTML da ake samu a cikin ma’ajiyar gajimare, da ‘resultantFile’ tare da sunan sakamakon daftarin aiki PDF da za a adana a cikin ma’ajiyar gajimare.
Idan muna da buƙatu don canza fayil ɗin HTML zuwa tsarin PDF da adana abin fitarwa akan faifan gida, da fatan za a aiwatar da umarni mai zuwa:
curl -v "https://api.aspose.cloud/v3.0/pdf/create/html?srcPath=sourceFolder.zip&htmlFileName=source.html&height=1000&width=800&isLandscape=false&marginLeft=10&marginBottom=10&marginRight=10&marginTop=10" \
-X GET \
-H "accept: multipart/form-data" \
-H "authorization: Bearer {accessToken}" \
-o "Converted.pdf"
Kuna iya yin la’akari da zazzage samfurin fayilolin da aka yi amfani da su a cikin misalin da ke sama daga inputHTML.html da htmlOutput.pdf.
Kammalawa
A ƙarshe, canza HTML zuwa PDF shine ainihin abin da ake bukata a masana’antu daban-daban, kuma ta hanyar yin amfani da Aspose.PDF Cloud SDK don NET, tare da umarnin cURL, muna samun mafita mai ƙarfi da inganci don cimma wannan aikin. Bugu da ƙari, tare da ƙaƙƙarfan fasalulluka masu ƙarfi na Aspose.PDF Cloud, kamar kiyaye shimfidar wuri da sigogin da za a iya daidaita su, za ku iya amincewa da samar da takaddun PDF masu inganci daga abun cikin HTML. Ko kuna gina shafukan yanar gizo masu ƙarfi, samar da rahotanni, adana bayanai, ko ƙirƙirar takaddun da za’a iya bugawa, wannan hanyar tana tabbatar da daidaitattun sakamakon juyawa.
Hanyoyin haɗi masu amfani
Labarai masu alaka
Muna ba da shawarar ziyartar shafukan yanar gizo masu zuwa: