ระบุตัวเลือกการแสดงผลเมื่อแปลงเป็นPDF

รูปแบบPDFเป็นรูปแบบหน้าถาวรที่เป็นที่นิยมมากในหมู่ผู้ใช้และได้รับการสนับสนุนอย่างกว้างขว ด้วยเหตุนี้การแปลงเป็นPDFเป็นคุณลักษณะสำคัญของAspose.Words.

PDFเป็นรูปแบบที่ซับซ้อน ต้องมีการคำนวณหลายขั้นตอนในกระบวนการแปลงเอกสารเป็นPDFรวมถึงการคำนวณโครงร่ ตั้งแต่ขั้นตอนเหล่านี้รวมถึงการคำนวณที่ซับซ้อนพวกเขาจะใช้เวลานาน นอกจากนี้รูปแบบPDFค่อนข้างซับซ้อนด้วยตัวเอง แต่ก็มีโครงสร้างไฟล์ที่เฉพาะเจาะจงรูปแบบกราฟิกและการฝังตัวอักษร นอกจากนี้ยังมีฟังก์ชั่นการส่งออกที่ซับซ้อนบางอย่างเช่นแท็กโครงสร้างเอกสาร,การเข้ารหัส,ลายเซ็นดิจิตอลและรูปแบบที่สามารถแก้ไขได้.

Aspose.Wordsเครื่องยนต์เค้าโครงเลียนแบบวิธีการทำงานของเครื่องยนต์เค้าโครงหน้าMicrosoft Word ดังนั้นAspose.Wordsทำให้PDFเอกสารที่ส่งออกมีลักษณะใกล้เคียงที่สุดเท่าที่เป็นไปได้กับสิ่งที่คุณเห็นในMicrosoft Word บางครั้งจำเป็นต้องระบุตัวเลือกเพิ่มเติมซึ่งอาจส่งผลต่อผลลัพธ์ของการบันทึกเอกสารลงในรูปแบบPDF อ็อพชันเหล่านี้สามารถระบุได้โดยใช้คลาสของPdfSaveOptionsซึ่งประกอบด้วยคุณสมบัติที่เป็นตัวกำหนดวิธี.

ตัวอย่างของการใช้PdfSaveOptionsมีให้ด้านล่าง.

การสร้างเอกสารPDFด้วยแบบฟอร์มที่กรอกได้

นอกจากนี้ยังเป็นไปได้ที่จะส่งออกแบบฟอร์มที่เติมจากเอกสารMicrosoft Wordลงในเอาท์พุทPDFซึ่งมีรูปแบบที่เติมแทนข้อความธรรมดา ใช้คุณสมบัติPreserveFormFieldsเพื่อบันทึกเอกสารเป็นPDFด้วยแบบฟอร์มที่เติมได้.

โปรดทราบว่าในทางตรงกันข้ามกับMicrosoft WordรูปแบบPDFมีจำนวนจำกัดของตัวเลือกสำหรับฟอร์มที่สามา Microsoft Wordมีรูปแบบอื่นๆเช่นตัวเลือกวันที่ในปฏิทิน โดยทั่วไปแล้วมันเป็นไปไม่ได้ที่จะเลียนแบบMicrosoft WordพฤติกรรมในPDFอย่างเต็มที่ ดังนั้นในบางกรณีที่ซับซ้อนผลลัพธ์PDFอาจแตกต่างจากสิ่งที่คุณเห็นในMicrosoft Word.

ตัวอย่างรหัสด้านล่างแสดงวิธีการบันทึกเอกสารเป็นPDFด้วยแบบฟอร์มที่เต็มไปด้วยการบีบอัด:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
auto saveOptions = MakeObject<PdfSaveOptions>();
saveOptions->set_ImageCompression(PdfImageCompression::Jpeg);
saveOptions->set_PreserveFormFields(true);
doc->Save(ArtifactsDir + u"WorkingWithPdfSaveOptions.PdfImageCompression.pdf", saveOptions);
auto saveOptions17 = MakeObject<PdfSaveOptions>();
saveOptions17->set_Compliance(PdfCompliance::Pdf17);
saveOptions17->set_ImageCompression(PdfImageCompression::Jpeg);
saveOptions17->set_JpegQuality(100);
saveOptions17->set_ImageColorSpaceExportMode(PdfImageColorSpaceExportMode::SimpleCmyk);
doc->Save(ArtifactsDir + u"WorkingWithPdfSaveOptions.PdfImageCompression_17.pdf", saveOptions17);

การส่งออกโครงสร้างเอกสารและคุณสมบัติที่กำหนดเอง

คุณสมบัติExportDocumentStructureช่วยให้คุณสามารถส่งออกโครงสร้างเอกสารไปยังเอาต์พุตได้PDF.

PDFสิ่งอำนวยความสะดวกโครงสร้างตรรกะให้กลไกสำหรับการรวมข้อมูลเกี่ยวกับโครงสร้างเนื้อหาเอกสารลงในไฟล์PDF Aspose.Wordsเก็บรักษาข้อมูลเกี่ยวกับโครงสร้างจากเอกสารMicrosoft Wordเช่นย่อหน้า,รายการ,ตาราง,เชิงอรรถ/สิ้นสุดฯลฯ.

ตัวอย่างต่อไปนี้สาธิตวิธีการบันทึกเอกสารเป็นรูปแบบPDFการเก็บรักษาโครงสร้างเอกสาร:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// Open a document
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Paragraphs.docx");
// Create a PdfSaveOptions object and configure it to preserve the logical structure that's in the input document
// The file size will be increased and the structure will be visible in the "Content" navigation pane
// of Adobe Acrobat Pro, while editing the .pdf
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>();
options->set_ExportDocumentStructure(true);
System::String outputPath = outputDataDir + u"PdfSaveOptions.ExportDocumentStructure.pdf";
doc->Save(outputPath, options);

Aspose.Wordsยังช่วยให้คุณสามารถส่งออกเอกสารคุณสมบัติที่กำหนดเองไปยังPDFซึ่งจะแสดงโดยตัวอย่างต่อไปนี้:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// Open a document
System::SharedPtr<Document> doc = System::MakeObject<Document>();
// Add a custom document property that doesn't use the name of some built in properties
doc->get_CustomDocumentProperties()->Add(u"Company", u"My value");
// Configure the PdfSaveOptions like this will display the properties
// in the "Document Properties" menu of Adobe Acrobat Pro
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>();
options->set_CustomPropertiesExport(PdfCustomPropertiesExport::Standard);
System::String outputPath = outputDataDir + u"PdfSaveOptions.CustomPropertiesExport.pdf";
doc->Save(outputPath, options);

การส่งออกเค้าร่างจากบุ๊กมาร์กและส่วนหัวในเอาต์พุตPDF

ถ้าคุณต้องการส่งออกบุ๊กมาร์กเป็นเค้าร่างในผลลัพธ์PDFคุณสามารถใช้คุณสมบัติDefaultBookmarksOutlineLevel คุณสมบัตินี้ระบุระดับดีฟอลต์ในเค้าร่างเอกสารซึ่งแสดงบุ๊กมาร์กMicrosoft Word หากเอกสารประกอบด้วยบุ๊กมาร์กในส่วนหัว/ท้ายกระดาษของเอกสารคุณสามารถตั้งค่าคุณสมบัติHeaderFooterBookmarksExportModeเป็นFirstหรือAllเพื่อระบุวิธีเอ็กซ์ปอร์ตในผลลัพธ์PDF บุ๊กมาร์กในส่วนหัว/ท้ายกระดาษจะไม่ถูกส่งออกเมื่อค่าของHeaderFooterBookmarksExportModeเป็นNone.

ตัวอย่างรหัสด้านล่างแสดงวิธีการส่งออกที่คั่นหน้าจากส่วนหัว/ส่วนท้ายแรกของส่วน:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// The path to the documents directory.
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"TestFile.docx");
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>();
options->get_OutlineOptions()->set_DefaultBookmarksOutlineLevel(1);
options->set_HeaderFooterBookmarksExportMode(HeaderFooterBookmarksExportMode::First);
System::String outputPath = outputDataDir + u"WorkingWithPdfSaveOptions.ExportHeaderFooterBookmarks.pdf";
doc->Save(outputPath, options);

ผลลัพธ์PDFของตัวอย่างนี้แสดงด้านล่าง:

specify-rendering-options-aspose-words-cpp-1

เมื่อHeaderFooterBookmarksExportModeถูกตั้งค่าเป็นครั้งแรกและเอกสารมีส่วนหัว/ท้ายกระดาษคู่และคี่หรือส่วนหัว/ท้ายกระดาษ.

นอกจากนี้คุณยังสามารถเอ็กซ์ปอร์ตส่วนหัวในเอาต์พุตPDFโดยใช้คุณสมบัติHeadingsOutlineLevels คุณสมบัตินี้ระบุจำนวนระดับของส่วนหัวที่รวมอยู่ในเค้าร่างเอกสาร.

ตัวอย่างโค้ดด้านล่างแสดงวิธีการส่งออกส่วนหัวที่มีสามระดับ:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// Open a document
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Rendering.doc");
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>();
options->get_OutlineOptions()->set_HeadingsOutlineLevels(3);
options->get_OutlineOptions()->set_ExpandedOutlineLevels(1);
System::String outputPath = outputDataDir + u"PdfSaveOptions.SaveToPdfWithOutline.pdf";
doc->Save(outputPath, options);

ผลลัพธ์PDFของตัวอย่างนี้แสดงไว้ด้านล่าง:

specify-rendering-options-aspose-words-cpp-2

ลดการสุ่มตัวอย่างภาพเพื่อลดขนาดเอกสาร

Aspose.Wordsให้ความสามารถในการลดภาพตัวอย่างเพื่อลดขนาดผลลัพธ์PDFโดยใช้คุณสมบัติDownsampleOptions การลดการสุ่มตัวอย่างถูกเปิดใช้งานโดยดีฟอลต์ในคุณสมบัติDownsampleImages.

โปรดทราบว่าคุณสามารถตั้งค่าความละเอียดเฉพาะในคุณสมบัติResolutionหรือเกณฑ์ความละเอียดในคุณสมบัติResolutionThreshold ในกรณีที่สองหากความละเอียดของภาพน้อยกว่าค่าเกณฑ์การลดการสุ่มตัวอย่างจะไม่ใช้.

ตัวอย่างโค้ดด้านล่างจะแสดงวิธีเปลี่ยนความละเอียดของรูปภาพในเอกสารออกPDF:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// Open a document that contains images
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Rendering.doc");
// If we want to convert the document to .pdf, we can use a SaveOptions implementation to customize the saving process
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>();
// We can set the output resolution to a different value
// The first two images in the input document will be affected by this
options->get_DownsampleOptions()->set_Resolution(36);
// We can set a minimum threshold for downsampling
// This value will prevent the second image in the input document from being downsampled
options->get_DownsampleOptions()->set_ResolutionThreshold(128);
System::String outputPath = outputDataDir + u"PdfSaveOptions.DownsampleOptions.pdf";
doc->Save(outputPath, options);

ความละเอียดจะถูกคำนวณตามขนาดของภาพจริงบนหน้าเว็บ.

การฝังแบบอักษรในรูปแบบอะโดบีPDF

Aspose.Wordsยังช่วยให้คุณสามารถควบคุมวิธีการฝังแบบอักษรลงในผลลัพธ์PDFเอกสาร แบบอักษรจะต้องมีการฝังลงในเอกสารอะโดบีPDFเพื่อให้แน่ใจว่าเอกสารสามารถแสดงผลได้อย่างถูกต้องบนเครื่องใดๆ(ดูรายละเอียดเพิ่มเติมเกี่ยวกับการแสดงผลแบบอักษรในส่วน ใช้แบบอักษรTrueType). โดยค่าเริ่มต้นAspose.Wordsจะฝังชุดย่อยของแบบอักษรที่ใช้ในเอกสารลงในPDFที่สร้างขึ้น ในกรณีนี้เฉพาะสัญลักษณ์(อักขระ)ที่ใช้ในเอกสารเท่านั้นที่จะถูกบันทึกลงในPDF.

เมื่อใดที่จะใช้แบบอักษรเต็มรูปแบบและเมื่อที่จะย่อย

มีวิธีระบุตัวเลือกสำหรับAspose.Wordsเพื่อฝังแบบอักษรแบบเต็ม รายละเอียดเพิ่มเติมพร้อมกับข้อดีและข้อเสียของแต่ละการตั้งค่าจะอธิบายไว้ในตารางด้.

โหมดแบบอักษรฝัง ข้อดี ข้อเสีย
Full มีประโยชน์เมื่อคุณต้องการแก้ไขผลลัพธ์PDFในภายหลังโดยการเพิ่มหรือแก้ไขข้อความ แบบอักษรทั้งหมดจะถูกรวมด้วยเหตุนี้ร่ายมนตร์ทั้งหมดที่มีอยู่. เนื่องจากแบบอักษรบางตัวมีขนาดใหญ่(หลายเมกะไบต์)ฝังไว้โดยไม่ต้องตั้งค่าย่อยอาจส่งผล.
Subset การตั้งค่าย่อยจะเป็นประโยชน์ถ้าคุณต้องการที่จะให้ขนาดไฟล์ที่ส่งออกมีขนาดเล็กลง.

ผู้ใช้ไม่สามารถเพิ่มหรือแก้ไขข้อความทั้งหมดโดยใช้แบบอักษรย่อยในเอกสารออกPDF งหมดของแบบอักษรที่มีอยู่.

ถ้าหลายPDFsถูกบันทึกด้วยแบบอักษรย่อยและประกอบเข้าด้วยกันเอกสารPDFที่รวมกันอาจมีแบบอั

การฝังแบบอักษรแบบเต็มในPDF

คุณสมบัติEmbedFullFontsช่วยให้คุณสามารถระบุวิธีที่Aspose.Wordsฝังแบบอักษรลงในผลลัพธ์PDFเอกสาร.

  • เมื่อต้องการฝังแบบอักษรเต็มลงในผลลัพธ์PDFเอกสารให้ตั้งค่าEmbedFullFontsเป็นจริง
  • เมื่อต้องการตั้งค่าแบบอักษรย่อยเมื่อบันทึกเป็นPDFให้ตั้งค่าEmbedFullFontsเป็นเท็จ

ตัวอย่างต่อไปนี้สาธิตวิธีการฝังแบบอักษรทั้งหมดในเอกสารออกPDF:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// Open a Document
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Rendering.doc");
// Aspose.Words embeds full fonts by default when EmbedFullFonts is set to true. The property below can be changed
// Each time a document is rendered.
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>();
options->set_EmbedFullFonts(true);
// The output PDF will be embedded with all fonts found in the document.
System::String outputPath = outputDataDir + u"EmbeddedFontsInPDF.EmbedAllFonts_out.pdf";
doc->Save(outputPath, options);

ตัวอย่างต่อไปนี้แสดงวิธีการตั้งค่าAspose.Wordsเป็นแบบอักษรย่อยในเอาต์พุตPDF:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// Open a Document
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Rendering.doc");
// To subset fonts in the output PDF document, simply create new PdfSaveOptions and set EmbedFullFonts to false.
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>();
options->set_EmbedFullFonts(false);
// The output PDF will contain subsets of the fonts in the document. Only the glyphs used
// In the document are included in the PDF fonts.
System::String outputPath = outputDataDir + u"EmbeddedFontsInPDF.EmbeddSubsetFonts_out.pdf";
doc->Save(outputPath, options);

วิธีการควบคุมการฝังแบบอักษรหลักและแบบอักษรมาตรฐานWindows

แบบอักษรหลักและแบบอักษรมาตรฐานWindowsคือชุดแบบอักษร"มาตรฐาน"ซึ่งมักจะปรากฏอยู่บนเครื่องเป้าหมายหรือโดยเครื่องอ่านเอกสารดังนั้นจึงไม่จำเป็นต้องฝังอยู่ในผลลัพธ์PDF โดยการไม่ฝังแบบอักษรเหล่านี้คุณสามารถลดขนาดของเอกสารที่แสดงผลPDFและยังรักษาคว.

Aspose.Wordsมีตัวเลือกให้เลือกวิธีส่งออกแบบอักษรไปยังPDF คุณสามารถเลือกที่จะฝังแบบอักษรหลักและแบบมาตรฐานลงในผลลัพธ์PDFหรือข้ามการฝังและใช้แบบอักษรมาตรฐานหลักPDFหรือแบบอักษรระบบบนเครื่องเป้าหมายแทน โดยปกติแล้วการลดขนาดไฟล์อย่างมีนัยสำคัญสำหรับPDFเอกสารที่สร้างโดยAspose.Words.

  • เนื่องจากตัวเลือกเหล่านี้เป็นพิเศษร่วมกันคุณควรเลือกเพียงหนึ่งครั้ง.
  • เมื่อบันทึกด้วยการปฏิบัติตามข้อกำหนดPDF/A-1แบบอักษรที่ใช้ทั้งหมดจะต้องฝังอยู่กับเอกสารPDF เมื่อบันทึกด้วยการปฏิบัติตามข้อกำหนดนี้ต้องตั้งคุณสมบัติUseCoreFontsเป็นเท็จและคุณสมบัติFontEmbeddingModeต้องตั้งค่าเป็นEmbedAll.

การฝังแบบอักษรหลัก

ตัวเลือกในการฝังแบบอักษรหลักสามารถเปิดหรือปิดใช้งานได้โดยใช้คุณสมบัติUseCoreFonts เมื่อมีการตั้งค่าเป็นจริงแบบอักษร"ชนิดจริง"ที่นิยมมากที่สุด(แบบอักษรฐาน 14)จะไม่ฝังอยู่ในเอกสารออกPDF:

Arial Times New Roman Courier New Symbol

แบบอักษรเหล่านี้จะถูกแทนที่ด้วยแบบอักษรชนิดแกน1ซึ่งมีให้โดยผู้อ่านเมื่อเปิดPDF.

ตัวอย่างที่ให้ไว้ด้านล่างแสดงวิธีการตั้งค่าAspose.Wordsเพื่อหลีกเลี่ยงการฝังแบบอักษรหลักและปล่อยให้ผู้อ่านแทนด้วยแบบอักษรPDFชนิด1:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// The path to the documents directories.
System::String inputDataDir = GetInputDataDir_RenderingAndPrinting();
System::String outputDataDir = GetOutputDataDir_RenderingAndPrinting();
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Rendering.doc");
// To disable embedding of core fonts and subsuite PDF type 1 fonts set UseCoreFonts to true.
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>();
options->set_UseCoreFonts(true);
System::String outputPath = outputDataDir + u"EmbeddingWindowsStandardFonts.pdf";
// The output PDF will not be embedded with core fonts such as Arial, Times New Roman etc.
doc->Save(outputPath);

เนื่องจากผู้ชมPDFให้แบบอักษรหลักบนแพลตฟอร์มที่รองรับตัวเลือกนี้จึงเป็นประโยชน์เมื่อต้อง งไรก็ตามแบบอักษรหลักอาจดูแตกต่างจากแบบอักษรของระบบ.

การฝังแบบอักษรของระบบ

ตัวเลือกนี้สามารถเปิดหรือปิดใช้งานได้โดยใช้คุณสมบัติFontEmbeddingMode เมื่อคุณสมบัตินี้ถูกตั้งค่าเป็นEmbedNonstandardแบบอักษรชนิดจริง"อาเรียล"และ"ไทม์โรมันใหม่"จะไม่ถูกฝังลงในเอกสารPDF ในกรณีนี้ตัวแสดงไคลเอ็นต์อาศัยแบบอักษรที่ติดตั้งบนระบบปฏิบัติการของไคลเอ็นต์ เมื่อFontEmbeddingModeคุณสมบัติถูกตั้งค่าเป็นEmbedNoneAspose.Wordsจะไม่ฝังแบบอักษรใดๆ.

ตัวอย่างด้านล่างแสดงวิธีการตั้งค่าAspose.Wordsเพื่อข้ามการฝังทางอากาศและเวลาแบบอักษรโรมันใหม่ลงในเอกสารPDF:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// Load the document to render.
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Rendering.doc");
// To disable embedding standard windows font use the PdfSaveOptions and set the EmbedStandardWindowsFonts property to false.
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>();
options->set_FontEmbeddingMode(PdfFontEmbeddingMode::EmbedNone);
// The output PDF will be saved without embedding standard windows fonts.
System::String outputPath = outputDataDir + u"EmbeddedFontsInPDF.DisableEmbedWindowsFonts_out.pdf";
doc->Save(outputPath, options);

โหมดนี้จะมีประโยชน์มากที่สุดเมื่อคุณต้องการดูเอกสารของคุณบนแพลตฟอร์มเดียวกัน,รักษาลักษณะที่แน่นอนของแบบอักษรในผลลัพธ์PDF.