HTML
JPG
PDF
XML
DOCX
PDF
Trabalhe com Links em PDF via .NET SDK
API para trabalhar com Links em documentos PDF com .NET.
Get StartedComo trabalhar com Links em documentos PDF usando Cloud .NET SDK
Para manipular Links em documentos PDF via Cloud .NET SDK, usaremos Aspose.PDF Cloud .NET SDK Este Cloud SDK permite que você crie facilmente aplicativos de criador, editor e conversor de PDF baseados em nuvem em C#, ASP.NET ou outras linguagens .NET para várias plataformas de nuvem. Abra NuGet gerenciador de pacotes, procure por Aspose.PDF Cloud e instale. Você também pode usar o seguinte comando do Console do Gerenciador de Pacotes.
Comando do Console do Gerenciador de Pacotes
PM> Install-Package Aspose.Pdf-Cloud
Etapas para adicionar links usando .NET SDK
Os desenvolvedores do Aspose.PDF Cloud podem facilmente carregar e anexar links a documentos PDF em apenas algumas linhas de código.
- Crie um novo objeto de Configuração com seu Secret e Key de Aplicação.
- Crie um objeto para conectar-se à API da Nuvem.
- Carregue o PDF para o armazenamento em nuvem.
- Criar novos objetos de anotação de link
- Adicionar um novo objeto de anotação de links ao PDF no armazenamento em nuvem usando a função PostPageLinkAnnotationsAsync.
- Verifica a resposta e registra o resultado.
- Baixa o arquivo atualizado para uso local.
Este código de exemplo mostra como adicionar links ao documento PDF
using Aspose.Pdf.Cloud.Sdk.Model;
namespace Links
{
public class LinksAdd
{
public static async Task Append(string documentName, string outputName, int pageNumber, string LinkAction, string remoteFolder)
{
// Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required).
pdfApi = new PdfApi(AppSecret, AppSid);
using (var file = File.OpenRead(Path.Combine(localFolder, documentName)))
{ // Upload the local PDF to cloud storage folder name.
FilesUploadResult uploadResponse = await pdfApi.UploadFileAsync(Path.Combine(remoteFolder, documentName), documentName);
Console.WriteLine(uploadResponse.Uploaded[0]);
}
// Create link annotation object with supported parameters
Link link = new Link(LinkAction);
LinkAnnotation newLink = new LinkAnnotation(
new List<Link>() { link },
ActionType: LinkActionType.GoToURIAction,
Action: LinkAction,
Highlighting: LinkHighlightingMode.Invert,
Color: new Color(A: 0xFF, R: 0xAA, G: 0x00, B: 0x00),
Rect: new Rectangle(LLX: 238, LLY: 488.622, URX: 305, URY: 498.588)
);
// Append new link annotation to the PDF on cloud storage.
AsposeResponse response = await pdfApi.PostPageLinkAnnotationsAsync(documentName, pageNumber, new List<LinkAnnotation>() { newLink }, folder: remoteFolder);
// Checks the response and logs the result.
if (response == null)
Console.WriteLine("LinksAdd(): Unexpected error!");
else if (response.Code < 200 || response.Code > 299)
Console.WriteLine("LinksAdd(): Failed to append link to the document.");
else
{ // Downloads the updated file for local use.
Console.WriteLine("PagesAdd(): page successfully appended to the document '{0}.", documentName);
Stream stream = pdfApi.DownloadFile(Path.Combine(remoteFolder, documentName));
using var fileStream = File.Create(Path.Combine(localFolder, "append_links_" + outputName));
stream.Position = 0;
await stream.CopyToAsync(fileStream);
Console.WriteLine("PagesAdd(): File '{0}' successfully downloaded.", "append_links_" + outputName);
}
}
}
}