Sukurkite PDF naudodami Java biblioteką

Mūsų galinga Java biblioteka leidžia kūrėjams programiškai sukurti PDF vos keliais veiksmais

Java kūrėjai gali lengvai sukurti PDF naudodami tik mūsų galingą produkto API. Tai reiškia, kad mūsų sprendimas suteiks programuotojams viską, ko reikia norint sukurti PDF Java.

Peržiūrėkite kodo fragmentą

Sukurkite "PDF" programoje "Java" programiškai

Naudodami "Java" biblioteką kūrėjai gali lengvai sukurti "PDF" nuo nulio. Norėdami tai padaryti, Java kūrėjai turi atlikti tik kelis veiksmus:

  1. Pridėti failo pavadinimą
  2. Pradėkite kurti "PDF" dokumentą naudodami "Java"
  3. Išsaugokite išvesties PDF failą

Verta paminėti, kad tuščiame dokumente techniškai turėtų būti viena pastraipa, todėl programiškai kurdami PDF dokumentą gausite būtent tokią pagrindinę dokumento struktūrą.

Atminkite, kad galite akimirksniu įtraukti turinį į naujai sukurtą "PDF" failą. Taigi jūs gausite ne tik tuščią dokumentą, bet ir dokumentą su reikiamu turiniu. Daugiau informacijos apie tai, kaip redaguoti dokumentą, rasite puslapyje Redagavimas.

Sukurkite "PDF" naudodami "Java".

Ši Java biblioteka leidžia programiškai kurti PDF dokumentus. Išbandykite mūsų galingą funkciją ir sužinokite, kaip sukurti PDF kai kuriais formatais, naudojant šį pavyzdį:

Sukurkite naują PDF naudodami Java
Iš sąrašo pasirinkite tikslinį formatą
Vykdyti kodą
import com.aspose.words.*;

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Font font = builder.getFont();
font.setName("Courier New");
font.setColor(Color.BLUE);
font.setSize(36);
font.setHighlightColor(Color.YELLOW);

builder.write("Morbi enim nunc faucibus a.");

doc.save("Output.pdf");
import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Jei NextSibling yra nulinis, greičiausiai tai yra paskutinis Run pastraipoje. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.pdf"); import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Jei NextSibling yra nulinis, greičiausiai tai yra paskutinis Run pastraipoje. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1); doc.save("Output.pdf", saveOptions);
import com.aspose.words.*;

Document doc = new Document();

Run run = new Run(doc, "Proin eros metus, sagittis sed.");
Paragraph para = doc.getFirstSection().getBody().getFirstParagraph();
para.appendChild(run);

Comment comment = new Comment(doc);
comment.setAuthor("John Doe");
comment.setInitial("JD");
comment.setDateTime(new Date());
comment.setText("Quisque fringilla leo.");

CommentRangeStart commentRangeStart = new CommentRangeStart(doc, comment.getId());
CommentRangeEnd commentRangeEnd = new CommentRangeEnd(doc, comment.getId());

run.getParentNode().insertBefore(commentRangeStart, run);
run.getParentNode().insertAfter(commentRangeEnd, run);
commentRangeEnd.getParentNode().insertAfter(comment, commentRangeEnd);

comment.addReply("Jane Doe", "JD", new Date(), "Pellentesque vel sapien justo.");

doc.save("Output.pdf");
import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Jei NextSibling yra nulinis, greičiausiai tai yra paskutinis Run pastraipoje. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.pdf"); import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Jei NextSibling yra nulinis, greičiausiai tai yra paskutinis Run pastraipoje. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1); doc.save("Output.pdf", saveOptions);
import com.aspose.words.*;

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. ");
Run secondRun = new Run(doc, "Morbi enim nunc faucibus a.");
doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun);

builder.moveTo(secondRun);
builder.startBookmark("Aspose bookmark");
// Jei NextSibling yra nulinis, greičiausiai tai yra paskutinis Run pastraipoje.
if (secondRun.getNextSibling() != null)
    builder.moveTo(secondRun.getNextSibling());
else
    builder.moveTo(secondRun.getParentParagraph());
builder.endBookmark("Aspose bookmark");

PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1);

doc.save("Output.pdf", saveOptions);
import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Jei NextSibling yra nulinis, greičiausiai tai yra paskutinis Run pastraipoje. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.pdf"); import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Jei NextSibling yra nulinis, greičiausiai tai yra paskutinis Run pastraipoje. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1); doc.save("Output.pdf", saveOptions);
import com.aspose.words.*;

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.insertChart(ChartType.PIE, 432, 252);
Chart chart = shape.getChart();
chart.getTitle().setText("Demo Chart");

chart.getSeries().clear();
chart.getSeries().add("Series 1",
        new String[] { "Category1", "Category2", "Category3" },
        new double[] { 2.7, 3.2, 0.8 });

doc.save("Output.pdf");
import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Jei NextSibling yra nulinis, greičiausiai tai yra paskutinis Run pastraipoje. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); doc.save("Output.pdf"); import com.aspose.words.*; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Run firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); Run secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.getFirstSection().getBody().getFirstParagraph().appendChild(firstRun); doc.getFirstSection().getBody().getFirstParagraph().appendChild(secondRun); builder.moveTo(secondRun); builder.startBookmark("Aspose bookmark"); // Jei NextSibling yra nulinis, greičiausiai tai yra paskutinis Run pastraipoje. if (secondRun.getNextSibling() != null) builder.moveTo(secondRun.getNextSibling()); else builder.moveTo(secondRun.getParentParagraph()); builder.endBookmark("Aspose bookmark"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getOutlineOptions().getBookmarksOutlineLevels().add("Aspose bookmark", 1); doc.save("Output.pdf", saveOptions);
Vykdyti kodą

Kaip padaryti PDF Java

  1. Įdiekite Aspose.Words for Java
  2. Pridėkite bibliotekos nuorodą (importuokite biblioteką) prie savo Java projekto
  3. Sukurkite naują PDF dokumentą
  4. Iškvieskite metodą "save()", perduodami failo pavadinimą
  5. Gaukite rezultatą kaip atskirą failą

Java biblioteka sukurti PDF

" Java paketus talpiname "Maven" saugyklose. 'Aspose.Words for Java' yra įprastas JAR failas, kuriame yra baitų kodas. Vadovaukitės nuosekliomis instrukcijomis, kaip ją įdiegti "Java" kūrėjo aplinkoje.

Sistemos reikalavimai

Palaikomos " Java SE 7 ir naujesnės " Java Taip pat pateikiame atskirą " Java SE 6 paketą, jei privalote naudoti šį pasenusį JRE.

Mūsų " Java paketas yra kelių platformų ir veikia visose operacinėse sistemose su JVM diegimu, įskaitant " Microsoft Windows, "Linux", "MacOS", "Android" ir "iOS".

Informacijos apie papildomas paketų priklausomybes, tokias kaip " JogAmp JOGL, " Harfbuzz šriftų variklis, " Java Advanced Imaging JAI, rasite gaminio dokumentacijoje.

Kiti palaikomi failų formatai

Galite kurti dokumentus kitais failų formatais:

5%

Prenumeruokite "Aspose" produktų naujinius

Gaukite mėnesinius naujienlaiškius ir pasiūlymus, pristatomus tiesiai į jūsų pašto dėžutę.

© Aspose Pty Ltd 2001-2024. Visos teisės saugomos.